-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
mewmew.g4
85 lines (61 loc) · 2.21 KB
/
mewmew.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
grammar mewmew;
prog: stmts
;
stmts: command*
;
command: assign
| print
| scan
| ifLoop
| ifElseLoop
| repeat
;
assign: ID '=' expr ';' # assignExpr
| ID '=' expr { notifyErrorListeners("Missing ';' at Assignment statement"); } # assignExprNoSemi
;
print: '::' exprlist ';' # printExprList
| '::$' exprlist ';' # printCharExpr
| '::' expr { notifyErrorListeners("Missing ';' at Meow Say statement"); } # printExprNoSemi
;
scan: ID '<<' ';' # scanExpr
| ID '<:' { notifyErrorListeners("Missing ';' at Meow Scan statement"); } # scanExprNoSemi
;
ifLoop: expr '?' stmts ';' # ifExpr
| expr '?' stmts { notifyErrorListeners("Missing ';' at If statement"); } # ifExprNoSemi
;
ifElseLoop: expr '?' stmts ':' stmts ';' # ifElseExpr
| expr '?' stmts ':' stmts {notifyErrorListeners("Missing ';' at If else statement");} # ifElseExprNoSemi
;
repeat: '@' expr ':' stmts ';' #repeatExpr
| '@' expr ':' stmts { notifyErrorListeners("Missing ';' at Meow Loop statement"); } #repeatExprNoSemi
;
exprlist : expr (',' expr)* # exprListExpr
;
expr: '~' expr # absExpr
| '-' expr # unaryExpr
| SCRATCH '(' expr ')' # scratchExpr
| expr '**' expr # PowExpr
| expr op=('*' | '/') expr # MulDivExpr
| expr op=('+' | '-') expr # AddSubExpr
| expr '%' expr # modExpr
| expr '<' expr # ltExpr
| expr '>' expr # gtExpr
| expr '<=' expr # leExpr
| expr '>=' expr # geExpr
| expr '==' expr # eqExpr
| expr '!=' expr # neExpr
| expr '&' expr # andExpr
| expr '|' expr # orExpr
| '(' expr ')' # parensExpr
| MEWNUMBER # numExpr
| ID # idExpr
;
MUL : '*' ;
DIV : '/' ;
ADD : '+' ;
SUB : '-' ;
SCRATCH : [#]+ ;
COMMENT : '//' .*? '\n' -> skip;
MEWNUMBER : ([m][e][w])+ ('.' ([m][e][w])+)? ;
ID : ([m][w_]*)+;
WS : [ \t\r\n]+ -> skip;