-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammer
88 lines (73 loc) · 1.08 KB
/
grammer
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
prog ::= func |
func prog
func ::= function iden ( flist ) returns type : body end |
body ::= stmt |
stmt body
stmt ::= expr ; |
defvar ; |
if ( expr ) stmt |
if ( expr ) stmt else stmt |
while ( expr ) do stmt |
foreach ( iden of expr ) stmt |
return expr ; |
: body end
defvar ::= val type iden
expr ::= iden ( clist ) |
expr [ expr ] |
expr ? expr : expr |
expr = expr |
expr + expr |
expr - expr |
expr * expr |
expr / expr |
expr % expr |
expr < expr |
expr > expr |
expr == expr |
expr != expr |
expr <= expr |
expr >= expr |
expr || expr |
expr && expr |
! expr |
- expr |
+ expr |
( expr ) |
iden |
num
flist ::= |
type iden |
type iden , flist
clist ::= |
expr |
expr , clist
type ::= Int |
Array |
Nil
num ::= [0-9]+
iden ::= [a-zA-Z_][a-zA-Z_0-9]*
expr :=
expr [ expr ] |
expr ? expr : expr |
expr + expr |
expr - expr |
expr * expr |
expr / expr |
expr % expr |
expr < expr |
expr > expr |
expr == expr |
expr != expr |
expr <= expr |
expr >= expr |
expr || expr |
expr && expr |
expr1 :=
expr ::= iden ( clist ) |
! expr |
- expr |
+ expr |
( expr ) |
iden |
num
iden = expr |