SHARE
TWEET

Untitled

a guest May 27th, 2018 196 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Mateusz Sanejko 271087
  2. //Gramatyka P3B
  3.  
  4. grammar Demo;
  5.  
  6. prog: ( stat? NEWLINE )*
  7. ;
  8.  
  9. stat:    ID '=' expr0       #assign
  10.     | PRINT ID          #print
  11.     | READ ID       #read
  12. ;
  13.  
  14. expr0:  expr1           #single0
  15.       | expr1 ADD expr1     #add
  16.     | expr1 SUB expr1   #sub
  17. ;
  18.  
  19. expr1:  expr2           #single1
  20.       | expr2 MULT expr2    #mult
  21.     | expr2 DIV expr2   #div
  22. ;
  23.  
  24. expr2:   INT            #int
  25.        | REAL           #real
  26.        | TOINT expr2        #toint
  27.        | TOREAL expr2       #toreal
  28.        | '(' expr0 ')'      #par
  29. ;  
  30.  
  31. PRINT:  'print'
  32.     ;
  33.  
  34. READ:   'read'
  35.    ;
  36.  
  37. TOINT: '(int)'
  38.     ;
  39.  
  40. TOREAL: '(real)'
  41.     ;
  42.  
  43. ID:   ('a'..'z'|'A'..'Z')+
  44.    ;
  45.  
  46. REAL: '0'..'9'+'.''0'..'9'+
  47.     ;
  48.  
  49. INT: '0'..'9'+
  50.     ;
  51.  
  52. ADD: '+'
  53.     ;
  54.  
  55. SUB: '-'
  56.     ;
  57.  
  58. MULT: '*'
  59.     ;
  60.  
  61. DIV: '/'
  62.     ;
  63.  
  64. NEWLINE:    '\r'? '\n'
  65.     ;
  66.  
  67. WS:   (' '|'\t')+ { skip(); }
  68.     ;
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top