-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammer
78 lines (60 loc) · 2.13 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
Model:
classes*=Class;
Class:
'class' name=ID ('extends' e=ID)? '{' things *= Thing '}';
Thing:
Field | Method;
Field:
static?="static" type=TYPE name=ID ';';
Method:
static?="static" returnType=TYPE name=ID ('<' template += ID[','] '>')? '(' (arguments+=Argument[','])? ')' cb=CodeBlock;
Argument:
type=ID name=ID;
Instruction:
(Error | MCCommand | Return | Assignment | Expression) ';'; // So I want assignment | expression
Error:
'throw' msg=/[^;]*/;
MCCommand:
'#' command = /[^;]*/;
As:
'as' '(' selector = /[^;)]*/ ')' cb=CodeBlock;
Command:
Instruction | FlowControl;
Return:
'return' (rval=Expression)?;
CodeBlock:
instructions+=Command | '{' instructions*=Command '}';
FlowControl:
As | If | While | For;
While:
'while' '(' exp=Expression ')' code=CodeBlock;
If:
'if' '(' exp=Expression ')' code=CodeBlock;
For:
'for' '(' type=TYPE name=ID ':' arr=Expression ')' code=CodeBlock;
Assignment:
(name=INDEX '=' value=Expression) | (name=PROP '=' value=Expression) | (type=TYPE name=ID '=' value=Expression);
Expression: expr=Compare;
SumOp: '+'|'-';
ProdOp: '*'|'/'|'%';
CompOp: '==' | '!=' | '<' | '>' | '<=' | '>=';
BoolOp: '&&' | '||';
Compare: comp += Sum (op += CompOp comp += Sum)*;
Sum: prod+=Product (op+=SumOp prod+=Product)*;
Product: bools+=Bool (op+=ProdOp bools+=Bool)*;
Bool: vals+=Value (op+=BoolOp vals += Value)*;
Value: CAST | TEMPLATE | SCOREBOARD | ACONSTRUCTOR | INDEX | CONSTRUCTOR | NUMBER | FUNCTION_CALL | PROP | SVAL | PARENTETHIS | NOT;
SCOREBOARD: name=ID ':' objective=ID;
NUMBER: nval=/-?[0-9]+/;
TYPE: ID '[]'?;
TVal: /[^<,>]+/;
TEMPLATE: func_name=PROP '<' tvals += TVal[','] '>' '('(func_call+=Expression[','])?')';
FUNCTION_CALL: func_name=PROP '('(func_call+=Expression[','])?')'; // ((caller+=ID) '.')*
NOT: '!' negate = Expression;
CAST: '(' ctype = ID ')' tocast = Expression;
CONSTRUCTOR: 'new' class_name=ID '('(args+=Expression[','])?')';
ACONSTRUCTOR: 'new' class_name=ID '['length=Expression']';
INDEX: arr=PROP '[' i=Expression ']';
PROP: ( expr=PARENTETHIS '.' props+=ID['.']) | ( expr=ID '.' props+=ID['.']) | (var = ID);
SVAL: STRING;
PARENTETHIS: ('('expr= Expression ')');