2023-10-19 19:40:03 +00:00
|
|
|
(* Conlang Expression Grammar *)
|
2023-10-26 19:33:56 +00:00
|
|
|
Start = Program ;
|
|
|
|
Program = Stmt* EOI ;
|
2023-10-19 19:40:03 +00:00
|
|
|
|
|
|
|
(* literal *)
|
|
|
|
Literal = STRING | CHARACTER | FLOAT | INTEGER | Bool ;
|
|
|
|
Bool = "true" | "false" ;
|
|
|
|
Identifier = IDENTIFIER ;
|
2023-10-20 20:33:02 +00:00
|
|
|
|
2023-10-26 19:33:56 +00:00
|
|
|
(* # Statements *)
|
|
|
|
(* statement *)
|
|
|
|
Stmt = Fn | Let | Expr ';' ;
|
|
|
|
Let = "let" "mut"? Identifier (':' Type)? ('=' Expr)? ';' ;
|
|
|
|
Fn = "fn" Identifier Block ; (* TODO: params, return value*)
|
|
|
|
|
2023-10-19 19:40:03 +00:00
|
|
|
(* # Expressions *)
|
|
|
|
(* expression *)
|
2023-10-26 19:36:55 +00:00
|
|
|
Expr = Assign ;
|
2023-10-26 19:33:56 +00:00
|
|
|
Block = '{' Expr '}' ;
|
2023-10-19 19:40:03 +00:00
|
|
|
Group = '(' Expr? ')' ;
|
|
|
|
Primary = Item | Identifier | Literal
|
|
|
|
| Block | Group | Branch ;
|
|
|
|
|
|
|
|
(* expression::math *)
|
|
|
|
Assign = Compare (AssignOp Compare)* ;
|
2023-10-22 23:30:00 +00:00
|
|
|
Compare = Range (CompareOp Range )* ;
|
|
|
|
Range = Logic (RangeOp Logic )* ;
|
2023-10-19 19:40:03 +00:00
|
|
|
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 *)
|
2023-10-17 03:33:38 +00:00
|
|
|
AssignOp = '=' | "+=" | "-=" | "*=" | "/=" |
|
2023-10-19 19:40:03 +00:00
|
|
|
"&=" | "|=" | "^=" |"<<=" |">>=" ;
|
2023-10-20 20:33:02 +00:00
|
|
|
CompareOp = '<' | "<=" | "==" | "!=" | ">=" | '>' ;
|
2023-10-20 22:09:14 +00:00
|
|
|
RangeOp = ".." | "..=" ;
|
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" ;
|