summary refs log tree commit diff
path: root/grammar.ebnf
blob: aaa0e78367dd2d469917f388a7172181b97138d3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Program      ::= Statement+

Statement    ::= (AssignmentStatement | FunctionCallStatement | IfStatement | ReturnStatement) SEMICOLON

AssignmentStatement ::= "let" IDENTIFIER EQUALS Expression

FunctionCallStatement ::= IDENTIFIER LPAREN FunctionArguments? RPAREN

IfStatement ::= "if" Expression LBRACE Statement* RBRACE -- TODO: Should function definitions be allowed?

ReturnStatement ::= RETURN Expression

FunctionArguments ::= Expression ("," Expression)*

Expression   ::= EqualityExpression | AdditiveExpression | FunctionDefinition

EqualityExpression ::= AdditiveExpression "==" AdditiveExpression

AdditiveExpression ::= PrimaryExpression (("+" | "-") AdditiveExpression)?

PrimaryExpression ::= NUMBER | BOOLEAN | IDENTIFIER | FunctionCallStatement

FunctionDefinition ::= LPAREN FunctionParamters? RPAREN ARROW LBRACE Statement* ReturnStatement SEMICOLON RBRACE

FunctionParameters ::= IDENTIFIER ("," IDENTIFIER)*