summary refs log tree commit diff
path: root/grammar.ebnf
blob: 406c2d033a8cbe6ccdbaa3113afb2027fb2e9d3d (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
Program      ::= Statement+

Statement    ::= (AssignmentStatement | PrintStatement | FunctionCallStatement) SEMICOLON

AssignmentStatement ::= "let" IDENTIFIER EQUALS Expression

PrintStatement ::= PRINT LPAREN Expression RPAREN -- TODO: this won't be needed once functions support arguments

FunctionCallStatement ::= IDENTIFIER LPAREN FunctionArguments? RPAREN

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

Expression   ::= AdditiveExpression | FunctionDefinition

AdditiveExpression ::= PrimaryExpression ("+" AdditiveExpression)

PrimaryExpression ::= NUMBER | IDENTIFIER | FunctionCallStatement

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

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

ReturnStatement ::= RETURN Expression SEMICOLON --TODO: I dont like this