This repository has been archived on 2022-12-27. You can view files and clone it, but cannot push or open issues or pull requests.
compilateurMIPS/parser.mly
2022-12-08 21:30:39 +01:00

48 lines
827 B
OCaml

%{
open Ast
open Ast.Syntax
%}
%token <int> Lint
%token <bool> Lbool
%token <Ast.type_t> Ltype
%token <string> Lvar
%token Lend Lassign Lsc
%start prog
%type <Ast.Syntax.block> prog
%%
prog:
| Lend { [] }
| i = instr; Lsc; b = prog { i @ b }
;
instr:
| t = Ltype; v = Lvar {
[ Decl { name = v; type_t = t; pos = $startpos(t) } ]
}
| t = Ltype; v = Lvar; Lassign; e = expr
{ [ Decl { name = v; type_t = t; pos = $startpos(t) }
; Assign { var = v; expr = e; pos = $startpos(v) } ]
}
| v = Lvar; Lassign; e = expr
{ [ Assign { var = v; expr = e; pos = $startpos(v) } ]
}
expr:
| n = Lint {
Val { value = Int (n) ; pos = $startpos(n) }
}
| b = Lbool {
Val { value = Bool (b) ; pos = $startpos(b) }
}
| v = Lvar {
Var { name = v ; pos = $startpos(v) }
}
;