-
Notifications
You must be signed in to change notification settings - Fork 86
/
lua.txt
199 lines (163 loc) · 4.19 KB
/
lua.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
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
Lua 5.3 grammar for Bison 3.2 with reduce/reduce conflict eliminated by expanding prefixexp - Dr. Robert A. van Engelen
%token
AND "and"
BREAK "break"
DO "do"
ELSE "else"
ELSEIF "elseif"
END "end"
FALSE "false"
FOR "for"
FUNCTION "function"
IF "if"
IN "in"
LOCAL "local"
NIL "nil"
NOT "not"
OR "or"
REPEAT "repeat"
RETURN "return"
THEN "then"
TRUE "true"
UNTIL "until"
WHILE "while"
EQU "=="
NEQ "~="
LTE "<="
GTE ">="
CAT ".."
SHL "<<"
SHR ">>"
DIV "//"
DOTS "..."
;
%token '#' '%' '&' '(' ')' '*' '+' ',' '-' '.' '/' ':' ';' '<' '=' '>' '[' ']' '^' '{' '|' '}' '~'
%left OR
%left AND
%left EQU NEQ LTE '<' GTE '>'
%right CAT
%left '|'
%left '~'
%left '&'
%left SHL SHR
%left '+' '-'
%left '*' '/' '%' DIV
%right NOT '#'
%right '^'
// we expect four shift-reduce conflicts due to Lua's optional semicolon, must always shift on '('
%expect 4
%%
chunk : block
semi : ';'
|
block : scope statlist
| scope statlist laststat semi
ublock : block UNTIL exp
scope :
| scope statlist binding semi
statlist :
| statlist stat semi
stat : DO block END
| WHILE exp DO block END
| repetition DO block END
| REPEAT ublock
| IF conds END
| FUNCTION funcname funcbody
| setlist '=' explist1
| funccall
repetition : FOR NAME '=' explist23
| FOR namelist IN explist1
conds : condlist
| condlist ELSE block
condlist : cond
| condlist ELSEIF cond
cond : exp THEN block
laststat : BREAK
| RETURN
| RETURN explist1
binding : LOCAL namelist
| LOCAL namelist '=' explist1
| LOCAL FUNCTION NAME funcbody
funcname : dottedname
| dottedname ':' NAME
dottedname : NAME
| dottedname '.' NAME
namelist : NAME
| namelist ',' NAME
explist1 : exp
| explist1 ',' exp
explist23 : exp ',' exp
| exp ',' exp ',' exp
exp : NIL
| TRUE
| FALSE
| NUMBER
| STRING
| DOTS
| function
| var
| funccall
| tableconstr
| NOT exp
| '#' exp
| '-' exp %prec NOT
| '~' exp %prec NOT
| exp OR exp
| exp AND exp
| exp '<' exp
| exp LTE exp
| exp '>' exp
| exp GTE exp
| exp EQU exp
| exp NEQ exp
| exp '|' exp
| exp '~' exp
| exp '&' exp
| exp SHL exp
| exp SHR exp
| exp CAT exp
| exp '+' exp
| exp '-' exp
| exp '*' exp
| exp '/' exp
| exp DIV exp
| exp '%' exp
| exp '^' exp
| '(' exp ')'
setlist : var
| setlist ',' var
var : NAME
| var '[' exp ']'
| var '.' NAME
| funccall '[' exp ']'
| funccall '.' NAME
| '(' exp ')' '[' exp ']'
| '(' exp ')' '.' NAME
funccall : var args
| var ':' NAME args
| funccall args
| funccall ':' NAME args
| '(' exp ')' args
| '(' exp ')' ':' NAME args
args : '(' ')'
| '(' explist1 ')'
| tableconstr
| STRING
function : FUNCTION funcbody
funcbody : params block END
params : '(' parlist ')'
parlist :
| namelist
| DOTS
| namelist ',' DOTS
tableconstr : '{' '}'
| '{' fieldlist '}'
| '{' fieldlist ',' '}'
| '{' fieldlist ';' '}'
fieldlist : field
| fieldlist ',' field
| fieldlist ';' field
field : exp
| NAME '=' exp
| '[' exp ']' '=' exp
%%