11 var: varName (':' type) ('=' expr)?;
\r
12 varInit: varName (':' type) ('=' expr);
\r
14 type: typeName (typeModifier)*;
\r
15 typeModifier: '*' | ('[' (INT_LIT)? ']');
\r
18 funcDecl: 'func' func;
\r
19 func: funcName genericDecl? '(' parameter ')' (':' type) body;
\r
20 parameter: (var (',' var)*)?;
\r
22 body: '{' stmt* '}';
\r
25 structDecl: 'struct' structName genericDecl? '{' structMember* '}';
\r
26 structMember: structVar | structMethod;
\r
30 genericDecl: '<' typeName (',' typeName)* '>';
\r
41 ifStmt: 'if' expr body elseIfStmt* elseStmt?;
\r
42 elseIfStmt: 'else' 'if' expr body;
\r
43 elseStmt: 'else' body;
\r
45 switchStmt: 'switch' identifierExpr switchBody;
\r
46 switchBody: '{' switchCase* '}';
\r
47 switchCase: 'case' expr body;
\r
49 forStmt: 'for' (varInit | assignStmt) ',' expr ',' expr body;
\r
51 whileStmt: 'while' expr body;
\r
53 assignStmt: identifierExpr '=' expr;
\r
55 returnStmt: 'return' expr;
\r
72 nonAccessExpr: funcExpr
\r
76 funcExpr: funcName '(' (expr (',' expr)*)? ')';
\r
78 opExpr: binaryOp | prefixOp | postfixOp | ternaryOp;
\r
79 binaryOp: nonOpExpr binary_op nonOpExpr (binary_op nonOpExpr)*;
\r
80 prefixOp: prefix_op nonOpExpr;
\r
81 postfixOp: nonOpExpr postfix_op;
\r
82 ternaryOp: nonOpExpr '?' expr ':' expr;
\r
84 identifierExpr: varName;
\r
86 litExpr: INT_LIT | DECIMAL_LIT | STRING_LIT | BOOL_LIT;
\r
88 accessExpr: nonAccessExpr (accessSubExpr)+;
\r
89 accessSubExpr: accessMember | accessBrackets;
\r
90 accessMember: ('.' | '->') identifierExpr;
\r
91 accessBrackets: '[' expr ']';
\r
93 parenExpr: '(' expr ')';
\r
104 '+' | '-' | '!' | '~' | '&' | '*' | postfix_op;
\r
106 '+' | '-' | '*' | '/' | '%' | '&' | '<' | '|' | '^' | '>' |
\r
107 '==' | '!=' | '<=' | '>=' | '<' | '>' |
\r
108 '<<' | '>>' | '||' | '&&' | '&=' | '|=' | '^=' |
\r
109 '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%=';
\r
111 INT_LIT: ('+' | '-')? [0-9]+;
\r
112 DECIMAL_LIT: ('+' | '-')* [0-9]+ '.' [0-9]+;
\r
113 STRING_LIT: '"' [^"]* '"';
\r
114 BOOL_LIT: 'true' | 'false';
\r
116 NAME: ([a-z] | [A-Z] | [0-9])+;
\r
117 WS: [ \t\r\n]+ -> skip;
\r