### expression grammar
- expression → assignment
- assignment → lvalue assignment_op assignment |
ternary_conditional |
lambda
- ternary_conditional → null_coalescing "?" expression ":" ternary_conditional
| null_coalescing
- null_coalescing → pipeline ( "??" pipeline )*
- pipeline → logical_or ( "|>" logical_or )*
- logical_or → logical_and ( "||" logical_and )*
- logical_and → bitwise_or ( "&&" bitwise_or )*
- bitwise_or → bitwise_xor ( "|" bitwise_xor )*
- bitwise_xor → bitwise_and ( "^" bitwise_and )*
- bitwise_and → equality ( "&" equality )*
- equality → comparison ( ( "!=" | "==" ) comparison )*
- comparison → bitwise_shift ( ( ">" | ">=" | "<" | "<=" ) bitwise_shift )*
- bitwise_shift → range ( ( ">>" | "<<" ) range )*
- range → term ( ".." term )?
- term → factor ( ( "-" | "+" ) factor )*
- factor → unary ( ( "/" | "\*" | "%" ) unary )*
- unary → ( "!" | "-" | "+" | "~" | "++" | "--" ) unary | postfix
- postfix → call ( "++" | "--" )*
- call → primary ( "(" arguments? ")" | "." IDENTIFIER | "?." IDENTIFIER )*
- primary → array | map | atom | new_expr
- atom →
IDENTIFIER |
NUMBER |
STRING |
CHAR |
true |
false |
null |
"(" expression ")"
- array → "[" (expression ("," expression)*)? "]"
- map → "{" (STRING ":" expression ("," STRING ":" expression)*)? "}"
- assignment_op → "=" | "+=" | "-="
| "*=" | "/=" | "%="
| "<<=" | ">>="
| "&=" | "^=" | "|="
- lvalue → postfix
- lambda → "(" parameters? ")" ( ":" type )? "=>" ( block | expr )
- new_expr → "new" qualified_name "(" arguments? ")"
- qualified_name → IDENTIFIER ("." IDENTIFIER)*
### declaration grammar
- declaration → classDecl |
funDecl |
varDecl |
letDecl |
constDecl |
useDecl |
exportDecl |
statement
- classDecl → ("sealed")? "class" IDENTIFIER ( "extends" IDENTIFIER )?
"{" classMember* "}"
- funDecl → "function" function
- varDecl → "var" IDENTIFIER (":" type )? ("=" expression)? ";"
- letDecl → "let" IDENTIFIER (":" type )? ("=" expression)? ";"
- constDecl → "const" IDENTIFIER (":" type )? "=" expression ";"
- useDecl → "use" STRING ";"
- exportDecl → "export" ( classDecl | funDecl | varDecl | constDecl )
### statement grammar
- statement →
exprStmt |
forStmt |
foreachStmt |
whileStmt |
tryStmt |
ifStmt |
switchStmt |
printStmt |
printlnStmt |
returnStmt |
breakStmt |
continueStmt |
throwStmt |
block
- block → "do" declaration* "end"
- exprStmt → expression ";"
- forStmt →
( "for" ( varDecl | exprStmt | ";" ) expression? ";" expression? statement )
| ( "for" varDecl "in" expression statement)
- foreachStmt &rarr "foreach" varDecl "in" expression statement
- whileStmt →
"while" expression statement
- tryStmt →
"try" block "catch" "(" IDENTIFIER ")" block ( "finally" block )?
- ifStmt → "if" expression "then" block
( "elif" expression "then" block )*
( "else" block )?
- switchStmt →
"switch" expression "do"
caseClause*
defaultClause?
"end"
- caseClause →
"case" expression ":" block
- defaultClause →
"default" ":" block
- printStmt → "print" expression ";"
- printlnStmt → "println" expression ";"
- returnStmt → "return" expression? ";"
- breakStmt → "break" ";"
- continueStmt → "continue" ";"
- throwStmt → "throw" expression ";"
### utility
- NUMBER → INT | DOUBLE
- INT → [0-9]+
- DOUBLE → [0-9]+.[0-9]+
- function → IDENTIFIER "(" parameters? ")" ( ":" type )? block
- parameters → IDENTIFIER ( ":" type)? ( "," IDENTIFIER ( ":" type)? )*
- arguments → expression ( "," expression )*
- classMember →
constructor
| ("static")? function
| ("static")? varDecl
| ("static")? constDecl
- constructor →
"init" "(" parameters? ")" block
- type = "int" |
"bool" |
"double" |
"number" |
"string" |
"char" |
"function" |
"any" |
IDENTIFIER = [class name]
### program
``this is the start point of program``
- program → useDecl* declaration* EOF