(* Grammar definition in EBNF format. *) Program = {Statement} EOF; (* Statement *) Statement = ExpressionStatement | ReturnStatement | PrintStatement; ExpressionStatement = Expression ";"; ReturnStatement = "return" Expression ";"; (* NOTE: Hard-coded PrintStatement until Rabbithole has an standard library *) PrintStatement = "print" Expression ";"; (* Expression *) Expression = AssignmentExpression; (* Expressions affected by precedence*) (* NOTE: Only allow IDENTIFIERs and their fields as the LValue for now. *) AssignmentExpression = IDENTIFIER {"." IDENTIFIER} ("=" | ":=") AssignmentExpression | TermExpression; TermExpression = FactorExpression { ("+" | "-") FactorExpression }; FactorExpression = UnaryExpression { ("*" | "/") UnaryExpression }; UnaryExpression = ( "-" | "!" ) UnaryExpression | UnitExpression ; (* Unaffected Expressions *) UnitExpression = FLOAT | INT | STR | GroupExpression | BlockExpression | FnExpression | TypeExpression | FormExpression | IfExpression; GroupExpression = "(" Expression ")"; BlockExpression = Block; FnExpression = "fn" FnHeader Block; TypeExpression = "type" TypeBlock; (* NOTE: Will associated functions clash with fields? *) FormExpression = "form" TypeBlock; IfExpression = "if" Expression Block { "elif" Expression Block } [ "else" Block ]; (* Parts *) FnHeader = (FnParameters) ["->" Type]; FnParameters = ("self" | FnParameter) { "," FnParameter}; (* Utils *) Block = "{" { Statement } [Expression] "}"; TypeBlock = "{" [ TypedIdentifier ] { "," TypedIdentifier } "}"; TypedIdentifier = IDENTIFIER [":" Type]; (* NOTE: Type doesn't include anything other than simple named types for now. *) Type = IDENTIFIER;