[antlr-interest] Help getting familiar with ANTLR

Oscar Simpson oscar_j_simpson at yahoo.com
Fri Jun 17 23:41:12 PDT 2005


Quickie background: My current project incorporates the SpiderMonkey
javascript engine to allow users to extend and enhance the functionality of
my app. While javascript is certainly capable for extending certain
functionality it is not suitable as a long term solution. In order to provide
a long term solution I have worked out a design for a language based on
ECMA-334 (C#) with significant extensions to delegates, exception handling,
switch/case statements with support for expressions and ranges, state
mechanisms, and several items specific to my application.

Over the years I've written several compilers with most having the lexer
based on an earlier compiler and the rest either generated from Bison (or
Bison++) or hand coded. Having hand coded a K&R compiler with extensions by
hand and dealing with using the Bison output in C++ I'm not looking forward
to doing either ever again. I've looked at several of the LALR, LL, and LR
parser generators and finally settled on ANTLR as it fits perfectly with
everything I'm looking for.

During my initial evaluation I used the 2.7.5 distro and used both the Java
1.3 and TinyC grammars. Between the FAQ, docs, and tutorials I'm slowly
coming up to speed in using ANTLR (as opposed to Bison) and so far I've
managed to be successful in modifying the Java 1.3 grammar to produce
expected results in the AST (and handle errors and very strict syntax
changes). I do however have a few questions concerning results I would like
to see.


1. Has anyone come up with a good approach for supporting #if/#else/#endif to
eliminate the need for a preprocessor?

2. Have the problems with using C++ and large grammars been fixed (i.e.
grammar size = 65536)? While not a problem at the moment I expect my grammar
to come close in size to the one for Java 1.5.

3. Is there an example dealing with parameterized classes? I know that both
the C++ and Java 1.5 grammars include this but with the entire grammar there
it's a little difficult isolating the innards that handle it.

4. In ANTLR is the operator precedence explicit or implied? I noticed that
the Java 1.3 grammar included the precedence level in the comments but there
didn't appear to an explicit declaration. If they are implicit by the order
of declaration is there a way to explicitly set the precedence?

***Note: From what I can tell the operator precedence in the AST is implicit
by order of inclusion - just want to make sure that's the case.



Most of these questions certainly come from the fact that I'm not up to speed
on ANTLR yet but I'm definitely getting the hang of it. I do have a few other
questions but I'm going to wait until I'm more familiar with ANTLR before I
post them.


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


More information about the antlr-interest mailing list