11 var: varName (':' type) ('=' expr)?;
\r
12 varInit: varName (':' type) ('=' expr);
\r
14 type: typeName (typeModifier)*;
\r
15 typeModifier: '*' | '[' NUMBER? ']';
\r
18 funcDecl: 'func' func;
\r
19 func: funcName '(' parameter ')' (':' type) body;
\r
20 parameter: (var (',' var)*)?;
\r
22 body: '{' stmt* '}';
\r
25 structDecl: 'struct' structName '{' structMember* '}';
\r
26 structMember: structVar | structMethod;
\r
40 ifStmt: 'if' expr body elseIfStmt* elseStmt?;
\r
41 elseIfStmt: 'else' 'if' expr body;
\r
42 elseStmt: 'else' body;
\r
44 switchStmt: 'switch' identifierExpr switchBody;
\r
45 switchBody: '{' switchCase* '}';
\r
46 switchCase: 'case' expr body;
\r
48 forStmt: 'for' (varInit | assignStmt) ',' expr ',' expr body;
\r
50 whileStmt: 'while' expr body;
\r
52 assignStmt: identifierExpr '=' expr;
\r
54 returnStmt: 'return' expr;
\r
71 nonAccessExpr: funcExpr
\r
75 funcExpr: funcName '(' (expr (',' expr)*)? ')';
\r
77 opExpr: binaryOp | prefixOp | postfixOp | ternaryOp;
\r
78 binaryOp: nonOpExpr binary_op nonOpExpr (binary_op nonOpExpr)*;
\r
79 prefixOp: prefix_op nonOpExpr;
\r
80 postfixOp: nonOpExpr postfix_op;
\r
81 ternaryOp: nonOpExpr '?' expr ':' expr;
\r
83 identifierExpr: varName;
\r
85 litExpr: INT_LIT | DECIMAL_LIT | STRING_LIT | BOOL_LIT;
\r
87 accessExpr: nonAccessExpr (accessSubExpr)+;
\r
88 accessSubExpr: accessMember | accessBrackets;
\r
89 accessMember: ('.' | '->') identifierExpr;
\r
90 accessBrackets: '[' expr ']';
\r
92 parenExpr: '(' expr ')';
\r
103 '+' | '-' | '!' | '~' | '&' | '*' | postfix_op;
\r
105 '+' | '-' | '*' | '/' | '%' | '&' | '<' | '|' | '^' | '>' |
\r
106 '==' | '!=' | '<=' | '>=' | '<' | '>' |
\r
107 '<<' | '>>' | '||' | '&&' | '&=' | '|=' | '^=' |
\r
108 '<<=' | '>>=' | '+=' | '-=' | '*=' | '/=' | '%=';
\r
110 INT_LIT: ('+' | '-')? [0-9]+;
\r
111 DECIMAL_LIT: ('+' | '-')* [0-9]+ '.' [0-9]+;
\r
112 STRING_LIT: '"' [^"]* '"';
\r
113 BOOL_LIT: 'true' | 'false';
\r
115 NAME: ([a-z] | [A-Z] | [0-9])+;
\r
116 WS: [ \t\r\n]+ -> skip;
\r