[antlr-interest] antlrworks interpreter like serialized parse tree

Candide Kemmler candide at palacehotel.org
Mon Jan 25 12:42:39 PST 2010


Yes that's already what I'm doing but the AST (in the form of a CommonTree) is only really giving me the leaf tokens without the intermediary branches corresponding to the rules that "recognized" my programs.

I have attached an example of a test grammar to illustrate what I mean. The sample sentence where multiple rules are fired ("location", "when", "where",...) are shown in a nice hierarchy in AntlrWorks whereas in the debugger in Eclipse I can only see a flat structure where the root tree has a boring set of 6 children each corresponding to the final tokens of my sentence.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: astantlrworks.png
Type: image/png
Size: 11893 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100125/9a892bf1/attachment.png 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: astdebugger.png
Type: image/png
Size: 25082 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20100125/9a892bf1/attachment-0001.png 
-------------- next part --------------



Or maybe I am completely missing the point here...

On 25 Jan 2010, at 21:14, Gavin Lambert wrote:

> At 01:17 26/01/2010, Candide Kemmler wrote:
> >I love the parse tree representation that antlrWorks presents and
> >getting such a structure would be ideal for my use case. However I
> >can't seem to find a way to create a similar representation of the
> >parse tree using the API.
> 
> Normally you don't really want to generate the parse tree as shown in ANTLRworks -- that's purely a debugging aid.  For production use you're better off generating an AST instead; this way you have more control over the output and you can (among other things) refactor your parser without altering the output if you want to.
> 
> See the output=AST option and the various example grammars, wiki pages, and book chapters about AST construction.
> 



More information about the antlr-interest mailing list