[antlr-interest] Putting this all into an AST
Chris Rose
offline at shaw.ca
Thu Mar 4 15:30:20 PST 2004
-----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
<*> 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