SHARE
TWEET

Untitled

a guest Mar 22nd, 2019 153 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. parser grammar Parser;
  2.  
  3. options { tokenVocab=Lexer; }
  4.  
  5. start
  6.         : (functiondcl | stmt)* EOF;
  7.  
  8. stmt
  9.         : dcl
  10.         | ifstmt
  11.         | whilestmt
  12.         | returnstmt
  13.         | functioncall
  14.         | repeatuntilstmt
  15.         | fromstmt
  16.         | assignment ;
  17.  
  18. stmtblock
  19.         : LCB stmt* RCB ;
  20.  
  21. truthpar
  22.         : LPAR truthexpr RPAR ;
  23.  
  24. dcl
  25.         : (INTDCL ID (ASSIGN (value))?
  26.         |  FLOATDCL ID (ASSIGN (value))?
  27.         |  TEXTDCL ID (ASSIGN TEXT)?
  28.         |  TRUTHDCL ID (ASSIGN (truthexpr))?) EOL ;
  29.  
  30. functiondcl
  31.         : FUNCTION ID RETURNS type LPAR paramlist RPAR stmtblock
  32.         | FUNCTION ID LPAR paramlist RPAR stmtblock ;
  33.  
  34. paramlist
  35.         : (truedcl (COMMA truedcl)*)* ;
  36.  
  37. truedcl
  38.         : INTDCL ID
  39.         | FLOATDCL ID
  40.         | TEXTDCL ID
  41.         | TRUTHDCL ID ;
  42.  
  43. functioncall
  44.         : ID LPAR args RPAR; //TODO: EOL
  45. args
  46.         : (types (COMMA types)*)* ;
  47.  
  48. ifstmt
  49.         : IF truthpar THEN stmtblock
  50.           (ELSE IF truthpar THEN stmtblock)*
  51.           (ELSE THEN stmtblock)? ;
  52.  
  53. whilestmt
  54.         : WHILE truthpar DO stmtblock ;
  55.  
  56. repeatuntilstmt
  57.         : REPEAT stmtblock UNTIL truthpar ;
  58.  
  59. fromstmt
  60.         : FROM LPAR value (UPTO | DOWNTO) value RPAR stmtblock ;
  61.  
  62. returnstmt
  63.         : RETURN (value | truthexpr)* EOL ;
  64.  
  65. assignment
  66.         : (ID ASSIGN value
  67.         | ID ASSIGN truthexpr) EOL ;
  68.  
  69. value
  70.         : addexpr
  71.         | functioncall ;
  72.         //| ID ;
  73.  
  74. addexpr
  75.         :  nums (PLUS nums | MINUS nums)*
  76.         |  nums (TIMES nums | DIVIDES nums)*
  77.         |  nums
  78.         |  LPAR addexpr RPAR ;
  79.  
  80. truthexpr
  81.             : truth (OR | AND)*
  82.             | value EQUALS value
  83.             | value GRTHAN value
  84.             | value LESSTHAN value
  85.             | (NOT)? TRUTHID | ID
  86.             | LPAR truthexpr RPAR ;
  87.  
  88. truth
  89.         : TRUTHID
  90.         | ID ;
  91.  
  92. type
  93.         : INTDCL
  94.         | FLOATDCL
  95.         | TRUTHDCL
  96.         | TEXTDCL ;
  97. nums
  98.         : INUM
  99.         | FNUM
  100.         | ID ;
  101. types
  102.         : nums
  103.         | TEXT
  104.         | TRUTHID ;
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