Does anyone have any guidelines on how the structure of the input grammar
will affect the efficiency of the resulting parser (eg, number of
levels of non-terminal, etc.)?
Kathy Harris
Hewlett Packard Systems Software Operation
Ft. Collins, Colorado
Avoid productions like
a : b ;
if possible. It helps to use precedence rules with an ambiguous
grammar. Thus you can write things like
expr : expr '+' expr
| expr '*' expr
| '-' expr
| '(' expr ')'
;
and use precedence rules to sort things out. This avoids alot of
nonterminals whose sole purpose is keeping the precedences straight.
Dale
dave
dave
> dave
----------
It depends on what you want to use yacc for. In compilers, it's probably
true that the computation involved in code generation makes the parse
time less critical.
However, yacc can be useful as a parser for other types of input languages
where the computation task is not so great and so yacc becomes a large
part of the task. A more efficient yacc parser would make it feasible
to use yacc in more contexts than just compilers.
The application I've been looking at is an assembler that uses yacc to
parse the assembly source. Currently, yyparse is 25%+ of the user time.
I'm looking for ways to speed of the parse phase, and yet not sacrifice
the flexibility (eg, in adding support for new instructions and addressing
types) that is provided by yacc.
kathy harris
{hplabs | ihnp4}!hpfcla!kah
dave