I have just started using antlr3 and am trying to serialize the AST output of a .g grammar.
Thanks,
Lezan
I have just started using antlr3 and am trying to serialize the AST output
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
As Vladimir pointed out, you can use a a custom AST node class that has serialize capabilities builtin. You could also use a tree adaptor to create the types of nodes you need.
If you only need serialization, and not de-serialization, you could probably just do:
The above will give you a LISP like tree structure. An easy way to do serialization would be to use that in combination with a custom AST node class with an overridden
toString(). SincetoStringTree()uses the node’stoStringTreemethod, it’ll essentially serialize whatever you put intoString. Make its output sufficient and useful and you should be set.