qsp_instruction.mly 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. %%
  2. optionnal_delimited(opening, X, closing):
  3. | v = delimited(opening, X, closing) { v }
  4. | v = X { v }
  5. (* Redefine the arguments from expression here because we accept
  6. * values without parens. *)
  7. argument(X):
  8. | a = optionnal_delimited(L_PAREN, arguments(X), R_PAREN) { a }
  9. | a = X { [ a ] }
  10. (** At the opposite of an expression, an instruction does not return anything. *)
  11. %public instruction:
  12. | expr = expression
  13. {
  14. let expr = Analyzer.Expression.v expr in
  15. Analyzer.Instruction.expression expr
  16. }
  17. | e = let_assignation { e }
  18. | k = keyword
  19. args = argument(expression)
  20. {
  21. let args = List.map args ~f:(Analyzer.Expression.v) in
  22. Analyzer.Instruction.call $loc k args
  23. }
  24. keyword:
  25. | k = KEYWORD { k }
  26. let_assignation:
  27. | assignation
  28. variable = variable
  29. op = assignation_operator
  30. value = expression
  31. {
  32. let variable = Helper.variable variable
  33. and value = Analyzer.Expression.v value in
  34. Analyzer.Instruction.assign $loc variable op value
  35. }
  36. %inline assignation:
  37. |
  38. | LET
  39. | SET {}
  40. assignation_operator:
  41. | EQUAL { T.Eq' }
  42. | INCR { T.Inc }
  43. | DECR { T.Decr }
  44. | MULT_EQUAL { T.Mult }
  45. | DIV_EQUAL { T.Div_assign }