2
votes

In lemon I was able to use the third parameter of the parsing function to pass back the result to the caller when the starting symbol was reduced.

How would I do the same in bison? Is it enough to assign that value to $$ within the starting symbol's action code, and from the caller to take it as the "yy minor" value, after the final call to yypush_parse()?

The parser is push and pure. Thread-safety is a must.

1
Nope, not a dupe, I have specific needs like thread-safety within a fixed framework: a pure push parser.Flavius

1 Answers

2
votes

You'll pretty much have to do-it-yourself with bison/yacc if you want an AST, by creating your own nodes and assigning them to $$.

The example at http://epaperpress.com/lexandyacc/ (look at the .y file in Calculator->Yacc input) or http://www.progtools.org/compilers/tutorials/cxx_and_bison/cxx_and_bison.html might give you ideas on how to do that.