--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
I think that you might need to go back in time for rewriting tree grammars to work. The templates were broken at one point and never got fixed if I remember correctly.
However, do you have the output=AST;Option set in your tree grammar? If you do not then I think you might not be able to use the += operator.
In general though, you are better off defining an interface for the external stuff and installing a pointer to this interface then calling indirectly through function pointers. Then your grammar stays the same and you can install different tree handlers. Accumulating the ID tokens is non-specific but you can also do: [...]
Jim
Hi,
Am Dienstag, 22. April 2014 03:02:09 UTC+2 schrieb Jim Idle:
I think that you might need to go back in time for rewriting tree grammars to work. The templates were broken at one point and never got fixed if I remember correctly.
And by "go back in time" you mean use an older version of antlr?
However, do you have the output=AST;Option set in your tree grammar? If you do not then I think you might not be able to use the += operator.
No, the AST option is only set in the grammar for parsing the input text, not in the tree grammar.
In general though, you are better off defining an interface for the external stuff and installing a pointer to this interface then calling indirectly through function pointers. Then your grammar stays the same and you can install different tree handlers. Accumulating the ID tokens is non-specific but you can also do: [...]I currently struggle a bit because I try to build a clean interface to get all the parsed data into nice C++ classes to avoid passing that nasty C stuff around in my application, but I haven't figured out the best way to do this by now... Any advices would be very welcome! ;-)
Jimchris
Then you will need to turn that on in your tree grammar to be able to use += I think. But as I say, That's probably too much overhead as you are not really re-writing trees.
Just copy the style of the interfaces in the C runtime - create a .h file with a struct that defines the interfaces as a list of pointers to functions, then populate a struct with pointers to your C++ methods marked as extern "C", but write everything in C++. The methods you call can build your C++ objects as a model of the program (or whatever it is you are parsing). Pass the pointer to structure in to the parser and make it available globally to your parser actions. Create macros to make the calls to your interface a little cleaner looking. Your action code should not contain any logic at all, just accumulate the token pointers you need and pass them off to your interface functions. This way if you want to reuse the tree walker to do something else with the same tree, you can just pass in a different interface. It isn't as neat as C++ inheritance etc, but it is quick and neat enough - once you have the grammar doing the interface calls you will only touch it if you change the grammar.
I apologize for the dull question but I am bit confused how I could create an interface to have a C++ class and invoke parser / tree walker functions in C.
Thank you in advance!
Patryk
--