%{ open Lexing open Types %} (* tokens *) %token SEMICOL EXCLAM PLUS MINUS OMEGA LPAREN RPAREN HASH %token NUMBER %token UPPER LOWER %token EOF (* start symbol *) %type program %start program %% program: | instrs=separated_list(SEMICOL, instruction) EOF { instrs } instruction: | c=LOWER { Basic c } | EXCLAM { Terminate } | PLUS c=LOWER { Ptest c } | MINUS c=LOWER { Ntest c } | HASH n=NUMBER { Jump n } | i=instruction n=NUMBER { Repeat (i, n) } | i=instruction OMEGA { Loop i } | c=UPPER { Program c } | LPAREN i=separated_list(SEMICOL, instruction) RPAREN { Concat i }