[antlr-interest] Stuff I don't like about ANTLR 2.x /ANTLR 3 wants

Richard Matthias richard at exaflop.org
Mon Mar 15 15:15:07 PST 2004


Hi,

1. The syntax for manual tree building. It looks an absolute mess with all
those # and [] marks. I assume this is because it sits in with action code in
the target language and you have to use syntax that won't clash with any
language known to man. Because tree building is free it only increases the
impact of the tree building syntax obscurity for occasional ANTLR users like
myself. What I would like to see is some simple ANTLR specific syntax for
tree building that exists outside the actions block.

2. Different syntax for manipulating tokens in Lexer actions compared to
manipulation of AST nodes in Parser actions. For example, in the Parser I can
change the AST node class from "within ANTLR syntax", but I still have to use
action code to change the node to use an 'imaginary' token. For example:-

unary
	: PLUS^<AST=iASTUnaryOp>   {#PLUS.setType(UNARYPLUS);} unary
	| MINUS^<AST=iASTUnaryOp>  {#MINUS.setType(UNARYMINUS);} unary
	| atom ( PERCENT^<AST=ASTUnaryOp> )?
	;

Whereas in the lexer, I sometimes want to change the token and have to use an
action (again), but this time have different syntax (it took me a while to
work this out too when I first started with ANTLR on this project):-

LESSTHAN		: "<"		;
LESSTHAN2		: "_lt_" { _ttype = LESSTHAN; };

(as an aside, I never really worked out why I couldn't use LESSTHAN: "<" |
"_lt_"; here. It consistently produced nondeterminism errors no matter how
much lookahead I allowed, yet this apparently equivalent construct works
fine. Thankfully its easy to change the token type (once you know the magic
syntax) so it didn't cause a major problem).

Another concern here is these actions are presumably quite dependent on the
object model employed by the target language selected. Given the proposed
language agnosticism of ANTLR3, doing common things like this without having
to dip into action code would be 'a good thing' IMO.

3. Actually that's it I think. I still think ANTLR is a great program and am
very glad to have it. I've been following PCCTS/ANTLR for a long time now
(I'm proud owner of an actual paper copy of the PCCTS book!), but I haven't
used it in anger until recently. Big thanks are also due to the people that
put the C# code-generator together!

Regards,

Richard Matthias




 
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