Safiye Celik wrote:
> Hi,
> I have to write a lexical rule such as
> 
> a: b c b
> b: D | E
> 
> and I want 'b' tokens in rule 'a' to be the same. That's, when the first 'b2
> in 'a' is D, then the last 'b' should be D. The same is true for E.
> 
> To provide this, do I have to write two alternatives for 'a' (that is, a: D
> c D | E c E) or is there an easier way to make ANTLR to provide this
> condition?

I think "a: D c D | E c E;" is probably the easiest way.

An alternative is

  a: x=b c y=b { $x != null && $y != null && $x.text.equals($y.text) }?;
  b: D | E;

but that is hardly simpler. (Also note that it is only equivalent when
D and E are fixed tokens, and it might have worse error recovery
behaviour.)

> I have to use explicit version (righthandside) of rule 'a' in
> many rules, so it would be good if I have a chance to write 'a' in one
> alternative.

Why do you need to use the RHS of rule 'a' rather than just saying "a"?

-- 
David-Sarah Hopwood  ⚥  http://davidsarah.livejournal.com


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to