Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. grammar Calculator;
  2.  
  3. @parser::members
  4. {
  5. protected const int EOF = Eof;
  6. }
  7.  
  8. @lexer::members
  9. {
  10. protected const int EOF = Eof;
  11. protected const int HIDDEN = Hidden;
  12. }
  13.  
  14. /*
  15. * Parser Rules
  16. */
  17.  
  18. prog: expr+ ;
  19.  
  20. expr : NOT expr # Not
  21. | expr op=('**') expr # Potencia
  22. | expr op=('AND') expr # AND
  23. | expr op=('OR') expr # OR
  24. | expr op=('*'|'/') expr # MulDiv
  25. | expr op=('+'|'-') expr # AddSub
  26. | INT # int
  27. | TRUE # true
  28. | FALSE # false
  29. | '(' expr ')' # parens
  30. ;
  31.  
  32. /*
  33. * Lexer Rules
  34. */
  35. TRUE : 'true';
  36. AND : 'and';
  37. OR : 'or';
  38. FALSE : 'false';
  39. NOT : '!';
  40. INT : [0-9]+;
  41. MUL : '*';
  42. DIV : '/';
  43. ADD : '+';
  44. SUB : '-';
  45. WS
  46. : (' ' | '\r' | '\n') -> channel(HIDDEN)
  47. ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement