[antlr-interest] Can I drive "CMinusWalker.g" from an external AST?

Gerald Rosenberg gerald at certiv.net
Mon Aug 2 16:10:32 PDT 2010


  ------ Original Message (Monday, August 02, 2010 11:28:13 
AM) From: Bob ------
Subject: [antlr-interest] Can I drive "CMinusWalker.g" from an external AST?
> Regarding "Building a tree grammar for the C-Language" chapter:
>
> My AST for "C-" is already built by non-Antlr means, however, it does match
> the "CMinus" grammar of chapter 8.2. To repeat, the AST image in 8.3, p200
> exists and was constructed outside of Antlr.
>
> I'd like to drive "CMinusWalker.g" by an in-order traversal of my AST (to
> serialize).
>
> Q: Can I do this, and what is this interface going to look like?
>     Assume my AST nodes have token id values from "CMinus.tokens".
Only if your AST is indistinguishable from an Antlr generated AST.  
Regardless of the picture, real Antlr ASTs have embedded DOWN and UP 
tokens delimiting subtrees.  Also, your individual tree node fields and 
methods would have to match up with Antlr CommonTree nodes - you will 
have to cast to CommonTree.  If you have this in place, then sure.
>     That is, how would this setup change?
Just substitute in your generated AST for the Antlr generated AST.

Unless there is some essential reason to use an Antlr walker, may be 
better to continue on with a non-Antlr solution.


More information about the antlr-interest mailing list