Skip to content

Instantly share code, notes, and snippets.

@jrozner
Created May 2, 2016 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrozner/115cf98b9c8321b85741baf14796efc1 to your computer and use it in GitHub Desktop.
Save jrozner/115cf98b9c8321b85741baf14796efc1 to your computer and use it in GitHub Desktop.
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;
@parrt
Copy link

parrt commented May 2, 2016

AND should be first. That really should work. could be issue with test!=Test. do you have another file in same dir?

@jrozner
Copy link
Author

jrozner commented May 3, 2016

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?

@parrt
Copy link

parrt commented May 6, 2016

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