nand2tetris/assembler/lib/Parser.mly

31 lines
562 B
OCaml

%{
open Ast
%}
%token <string> ID
%token <string> COMMENT
%token AT
%token LPAREN
%token RPAREN
%token SCOLON
%token EQUALS
%token EOF
%start <Ast.expr> prog
%%
prog:
| e = expr; EOF { e }
;
expr:
| c = COMMENT { Comment c }
| AT; a = ID; { Ainstr a }
| LPAREN; s = ID; RPAREN { Ginstr s }
| c = ID; SCOLON; j = ID { Cinstr ("", c, j) }
| d = ID; EQUALS; c = ID { Cinstr (d, c, "") }
| c = ID; { Cinstr ("", c, "") }
| e = expr; COMMENT { e }
;