parser.mly 710 B

12345678910111213141516171819202122232425262728293031
  1. %{
  2. open Lexing
  3. open Types
  4. %}
  5. (* tokens *)
  6. %token SEMICOL EXCLAM PLUS MINUS OMEGA LPAREN RPAREN HASH
  7. %token <int> NUMBER
  8. %token <char> UPPER LOWER
  9. %token EOF
  10. (* start symbol *)
  11. %type <Types.program> program
  12. %start program
  13. %%
  14. program:
  15. | instrs=separated_list(SEMICOL, instruction) EOF
  16. { instrs }
  17. instruction:
  18. | c=LOWER { Basic c }
  19. | EXCLAM { Terminate }
  20. | PLUS c=LOWER { Ptest c }
  21. | MINUS c=LOWER { Ntest c }
  22. | HASH n=NUMBER { Jump n }
  23. | i=instruction n=NUMBER { Repeat (i, n) }
  24. | i=instruction OMEGA { Loop i }
  25. | c=UPPER { Program c }
  26. | LPAREN i=separated_list(SEMICOL, instruction) RPAREN { Concat i }