Creating a parse tree with yacc (Pasi Tuominen)
3 Sep 1997 01:00:37 -0400

          From comp.compilers

Related articles
Creating a parse tree with yacc (1997-09-03)
| List of all articles for this month |

From: (Pasi Tuominen)
Newsgroups: comp.compilers
Date: 3 Sep 1997 01:00:37 -0400
Organization: Oy L M Ericsson Ab
Keywords: yacc, question


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]


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.