|Creating a parse tree with yacc Pasi.Tuominen@lmf.ericsson.se (1997-09-03)|
|From:||Pasi.Tuominen@lmf.ericsson.se (Pasi Tuominen)|
|Date:||3 Sep 1997 01:00:37 -0400|
|Organization:||Oy L M Ericsson Ab|
Does anybody have a simple example of how to create a parse tree with
yacc and lex? I have trouble using the '$' attributes when using a
yylval type other than the default, integer. I am not sure if I am
doing all correctly. I have defined yylval as a union. yylval is
assigned the yytext value in the lex specification.
Grateful for any help.
[For each symbol in your parser, the yylval has to be the subtree
rooted at that symbol. Each rule builds a new tree from the subtrees
of its constituent entries, if you want a full parse tree. For an AST,
rules that just do syntax, e.g., parenthesized expressions, can pass
through the interesting subtree directly. If I ever revise the lex&yacc
book, parse trees definitely need a chapter. -John]
Return to the
Search the comp.compilers archives again.