-
Notifications
You must be signed in to change notification settings - Fork 1
/
parser.y
169 lines (130 loc) · 2.95 KB
/
parser.y
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
class Mlua::Parser
prechigh
nonassoc UMINUS
left '*' '/' '%'
left '+' '-' '..'
left '<<' '>>'
left '<' '>' '<=' '>='
left '==' '!='
left '&'
left '^'
left '|'
left '&&' 'and'
left '||' 'or'
right '=' '+=' '-=' '~='
preclow
expect 1
rule
chunk: _chunk_sub laststat_opt
| laststat_opt
_semi_opt: ';'
|
_chunk_sub: stat { @need_semi = true } _semi_opt { @need_semi = false }
| _chunk_sub stat { @need_semi = true } _semi_opt { @need_semi = false }
block: chunk
/* for yuusendo */
prefixexp: var
| functioncall
| '(' exp ')'
stat: varlist '=' explist
| functioncall
| lua52_label
| 'do' block 'end'
| 'while' exp 'do' block 'end'
| 'repeat' block 'until' exp
| 'if' exp 'then' block _elsif_list _else_opt 'end'
| 'for' NAME '=' exp ',' exp _comma_exp_opt 'do' block 'end'
| 'for' namelist 'in' explist 'do' block 'end'
| 'function' funcname funcbody
| 'local' 'function' NAME funcbody
| 'local' namelist _eq_explist_opt
_comma_exp_opt: ',' exp
|
_elsif_list: _elsif_list 'elseif' exp 'then' block
|
_else_opt: 'else' block
|
_eq_explist_opt: '=' explist
|
laststat_opt: laststat _semi_opt
|
laststat: 'return' _explist_opt
| 'break'
| lua52_goto
lua52_goto: 'goto' NAME
lua52_label: '::' NAME '::'
funcname: NAME _dot_name_list _colon_name_opt
_dot_name_list: _dot_name_list '.' NAME
|
_colon_name_opt: ':' NAME
|
varlist: varlist ',' var
| var
var: NAME
| prefixexp '[' exp ']'
| prefixexp '.' NAME
namelist: namelist ',' NAME
| NAME
_explist_opt: explist
|
explist: explist ',' exp
| exp
exp: 'nil'
| 'false'
| 'true'
| numeric
| STRING
| '...'
| function
| prefixexp
| tableconstructor
| binexp
| unop exp = UMINUS
numeric: FFI_INT64
| FFI_UINT64
| FFI_IMAGINARY
| NUMBER
functioncall: prefixexp args
| prefixexp ':' NAME args
args: '(' _explist_opt ')'
| tableconstructor
| STRING
function: 'function' funcbody
funcbody: '(' parlist ')' block 'end'
parlist: _parlist_sub NAME ',' '...'
| _parlist_sub NAME
| NAME ',' '...'
| NAME
| '...'
|
_parlist_sub: _parlist_sub NAME ','
| NAME ','
tableconstructor: '{' fieldlist '}'
fieldlist: _fieldlist_sub field fieldsep
| _fieldlist_sub field
| field fieldsep
| field
|
_fieldlist_sub: _fieldlist_sub field fieldsep
| field fieldsep
field: '[' exp ']' '=' exp
| NAME '=' exp
| exp
fieldsep: ',' | ';'
binexp: exp '+' exp
| exp '-' exp
| exp '*' exp
| exp '/' exp
| exp '^' exp
| exp '%' exp
| exp '..' exp
| exp '<' exp
| exp '<=' exp
| exp '>' exp
| exp '>=' exp
| exp '==' exp
| exp '~=' exp
| exp 'and' exp
| exp 'or' exp
unop: '-' | 'not' | '#'
end