Precise precedence

26 views
Skip to first unread message

Tjad Clark

unread,
Oct 30, 2013, 10:19:20 AM10/30/13
to antlr-di...@googlegroups.com
Hi

I am having precedence issues where I would like to control precisely how the precedence works.


Example

RULE_A
   
//More specific than RULE_B (Larger)
;


RULE_B
   
//Some rule also matched by RULE_A
;


RULE_C
   
: RULE_B
   
| RULE_A
;



I would like RULE_B to be matched instead of RULE_A and there is no way to differentiate RULE_B from RULE_A

So I tried to use gate predicates as follows

@members { boolean notB = true }

RULE_C
   
: RULE_B {notB = false}
   
| {notB}? RULE_A
;

However to my surprise, this didn't work as the action does not get executed.

This would mean the lexing is being done as a side process - only returning the matched rule, and thereafter executing the matched rule's action code. In other words it will run through RULE_B, then run through RULE_A, and return as RULE_A as that rule is more specific.

Is there a way to change the variable 'notB' (execute the action) during the lexing ?

Terence Parr

unread,
Oct 30, 2013, 11:09:55 AM10/30/13
to antlr-di...@googlegroups.com
hi. try fragment keyword on A and B.
Ter
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Tjad Clark

unread,
Oct 30, 2013, 4:25:25 PM10/30/13
to antlr-di...@googlegroups.com
Perfect! Thanks a million!! :)

Hmmm.. Will need to read up on that section again


--
You received this message because you are subscribed to a topic in the Google Groups "antlr-discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/antlr-discussion/nqzdot0-hKM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to antlr-discussi...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages