John
79fda16788
Broke frontend into its own library, "cl-frontend" - Frontend is pretty :D - Included sample fibonacci implementation Deprecated conlang::ast::Visitor in favor of bespoke traits - Rust traits are super cool. - The Interpreter is currently undergoing a major rewrite Added preliminary type-path support to the parser - Currently incomplete: type paths must end in Never..? Pretty printer is now even prettier - conlang::ast now exports all relevant AST nodes, since there are no namespace collisions any more
85 lines
2.4 KiB
EBNF
85 lines
2.4 KiB
EBNF
(* Conlang Expression Grammar *)
|
|
Start = Program ;
|
|
Program = Stmt* EOI ;
|
|
(* TODO:
|
|
- Replace Program with Module
|
|
Module = Decl* EOI ;
|
|
- Move Fn and Let into "Decl":
|
|
Decl = Fn | Let ;
|
|
- allow Decl | ExprStmt in Stmt:
|
|
Stmt = Decl | Expr ';' ;
|
|
*)
|
|
(* literal *)
|
|
Literal = STRING | CHARACTER | FLOAT | INTEGER | Bool ;
|
|
Bool = "true" | "false" ;
|
|
Identifier = IDENTIFIER ;
|
|
|
|
(* # Statements *)
|
|
(* statement *)
|
|
Stmt = Fn | Let | Expr ';' ;
|
|
Let = "let" Name ('=' Expr)? ';' ;
|
|
Fn = "fn" Identifier '(' Params? ')' Block ;
|
|
(* TODO: Type system *)
|
|
Params = (Name ',')* Name? ;
|
|
Name = "mut"? Identifier (':' Type )? ;
|
|
|
|
(* # Type Expressions *)
|
|
(* types *)
|
|
TypeExpr = Never | Empty | TypeTuple | PathExpr ;
|
|
Never = '!' ;
|
|
Empty = '(' ')' ;
|
|
TypeTuple = '(' (TypeExpr ',')* TypeExpr? ')' ;
|
|
|
|
PathExpr = '::'? PathPart ;
|
|
PathPart = "super" | Identifier ;
|
|
|
|
|
|
(* # 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" ;
|