[antlr-interest] Why cant += be used without an "output=" option (and other Q's)

Thomas Brandon tbrandonau at gmail.com
Fri Feb 15 17:45:05 PST 2008


On Feb 16, 2008 12:00 PM, Benjamin Shropshire
<shro8822 at vandals.uidaho.edu> wrote:
> I want to create a grammar that has a repeated term in it:
>
> rule : red+;
>
> Then I want to add an action to this rule that collects the red's and
> returns the list of them. Thats shouldn't be to hard:
>
> rule returns [IList l ]:  (i += red)+ {$l = $i};
>
> but antlr now insistent I add
>
> options { output=template; }
> or
> options { output=AST; }
>
> but both of these are worthless for my needs; 'template' turns i into a
> list of StringTemplate's and 'AST' try to do something with tree's. What
> I want is to just get a list of the things that red returns.
>
> Is this even possible?
>
This is a bug (or perhaps better an oversight) in ANTLR 3.0.1 that I
believe has been fixed in the latest intermediate release of ANTLR.
ANTLR did not allow labels in parsers without an output. I think the
intermediate builds should be fairly stable as far as basic
functionality goes and I believe a release is due fairly soon. Or as a
workaround in the current version you can add output=AST and ignore
the AST tree, you will be able to access both the returned AST and any
custom rule returns (use $i.l instead of just $i). Or you could build
an AST and then have your application deal with this instead of
directly collecting a list.
> If it isn't that either antlr has a _serious_ design flaw or it has bean
> _seriously_ miss-marketed. This operation (parse a tree and give me, the
> user, unrestricted and direct access to the actual things that was
> parsed by the referenced rules) is the ONLY thing I was looking for when
> I found antlr. From a first pass over the documentation I got the
> impression that it would give me this. From trying to do this, I'm
> beginnings to fear that it is utterly impossible!
>
> Seriously people, you seem to have a major problem. If antlr isn't
> supposed to do what I'm wanting it to do, why has it taken me 2 weeks to
> learn this? If antlr can do this, why haven't I yet bean able to figure
> out how? (I really hope it isn't the other possibility that antlr is
> just flat broken.)
I can't say exactly why it took you so long to get to this point. I
would imagine a need to familiarise yourself with the more basic
aspects of ANTLR played some role. The fact that you ran into an issue
in the current release played a fairly major role. The fact that this
isn't a totally standard way of proceeding doesn't help either. More
usually you would output an AST or use templates to generate output so
this sort of processing isn't the major focus of ANTLR. It should do
it certainly but the documentation and testing isn't focussed on it.
And certainly the state of the ANTLR documentation doesn't help. This
has been discussed. There is the book which is currently the most
complete reference, though in your case even this may not have made
this immediately obvious due to the previous point. As an open source
project Terrence directs his time based on his own needs, as he
should. There have been more pressing concerns for him than
documentation. Others are free to work on the documentation through
the wiki, this is still a work in progress though. If you are
dissatisfied with this then perhaps a commercial product would better
meet your demands.

Tom.
>
> Benjamin Shropshire
>
>
>
>


More information about the antlr-interest mailing list