SHARE
TWEET

Untitled

a guest Jun 19th, 2018 184 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. IDENTIFIER: /[A-Za-z_?!][A-Za-z0-9_?!]*/
  2. INTEGER: ("0".."9")+
  3. COMMENT: "//" /[^\n]*/
  4.  
  5. top_level_compound: top_level_single* -> multi
  6.  
  7. top_level_single: "function" IDENTIFIER arg_list multi_stmt? "end" -> function
  8.                 | "procedure" IDENTIFIER multi_stmt? "end" -> procedure
  9.                 | "structure" IDENTIFIER *IDENTIFIER "end"
  10.                 | "const" IDENTIFIER "=" expr
  11.  
  12. multi_stmt: stmt (";"? stmt)* -> multi
  13.  
  14. stmt: expr -> const
  15.     | "return" expr -> return_
  16.     | "break" -> break_
  17.     | "if" expr "then" multi_stmt? ("elseif" expr "then" multi_stmt?)* "end" -> if_no_else
  18.     | "if" expr "then" multi_stmt? ("elseif" expr "then" multi_stmt?)* "else" multi_stmt? "end" -> if_else
  19.     | "while" expr "do" multi_stmt? "end" -> while_
  20.     | IDENTIFIER "=" expr -> assign
  21.  
  22. expr: sum -> const
  23.     | expr "." expr -> get_attr
  24.     | bool_sum -> const
  25.     | list -> const
  26.     | range_literal -> const
  27.     | expr arg_list -> func_call
  28.     | expr "==" expr -> eq
  29.     | expr ">" expr -> gt
  30.     | expr "<" expr -> lt
  31.     | expr ">=" expr -> ge
  32.     | expr "<=" expr -> le
  33.     | "#" expr -> length
  34.  
  35. list: "[" compound_expr "]" -> list_
  36.     | "[]" -> list_
  37.  
  38. arg_list: "(" compound_expr ")" -> list_
  39.     | "()" -> list
  40.  
  41. range_literal: "{" atom ".." atom "}" -> range
  42.  
  43. compound_expr: expr ("," expr)* -> multi
  44.  
  45. bool_sum: bool_product -> const
  46.         | bool_sum "or" bool_product -> or_
  47.  
  48. bool_product: bool -> const
  49.             | bool_product "and" bool -> and_
  50.  
  51. bool: "true" -> boolt
  52.     | "false" -> boolf
  53.     | "not" bool -> not_
  54.     | "(" bool_sum ")" -> const
  55.  
  56. sum: product -> const
  57.    | sum "+" product -> add
  58.    | sum "-" product -> sub
  59.  
  60. product: atom -> const
  61.        | product "*" atom -> mul
  62.        | product "/" atom -> div
  63.        | product "%" atom -> mod
  64.  
  65. atom: INTEGER -> num
  66.     | IDENTIFIER -> iden
  67.     | ESCAPED_STRING -> string
  68.     | "(" sum ")" -> const
  69.  
  70. %import common.WS
  71. %import common.ESCAPED_STRING
  72.  
  73. %ignore WS
  74. %ignore COMMENT
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