add comments

This commit is contained in:
Mylloon 2022-12-09 22:14:18 +01:00
parent f657f8d9d7
commit 41664b64bd
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -10,7 +10,8 @@
%token Lend Lassign Lsc Lreturn
%token Ladd Lsub Lmul Ldiv
%left Ladd Lsub Lmul Ldiv
%left Ladd Lsub
%left Lmul Ldiv
%start prog
@ -19,42 +20,65 @@
%%
prog:
/* Fin de programme */
| Lend { [] }
/* instr; */
| i = instr ; Lsc ; b = prog { i @ b }
;
instr:
/* return x */
| Lreturn ; e = expr { [ Return { expr = e ; pos = $startpos } ] }
/* type v */
| t = Ltype ; v = Lvar {
[ Decl { name = v ; type_t = t ; pos = $startpos(t) } ]
}
/* type v = e */
| 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 = e */
| v = Lvar ; Lassign ; e = expr {
[ Assign { var = v ; expr = e ; pos = $startpos($2) } ]
}
expr:
/* int */
| n = Lint {
Val { value = Int (n) ; pos = $startpos(n) }
}
/* bool */
| b = Lbool {
Val { value = Bool (b) ; pos = $startpos(b) }
}
/* Variable */
| v = Lvar {
Var { name = v ; pos = $startpos(v) }
}
/* e + e */
| a = expr ; Ladd ; b = expr {
Call { func = "%add" ; args = [ a ; b ] ; pos = $startpos($2) }
}
/* e - e */
| a = expr ; Lsub ; b = expr {
Call { func = "%sub" ; args = [ a ; b ] ; pos = $startpos($2) }
}
/* e * e */
| a = expr ; Lmul ; b = expr {
Call { func = "%mul" ; args = [ a ; b ] ; pos = $startpos($2) }
}
/* e / e */
| a = expr ; Ldiv ; b = expr {
Call { func = "%div" ; args = [ a ; b ] ; pos = $startpos($2) }
}