[comp.compilers] Questions about Yacc

srini@synopsys.Synopsys.COM (Srinivas Raghvendra) (03/05/91)

This is a question about the standard Yacc tool distributed with Unix.

I notice that Yacc uses a #define named YYMAXDEPTH and that this value has
been set at 150. 
	(1) I notice that even for moderately nested constructs, this seems
	insufficient. (I get a Yacc stack overflow).  Has anybody else faced 
	the same problem ?
	(2) If the answer to (1) is Yes, what is a reasonable value for
	YYMAXDEPTH ?


Srinivas Raghvendra, Synopsys, Inc., Mountain View, CA
(415)962-5000, srini@synopsys.com
-- 
Send compilers articles to compilers@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.

dg@hplabs.hpl.hp.com (Dipankar Gupta) (03/07/91)

In article <694@synopsys.COM> srini@synopsys.Synopsys.COM (Srinivas Raghvendra) writes:
>This is a question about the standard Yacc tool distributed with Unix.
>
>I notice that Yacc uses a #define named YYMAXDEPTH and that this value has
>been set at 150. 
>	(1) I notice that even for moderately nested constructs, this seems
>	insufficient. (I get a Yacc stack overflow).  Has anybody else faced 
>	the same problem ?
>	(2) If the answer to (1) is Yes, what is a reasonable value for
>	YYMAXDEPTH ?

You may want to use the __RUNTIME_YYMAXDEPTH option, which allows runtime
allocation of YACC stacks. You may choose a convenient value for
the increment YYINCREMENT. This uses malloc (3) routines to manage stacks.

Caveat:
The version of yacc that I have (on HP-UX 7.0) demands char *malloc (), which
may interfere with ANSI headers.

Dipankar Gupta
Hewlett-Packard India  Software Operation, Bangalore, India
dg@hplb.hpl.hp.com
[This must be an HP-ism, it's not present in the SVR3 yacc parser. Personally,
I've always found the default depth to be plenty.  What sort of grammars are
you parsing that overflow? -John]
-- 
Send compilers articles to compilers@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.

bliss@sp64.csrd.uiuc.edu (Brian Bliss) (03/09/91)

In article <694@synopsys.COM>, srini@synopsys.Synopsys.COM (Srinivas
Raghvendra) writes:
|> I notice that Yacc uses a #define named YYMAXDEPTH and that this value has
|> been set at 150. 
|> 	(1) I notice that even for moderately nested constructs, this seems
|> 	insufficient. (I get a Yacc stack overflow).

If you get overflows, you are probably using too many right-recursive
productions in you grammar.  change these to left-recursive productions
and the stack won't grow without bound.  (i.e. lemme see your grammar).

bb
-- 
Send compilers articles to compilers@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.

kathy@hpdcdb.fc.hp.com (Kathy Harris) (03/14/91)

 dg@hpl.hp.com (Dipankar Gupta) writes:

>You may want to use the __RUNTIME_YYMAXDEPTH option, which allows runtime

This is an HP-UX feature, not part of standard (POSIX, ???) yacc.

Kathy Harris
Colorado Language Labratory
Hewlett Packard
Ft. Collins, Co.
-- 
Send compilers articles to compilers@iecc.cambridge.ma.us or
{ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.