Store antlr parse tree #4728
Replies: 1 comment
-
|
Correct, many grammars are ambiguous or have large max-k's. The architects of Antlr4 believed that one could simply regenerate the tree from scratch quickly. But it's basically wrong. Most grammars in gramamrs-v4 are ambiguous. Antlr4 does have a serialized representation of the parse tree with Tree.ToStringTree(Parser). But, this representation does not output the token type of the leaf nodes of the parse tree, which makes it almost useless. There is no DOM representation implemented in the runtime. Trash represents parse trees as a DOM, but it's in C#, not Python3. You'll need to write your own. Trash uses DOM attributes to represent white space, comments, line numbers, etc. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am developing a Tool that converts C++ Code. Within the tool i have two runs of my tool. Between the runs users can edit output from first run and can use it for the second run as configuration.
My tool is written in python and uses the visitor pattern.
For larger C++-Input the generation of the parse tree takes quiet some time. It isn't a big deal but a bit annoying. So i wondered if there is a way to store a parse-tree to a file that I can reuse for the second run.
It seems the issue is the serialization of the context objects as they have attributes that can't be serialized. Going through the web didn't bring a solution, so I thought i just ask here and may receive answers from some people more in to the antlr project.
Thanks in advance for your answers
Beta Was this translation helpful? Give feedback.
All reactions