Advertisement
tinyevil

Untitled

Aug 25th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. [general]
  2. expose TopLevel
  3.  
  4. [ast]
  5. StmtList
  6. Cons (head, tail)
  7. Nil
  8.  
  9. Stmt
  10. Eval (expr)
  11. Assign (token, expr)
  12.  
  13. Expr
  14. BinOp (lhs, op:BinOp, rhs)
  15. Decimal (literal)
  16. Float (literal)
  17.  
  18. BinOp
  19. Or
  20. And
  21. EQ
  22. NE
  23. LE
  24. LT
  25. GE
  26. GT
  27. Sub
  28. Add
  29. Div
  30. Mul
  31. Pow
  32.  
  33. [grammar]
  34.  
  35. TopLevel
  36. | Statements
  37.  
  38. Statements : StmtList
  39. | Statement Statements {Cons($1,$2)}
  40. | {Nil}
  41.  
  42. Statement : Stmt
  43. | Expr {Eval($1)}
  44. | identifier = Expr {Assign($1,$3)}
  45.  
  46. Expr : Expr
  47. | expr[10]
  48.  
  49. expr[prec]
  50. prec = 10 | expr[10] or expr[9] {BinOp($1,Or,$3)}
  51.  
  52. prec = 9 | expr[9] and expr[8] {BinOp($1,And,$3)}
  53.  
  54. prec = 8 | expr[8] == expr[7] {BinOp($1,EQ,$3)}
  55. prec = 8 | expr[8] <> expr[7] {BinOp($1,NE,$3)}
  56. prec = 8 | expr[8] <= expr[7] {BinOp($1,LE,$3)}
  57. prec = 8 | expr[8] >= expr[7] {BinOp($1,GE,$3)}
  58. prec = 8 | expr[8] < expr[7] {BinOp($1,LT,$3)}
  59. prec = 8 | expr[8] > expr[7] {BinOp($1,GT,$3)}
  60.  
  61. prec = 7 | expr[7] - expr[6] {BinOp($1,Sub,$3)}
  62. prec = 7 | expr[7] + expr[6] {BinOp($1,Add,$3)}
  63.  
  64. prec = 6 | expr[6] / expr[5] {BinOp($1,Div,$3)}
  65. prec = 6 | expr[6] * expr[5] {BinOp($1,Mul,$3)}
  66.  
  67. prec = 5 | expr[4] ^ expr[5] {BinOp($1,Pow,$3)}
  68.  
  69. prec = 0 | prim_expr
  70.  
  71. prec > 0 | expr[prec-1]
  72.  
  73. prim_expr
  74. | decimal {Decimal($1)}
  75. | float {Float($1)}
  76. | ( expr[10] ) {$2}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement