[antlr-interest] Re: Putting this all into an AST

lgcraymer lgc at mail1.jpl.nasa.gov
Thu Mar 4 16:34:42 PST 2004


I have to disagree with Monty, here (sorry, Monty).  There are a few tricks that you can do.  First of all, you want a value rule that 
builds the subtree with VALUE as root.  The WORD ( DOT WORD )* can be refactored as

WORD ( DOT^ WORD ( DOT! WORD )* )?

to build a tree #( DOT (WORD)+ ) or a single node WORD

name should probably be inlined (ugly, but that's the way ANTLR 2 works) with ^ appended to each of the token names, but as a 
brutal hack you can also do

n:name!  { astFactory.makeASTRoot(currentAST, #n); }

That's pretty ugly, but 2.8 (if Ter can get a final 2.7.3 release out the door and I can find time to finish testing the C++ interface) will 
provide a better alternative.

--Loring


--- In antlr-interest at yahoogroups.com, mzukowski at y... wrote:
> You need some imaginary nodes, search for "Imaginary nodes" in Ter's lecture
> http://www.cs.usfca.edu/~parrt/course/652/lectures/java.ast.html
> 
> Monty
> 
> -----Original Message-----
> From: Chris Rose [mailto:offline at s...] 
> Sent: Thursday, March 04, 2004 3:30 PM
> To: antlr-interest at yahoogroups.com
> Subject: [antlr-interest] Putting this all into an AST
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> Here's what i'm working with -- or at least an example of it:
> 
> i have a line from the vCard that will be (for example) this:
> 
> com.foo.FN;CHARSET=US-ASCII;ENCODING=8BIT:Rose;Chris;;;;
> 
> This is parsed and recognized (so far correctly) as the following tokens:
> 
> Type: "WORD" ["com",<33>,line=1,col=1]
> Type: "DOT" [".",<8>,line=1,col=4]
> Type: "WORD" ["foo",<33>,line=1,col=5]
> Type: "DOT" [".",<8>,line=1,col=8]
> Type: ""fn"" ["FN",<16>,line=1,col=9]
> Type: "SEMI" [";",<34>,line=1,col=11]
> Type: ""CHARSET"" ["CHARSET",<39>,line=1,col=12]
> Type: "EQUALS" ["=",<36>,line=1,col=19]
> Type: ""us-ascii"" ["US-ASCII",<51>,line=1,col=20]
> Type: "SEMI" [";",<34>,line=1,col=28]
> Type: ""ENCODING"" ["ENCODING",<38>,line=1,col=29]
> Type: "EQUALS" ["=",<36>,line=1,col=37]
> Type: ""8bit"" ["8BIT",<48>,line=1,col=38]
> Type: "VALUE" ["Rose;Chris;;;;
> 
> So how do i build a tree out of this?  FN should be the root, with the
> WORD (DOT WORD)* preceding it as one descendant, the params as a
> separate descendant, and the value as the third, and then another
> similar item as its right neighbor.
> 
> Thing is, "FN" is one of about 30 possible words there, so i have them
> in a parser rule called "name" - but i can't make that the root of a
> tree (antlr throws a fit when i try to append a '^' to name)
> 
> The same problem comes in everywhere else - the parameter names and
> accepted values are in parser rules as well.  So how do i generalize
> this to build a tree like the one i'm talking about?
> 
> - --
> Chris R.
> =======
> http://offlineblog.com/
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.2.2 (Cygwin)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
> 
> iD8DBQFAR7wLYGWCRcy3UcsRAlnVAJ0ffZ7RcQy0LxEepG4T14xKEP/azACffebA
> OZbBom517Deoo4JmbTcHkWE=
> =9jXQ
> -----END PGP SIGNATURE-----
> 
> 
>  
> Yahoo! Groups Links



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/antlr-interest/

<*> To unsubscribe from this group, send an email to:
     antlr-interest-unsubscribe at yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 



More information about the antlr-interest mailing list