[antlr-interest] Variable definition annoyances
Scott Stanchfield
scott at javadude.com
Fri Mar 25 19:30:22 PST 2005
> Yep, that is really annoying. I racked my brain over it for
> a long time. It turns out you don't need to define them
> anymore. You can do
> this:
>
> start : r=rule { @r.i ... @r.s ... } ;
I pretty-much like, but can't we infer a variable for the rule? So it would
just be:
start
: rule { @rule.i ... } ;
You could easily do this by genning
ResultType __rule = rule();
__rule.i
Or some such thing.
For multiple refs. They could be numbered:
start
: rule otherRule rule { @rule[1].i ... @rule[2] ... }
;
Which could expand to
__rule_1 = rule();
__otherRule = otherRule();
__rule_2 = rule();
...
Though while we're at it, I'd really like to define a standard syntax that
can be for antlr replacement in action code with an obvious start and end,
which is why I suggested a paired delimiter like :: on either end. We'd just
need to pick something not super likely to appear in the action code...
> rule returns [int i, String s] : ... {@i=3; @s="foo";} ... ;
>
> Cool eh? Does this satisfy you? It integrates very nicely
> with the dynamically scoped attributes and trees etc...
Actually, why would we need to use the @ in that syntax? In ANTLR 2.0 with
the same syntax we just use i and s... Wait a sec... Multiple return
values? Are you pushing them on a stack or something?
-- Scott
More information about the antlr-interest
mailing list