2023-10-19 19:40:03 +00:00
|
|
|
(* Conlang Expression Grammar *)
|
|
|
|
Start = Expr ;
|
|
|
|
|
|
|
|
(* literal *)
|
|
|
|
Literal = STRING | CHARACTER | FLOAT | INTEGER | Bool ;
|
|
|
|
Bool = "true" | "false" ;
|
|
|
|
Identifier = IDENTIFIER ;
|
|
|
|
(* # Expressions *)
|
|
|
|
(* expression *)
|
|
|
|
Expr = Ignore
|
|
|
|
Block = '{' Expr? '}' ;
|
|
|
|
Group = '(' Expr? ')' ;
|
|
|
|
Primary = Item | Identifier | Literal
|
|
|
|
| Block | Group | Branch ;
|
|
|
|
|
|
|
|
(* expression::math *)
|
|
|
|
Ignore = Assign (IgnoreOp Assign )* ;
|
|
|
|
Assign = Compare (AssignOp Compare)* ;
|
|
|
|
Compare = Logic (CompareOp Logic )* ;
|
|
|
|
Logic = Bitwise (LogicOp Bitwise)* ;
|
|
|
|
Bitwise = Shift (BitwiseOp Shift )* ;
|
|
|
|
Shift = Term (ShiftOp Term )* ;
|
|
|
|
Term = Factor (TermOp Factor )* ;
|
|
|
|
Factor = Unary (FactorOp Unary )* ;
|
|
|
|
Unary = (UnaryOp)* Primary ;
|
|
|
|
|
|
|
|
(* expression::math::operator *)
|
|
|
|
IgnoreOp = ';' ;
|
|
|
|
CompareOp = '<' | "<=" | "==" | "!=" | ">=" | '>' ;
|
2023-10-17 03:33:38 +00:00
|
|
|
AssignOp = '=' | "+=" | "-=" | "*=" | "/=" |
|
2023-10-19 19:40:03 +00:00
|
|
|
"&=" | "|=" | "^=" |"<<=" |">>=" ;
|
|
|
|
LogicOp = "&&" | "||" | "^^" ;
|
|
|
|
|
|
|
|
BitwiseOp = '&' | '|' | '^' ;
|
|
|
|
ShiftOp = "<<" | ">>";
|
|
|
|
TermOp = '+' | '-' ;
|
|
|
|
FactorOp = '*' | '/' | '%' ;
|
|
|
|
UnaryOp = '*' | '&' | '-' | '!' ;
|
|
|
|
|
|
|
|
(* expression::control *)
|
|
|
|
Branch = While | If | For | Break | Return | Continue ;
|
|
|
|
If = "if" Expr Block (Else)? ;
|
|
|
|
While = "while" Expr Block (Else)? ;
|
|
|
|
For = "for" Identifier "in" Expr Block (Else)? ;
|
|
|
|
Else = "else" Block ;
|
|
|
|
Break = "break" Expr ;
|
|
|
|
Return = "return" Expr ;
|
|
|
|
Continue = "continue" ;
|