Advertisement
Guest User

Untitled

a guest
Jun 4th, 2016
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. %token <Ast.expr> NUMERIC
  2. %token <Ast.expr> STRING
  3. %token <string> ID
  4. %token COMMA EQ FUNCTION LBRACE RBRACE
  5. %token LPAREN RPAREN LBRACKET RBRACKET EOF SEMI LEFTARROW
  6. %type <Ast.expr> expr
  7. %start expr
  8. %%
  9.  
  10. expr:
  11. | LBRACE expr SEMI expr RBRACE {CompoundExpression($2, $4)}
  12. | ID LBRACKET LBRACKET expr RBRACKET RBRACKET {ArrayAccess(Symbol($1), $4)}
  13. | FUNCTION LPAREN sublist RPAREN expr {FunctionDeclaration($3,$5)}
  14. | ID LPAREN subarg RPAREN {Application(Symbol($1),$3)}
  15. | ID LEFTARROW expr {AssignExpression(Symbol($1),$3)}
  16. | ID LBRACKET LBRACKET expr RBRACKET RBRACKET LEFTARROW expr {ArrayAssignWithIndex(Symbol($1),$4,$8)}
  17. | term {$1}
  18.  
  19. term:
  20. | ID {Symbol($1)}
  21. | NUMERIC {$1}
  22. | STRING {$1}
  23.  
  24. sublist :
  25. | subF {$1}
  26. | subF COMMA sublist {$1@$3}
  27. | {[]}
  28.  
  29. subarg :
  30. | subA {$1}
  31. | subA COMMA subarg {$1@$3}
  32. | {[]}
  33.  
  34. subF :
  35. | ID {[Identifier($1)]}
  36. | ID EQ expr {[AssignParam($1,$3)]}
  37.  
  38. subA:
  39. | expr {[Expr($1)]}
  40. | ID EQ expr {[AssignArg($1,$3)]}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement