summary refs log blame commit diff
path: root/grammar.ebnf
blob: 890ba2d5682f892ad074f464c2c6ccb9a57b4034 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
                           
 
                                                                                                                         
 
                                                          
 

                                                                     

                                                                                                         

                                                              

                                     
                                                  
 
                                                                             
 

                                                                 


                                                                     
 
                                                                                                      
 
                                                                                                                 

                                                   
Program      ::= Statement+

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

AssignmentStatement ::= "let" IDENTIFIER EQUALS Expression

FunctionCallStatement ::= IDENTIFIER LPAREN FunctionArguments? RPAREN

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

WhileStatement ::= "while" Expression LBRACE Statement* RBRACE

ReturnStatement ::= RETURN Expression

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

Expression   ::= EqualityExpression | AdditiveExpression | FunctionDefinition

EqualityExpression ::= AdditiveExpression "==" AdditiveExpression

AdditiveExpression ::= UnaryExpression (("+" | "-") UnaryExpression)*

UnaryExpression ::= "!" UnaryExpression | PrimaryExpression

PrimaryExpression ::= NUMBER | BOOLEAN | IDENTIFIER | FunctionCallStatement | LPAREN Expression RPAREN

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

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