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

49 lines
827 B
OCaml
Raw Normal View History

2022-12-06 20:39:15 +01:00
%{
open Ast
open Ast.Syntax
%}
%token <int> Lint
2022-12-08 21:30:39 +01:00
%token <bool> Lbool
2022-12-08 19:55:22 +01:00
%token <Ast.type_t> Ltype
%token <string> Lvar
%token Lend Lassign Lsc
2022-12-06 20:39:15 +01:00
%start prog
2022-12-08 19:55:22 +01:00
%type <Ast.Syntax.block> prog
2022-12-06 20:39:15 +01:00
%%
prog:
2022-12-08 19:55:22 +01:00
| Lend { [] }
| i = instr; Lsc; b = prog { i @ b }
2022-12-06 20:39:15 +01:00
;
2022-12-08 19:55:22 +01:00
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) } ]
}
2022-12-06 20:39:15 +01:00
expr:
2022-12-08 19:55:22 +01:00
| n = Lint {
Val { value = Int (n) ; pos = $startpos(n) }
}
2022-12-08 21:30:39 +01:00
| b = Lbool {
Val { value = Bool (b) ; pos = $startpos(b) }
}
2022-12-08 19:55:22 +01:00
| v = Lvar {
Var { name = v ; pos = $startpos(v) }
}
2022-12-06 20:39:15 +01:00
;