-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLua.g4
71 lines (56 loc) · 1.28 KB
/
Lua.g4
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
grammar Lua;
translation: chunk;
chunk: statement*;
statement:
variableDeclaration
| ifStatement
| whileStatement
| numericForStatement;
variableDeclaration: Identifier Equal expression;
expression:
(FloatConstant | IntegerConstant) # ExpressionConstant
| expression binaryOperator expression # ExpressionBinary;
binaryOperator: Add | Subtract | Multiply | Divide;
ifStatement:
If expression Then chunk (elseifStatement)* (elseStatement)? End;
elseifStatement: ElseIf expression chunk;
elseStatement: Else chunk;
whileStatement: While expression Do chunk End;
numericForStatement:
For Identifier Equal expression Comma expression (
Comma expression
)? Do chunk End;
Equal: '=';
Add: '+';
Subtract: '-';
Multiply: '*';
Divide: '/';
Comma: ',';
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';
Identifier: [a-zA-Z_] [a-zA-Z0-9_]*;
FloatConstant: [0-9]+ '.' [0-9]+;
IntegerConstant: [1-9] [0-9]*;
BlockComment: '--[[' .*? '--]]' -> skip;
LineComment: '--' ~[\r\n]* -> skip;
Whitespace: [ \t]+ -> skip;
Newline: ( '\r' '\n'? | '\n') -> skip;