John
ee5dabb4f3
- [x] Call syntax - [x] Function declaration syntax TODO: - [ ] Any form of type checking - [ ] Static variable resolution - [ ] Closures, etc.
67 lines
2.0 KiB
EBNF
67 lines
2.0 KiB
EBNF
(* Conlang Expression Grammar *)
|
|
Start = Program ;
|
|
Program = Stmt* EOI ;
|
|
|
|
(* literal *)
|
|
Literal = STRING | CHARACTER | FLOAT | INTEGER | Bool ;
|
|
Bool = "true" | "false" ;
|
|
Identifier = IDENTIFIER ;
|
|
|
|
(* # Statements *)
|
|
(* statement *)
|
|
Stmt = Fn | Let | Expr ';' ;
|
|
Let = "let" "mut"? Identifier (':' Type)? ('=' Expr)? ';' ;
|
|
Fn = "fn" Identifier '(' Params? ')' Block ;
|
|
(* TODO: Type system *)
|
|
Params = (Param ',')* Param? ;
|
|
Param = Identifier (*':' Type *) ;
|
|
|
|
(* # Expressions *)
|
|
(* expression *)
|
|
Expr = Assign ;
|
|
Block = '{' Stmt* Expr? '}' ;
|
|
Primary = Identifier | Literal
|
|
| Block | Group | Branch ;
|
|
|
|
(* expression::call *)
|
|
Call = FnCall | Primary ;
|
|
FnCall = Primary ('(' Tuple? ')')? ;
|
|
|
|
(* expression::tuple *)
|
|
Group = '(' Tuple? ')' ;
|
|
Tuple = Expr (',' Expr)* ;
|
|
|
|
(* expression::math *)
|
|
Assign = Identifier (AssignOp Assign) | Compare ;
|
|
Compare = Range (CompareOp Range )* ;
|
|
Range = Logic (RangeOp Logic )* ;
|
|
Logic = Bitwise (LogicOp Bitwise)* ;
|
|
Bitwise = Shift (BitwiseOp Shift )* ;
|
|
Shift = Term (ShiftOp Term )* ;
|
|
Term = Factor (TermOp Factor )* ;
|
|
Factor = Unary (FactorOp Unary )* ;
|
|
Unary = (UnaryOp)* Call ;
|
|
|
|
(* expression::math::operator *)
|
|
AssignOp = '=' | "+=" | "-=" | "*=" | "/=" |
|
|
"&=" | "|=" | "^=" |"<<=" |">>=" ;
|
|
CompareOp = '<' | "<=" | "==" | "!=" | ">=" | '>' ;
|
|
RangeOp = ".." | "..=" ;
|
|
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" Expr ;
|
|
Break = "break" Expr ;
|
|
Return = "return" Expr ;
|
|
Continue = "continue" ;
|