Created
May 2, 2016 15:38
-
-
Save jrozner/115cf98b9c8321b85741baf14796efc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar Test; | |
root: expr EOF; | |
expr: | |
expr OR expr | |
| expr XOR expr | |
| expr AND expr | |
| INT | |
; | |
INT: [0-9]+; | |
AND: 'and'; | |
XOR: 'xor'; | |
OR: 'or'; | |
WS: (' ' | '\r' | '\n' | '\t') -> skip; |
There are no other files in the directory and I'm running this with "grun Test root -tokens -gui" with the input "2 or 3 and 4". With the above grammar the AND is at the top but from what you've said OR should be in the above case because it is the first alternative, correct?
works for me. OR is lowest in tree as it is first precedence, binding it tighter to 2, 3 leaves.
2 or 3 and 4
[@0,0:0='2',<1>,1:0]
[@1,2:3='or',<4>,1:2]
[@2,5:5='3',<1>,1:5]
[@3,7:9='and',<2>,1:7]
[@4,11:11='4',<1>,1:11]
[@5,13:12='<EOF>',<-1>,2:0]
(root (expr (expr (expr 2) or (expr 3)) and (expr 4)) <EOF>)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
AND should be first. That really should work. could be issue with test!=Test. do you have another file in same dir?