-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.txt
88 lines (77 loc) · 1.51 KB
/
grammar.txt
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<program> ::=
[type_def]* <expr_seq> EOF
<types> ::=
| int
| bool
| unit
| REF <types>
| T_VAR
| T_VAR IDENT
| IDENT
| <types> -> <types>
| ( <types> )
<types_def> ::=
| type IDENT = { [[mutable]? IDENT : <types>;]+ }
| type [T_VAR]? IDENT = [ | UIDENT [of [<types> *]* <types>]? ]
<expr_seq> ::=
| <expr>
| <expr> ; <expr_seq>
<expr> ::=
| <s_expr>
| <uop> <exprssion>
| <expr> <binop> <expr>
| <app_expr> <simple_expr>
| REF <simple_expr>
| IDENT := <expression>
| if <expr_seq> then <expr>
| if <expr_seq> then <expr> else <expr>
| fun <fun_args> -> <expr_seq>
| <s_expr>.IDENT <- <expr>
| <s_expr>.(<expr_seq>) <- <expr>
| let [rec]? IDENT [<let_ags>]* [:<types>] = <expr_seq> in <expr_seq>
| MATCH <expression> WITH [pattern_expr]+
| <print_type> <simple_expr>
<s_expr> ::=
| n
| true | false
| ()
| IDENT
| ( expr_seq )
| <s_expr>.IDENT
| <s_expr>.(expr_seq)
| { [ IDENT = <expr>; ]* }
| [| [[ <s_expr>; ]* <s_expr>]? |]
| Array.create <s_expr> <s_expr>
| UIDENT [([<expr>, ]* <expr>)]?
<let_args> ::=
| IDENT
| ()
| (IDENT: <types>)
<print_type> ::=
| print_int
| print_bool
| print_char
| print_string
| print_endline
| print_newline
<pattern> ::=
| n
| id
| bool
| CONSTR
| CONSTR ( <pattern> [, <pattern>]* )
<pattern_expr> ::=
| | <pattern> -> expr_seq
<uop> ::=
| -
| not
| !
| Array.length | String.length
<binop> ::=
| + | -
| mod
| * | /
| == | !=
| = | <>
| <= | <
| || | &&