grammar.ebnf: Initial prototype grammar

This commit is contained in:
John 2023-10-16 22:33:38 -05:00
parent e4c827e429
commit cdb8c28e64

55
grammar.ebnf Normal file
View File

@ -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"