views:

895

answers:

1

Is it possible to make YACC (or I'm my case MPPG) output an Abstract Syntax Tree (AST).

All the stuff I'm reading suggests its simple to make YACC do this, but I'm struggling to see how you know when to move up a node in the tree as your building it.

+1  A: 

Have you looked at the manual (search for "parse tree" to find the spot)? It suggests putting node creation in an action with your left and right descendants being $1 and $3, or whatever they may be. In this case, yacc would be moving up the tree on your behalf rather than your doing it manually.

Hao Lian
Thanks, I'd seen this before in the lexx ...LexValue(State state, object child1, object child2) {...}} This allows you to store a tree node as your state. You can then assign data to it using the $$ alias$$ = new LexValue(State.SchemaImport, $3, $5);Note: The lexer needs to push its token data into this structure as well.Easy when you know how...
Sprotty