blob: d757ab920759bf8547617b2230503ccb78ea7339 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
%%
optionnal_delimited(opening, X, closing):
| v = delimited(opening, X, closing) { v }
| v = X { v }
(* Redefine the arguments from expression here because we accept
* values without parens. *)
argument(X):
| a = optionnal_delimited(L_PAREN, arguments(X), R_PAREN) { a }
| a = X { [ a ] }
(** At the opposite of an expression, an instruction does not return anything. *)
%public instruction:
| expr = expression
{
let expr = Analyzer.Expression.v expr in
Analyzer.Instruction.expression expr
}
| e = let_assignation { e }
| k = keyword
args = argument(expression)
{
let args = List.map args ~f:(Analyzer.Expression.v) in
Analyzer.Instruction.call $loc k args
}
keyword:
| k = KEYWORD { k }
let_assignation:
| assignation
variable = variable
op = assignation_operator
value = expression
{
let variable = Helper.variable variable
and value = Analyzer.Expression.v value in
Analyzer.Instruction.assign $loc variable op value
}
%inline assignation:
|
| LET
| SET {}
assignation_operator:
| EQUAL { T.Eq' }
| INCR { T.Inc }
| DECR { T.Decr }
| MULT_EQUAL { T.Mult }
| DIV_EQUAL { T.Div_assign }
|