[antlr-interest] on parsers look and feel

Cristian Amitroaie cristian at amiq.ro
Wed Nov 26 00:42:14 PST 2003


Hello guys,

Case:
   o sometimes I kind of foreget what name I gave to the "=" token from the 
Lexer (EQ/EQUAL/EQUALS/ASSIGN) when I want to add a new rule to a parser.
   o sometimes I get bored to write LCURLEY instead of "{" or '{'
   o sometimes it's hard for me to follow rules full of SEMI, LCURL(E)?Y, 
LBRACK, LPARENS and so on

For example, I would like to see my parser rules look like:

assign:
        ID "="^ ID ";"!
    ;

I browsed throw the documentation/big examples, yet I couldn't find any 
similar approach as a guideline or something.

Yet, it doesn't seem impossible (see the attached files).

Although the parsers token table won't have a token type attached to "=" (I 
asssume LITERAL_= is not a valid id in almost any language), it reserves a 
number for it. Now importing the parsers vocabulary in the lexer, and leaving 
testLiterals true (default value) it seems that the lexer's token table keeps 
the number from the parser for "=" and adds to it a token type 
(EQUAL/EQ/ASSIGN, oops I don't remember).

Are there any disadvantages/risks related to this approach?

Of course, in the parser, if somebody likes to build new AST nodes using "=", 
it may attach it a token type in the tokens section and use it...

Either I am a maniac, or the parser gramar looks much clearer to me...

And the walkers import the lexers vocabulary (see the attached files).

Or it's just a matter of taste?
Cristian




 

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: LookLexer.g
Type: text/x-java
Size: 550 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20031126/bd6dc24d/LookLexer.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LookWalker.g
Type: text/x-java
Size: 210 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20031126/bd6dc24d/LookWalker.bin
-------------- next part --------------
ana = mihai;
mihai = maria;
ana = maria;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: LookParser.g
Type: text/x-java
Size: 231 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20031126/bd6dc24d/LookParser.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Main.java
Type: text/x-java
Size: 984 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20031126/bd6dc24d/Main.bin


More information about the antlr-interest mailing list