From cdb8c28e64b81a9ee7eefbad30fed95abc40b137 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 16 Oct 2023 22:33:38 -0500 Subject: [PATCH] grammar.ebnf: Initial prototype grammar --- grammar.ebnf | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 grammar.ebnf diff --git a/grammar.ebnf b/grammar.ebnf new file mode 100644 index 0000000..e521c9b --- /dev/null +++ b/grammar.ebnf @@ -0,0 +1,55 @@ +# Conlang Expression Grammar +Start = Expr + +# literal +Literal = String | Char | Float | Int | Bool +String = STRING +Float = FLOAT +Char = CHARACTER +Bool = "true" | "false" +Int = INTEGER + +Identifier = IDENTIFIER + +# Expressions +Expr = Flow | Ignore +Block = '{' Expr '}' +Group = '(' Expr ')' +Final = 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)* Final + +# expression::math::operator +IgnoreOp = ';' +CompareOp = '<' | "<=" | "==" | "!=" | ">=" | '>' +AssignOp = '=' | "+=" | "-=" | "*=" | "/=" | + "&=" | "|=" | "^=" |"<<=" |">>=" +LogicOp = "&&" | "||" | "^^" + +BitwiseOp = '&' | '|' | '^' +ShiftOp = "<<" | ">>" +TermOp = '+' | '-' +FactorOp = '*' | '/' | '%' +UnaryOp = '*' | '&' | '-' | '!' + +# expression::control +Branch = While | If | For +If = "if" Expr Block (Else)? +While = "while" Expr Block (Else)? +For = "for" Identifier "in" Expr Block (Else)? +Else = "else" Block + +Flow = Break | Return | Continue +Break = "break" Expr +Return = "return" Expr +Continue = "continue"