[antlr-interest] brief analysis of java.g's tree building in 2.x vs proposed 3.0

Dean Tribble tribble at e-dean.com
Tue Feb 1 02:06:15 PST 2005


Terence Parr wrote:

> The real test of any proposal is to see what it looks like in
> practice. I have looked again at the java grammar. Here is some useful
> info.

For another antlr grammar, please check out:

http://www.erights.org/e-impls/e-on-e/egrammar/

which includes the grammar for the E language (and its two lexers). The
grammar is still under development (e.g., not all productions make the
right trees), but I spent a lot of time trying to figure out how to make
trees (e.g., for left and right associativity). I like the idea of
improving the tree construction support. I've tried very hard in the
grammars to stay within the antlr-only syntax, and avoid using Java
action code. Any cleanup so that the grammar is more obvious (and so
that the grammar is not shaped by the needs of tree construction) would
be excellent.

Incidentally, in your examples below, I don't understand why you don't
use the ## shortcut to refer to the current node when comparing new and
old syntaxes. For example,

> modifiers
> : ( modifier )*
> {#modifiers = #([MODIFIERS, "MODIFIERS"], #modifiers);}
> ;

should be
modifiers
: ( modifier )*
{##= #([MODIFIERS, "MODIFIERS"], ##);}
;

which, while easy to improve upon, is still a lot less verbose than the
previous version.

> implementsClause
> : ( i:"implements"! identifier ( COMMA! identifier )* )?
> {#implementsClause = #(#[IMPLEMENTS_CLAUSE,"IMPLEMENTS_CLAUSE"],
> #implementsClause);}
> ;

implementsClause
: ( "implements"! identifier ( COMMA! identifier )* )?
{##= #([IMPLEMENTS_CLAUSE,"IMPLEMENTS_CLAUSE"],##);}
;
another example.

A particular thing I wanted to be able to do is to say "for the node in
which you recognize "if", make the node of type IfExpr, but I had to
explicitly either set the type or create a new parent node.

>
>
>



More information about the antlr-interest mailing list