11 namespaceDecl: 'namespace' typeName '{' decl* '}';
\r
14 var: varName (':' type) ('=' expr)?;
\r
15 varInit: varName (':' type) ('=' expr);
\r
17 type: typeName (typeModifier)*;
\r
18 typeModifier: '*' | ('[' (INT_LIT)? ']');
\r
21 funcDecl: 'func' func;
\r
22 func: funcName genericDecl? '(' parameter ')' (':' type) body;
\r
23 parameter: (var (',' var)*)?;
\r
25 body: '{' stmt* '}';
\r
28 structDecl: 'struct' structName genericDecl? '{' structMember* '}';
\r
29 structMember: privateDecl? structVar | structMethod;
\r
32 privateDecl: 'private';
\r
34 genericDecl: '<' typeName (',' typeName)* '>';
\r
45 ifStmt: 'if' expr body elseIfStmt* elseStmt?;
\r
46 elseIfStmt: 'else' 'if' expr body;
\r
47 elseStmt: 'else' body;
\r
49 switchStmt: 'switch' identifierExpr switchBody;
\r
50 switchBody: '{' switchCase* '}';
\r
51 switchCase: 'case' expr body;
\r
53 forStmt: 'for' (varInit | assignStmt) ',' expr ',' expr body;
\r
55 whileStmt: 'while' expr body;
\r
57 assignStmt: identifierExpr '=' expr;
\r
59 returnStmt: 'return' expr;
\r
76 nonAccessExpr: funcExpr
\r
80 funcExpr: funcName '(' (expr (',' expr)*)? ')';
\r
82 opExpr: binaryOp | prefixOp | postfixOp | ternaryOp;
\r
83 binaryOp: nonOpExpr binary_op nonOpExpr (binary_op nonOpExpr)*;
\r
84 prefixOp: prefix_op nonOpExpr;
\r
85 postfixOp: nonOpExpr postfix_op;
\r
86 ternaryOp: nonOpExpr '?' expr ':' expr;
\r
88 identifierExpr: varName;
\r
90 litExpr: INT_LIT | DECIMAL_LIT | STRING_LIT | BOOL_LIT;
\r
92 accessExpr: nonAccessExpr (accessSubExpr)+;
\r
93 accessSubExpr: accessMember | accessBrackets;
\r
94 accessMember: ('.' | '->') identifierExpr;
\r
95 accessBrackets: '[' expr ']';
\r
97 parenExpr: '(' expr ')';
\r
108 '+' | '-' | '!' | '~' | '&' | '*' | postfix_op;
\r
110 '+' | '-' | '*' | '/' | '%' | '&' | '<' | '|' | '^' | '>' |
\r
111 '==' | '!=' | '<=' | '>=' | '<' | '>' |
\r
112 '<<' | '>>' | '||' | '&&' | '&=' | '|=' | '^=' |
\r
113 '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%=';
\r
115 INT_LIT: ('+' | '-')? [0-9]+;
\r
116 DECIMAL_LIT: ('+' | '-')* [0-9]+ '.' [0-9]+;
\r
117 STRING_LIT: '"' [^"]* '"';
\r
118 BOOL_LIT: 'true' | 'false';
\r
120 NAME: ([a-z] | [A-Z] | [0-9])+;
\r
121 WS: [ \t\r\n]+ -> skip;
\r