I've found this example, but it creates tree bottoms-up. Is it possible to create tree topdown using bison, flex?
Pseudocode:
block(parent):
{ current = new Block(); parent.addBlock(this); }
BLOCK_BEGIN_TOKEN block_content(current) BLOCK_END_TOKEN
;
block_content(parent)
: block_content(parent) statement(current)
| block_content(parent) block(current)
| statement(parent)
| block(parent)
;
statement(parent)
: STATEMENT_TOKEN { parent.addStatement(new Statement($1)); }
You can do pretty much exactly what you describe with btyacc. You can write:
You can do the same thing in bison, but you have to use embedded actions with explicit type tags: