Language Grammar - aabounegm/banana GitHub Wiki

The following grammar represents the syntax of our language:

Program     ::= { Statement }
Statement   ::= VarDecl | VarAssign | IfStatement | WhileLoop | FuncCall

FuncDef     ::= 'def', Identifier, '(', [ Params ], ')', [ ':', Type ], 'do', { Statement }, 'end'
Params      ::= VarDecl | VarDecl, ',', Params 

VarDecl     ::= 'var', Identifier, ':', Type
Type        ::= 'num' | 'array', IntegerLiteral, Type

VarAssign   ::= (Identifier | ArrayAccess), ':=', Expression
ArrayAccess ::= Identifier, '[', Expression, ']'

IfStatement ::= 'if', Expression, 'then', { Statement }, [ 'else', { Statement } ], 'end'
WhileLoop   ::= 'while', Expression, 'loop', { Statement }, 'end'

FuncCall    ::= Identifier, '(', [Args], ')'
Args        ::= Expression | Expression, ',', Args

Expression  ::= Relation, { ('and' | 'or'), Relation }
              | 'not', Relation
Relation    ::= Relational, [ ('=', '/=', '<' | '>', '>=', '<=') , Relational ]
Relational  ::= Term, { ('+' | '-'), Relational }
Term        ::= Factor, { ('*' | '/'), Term }
Factor      ::= '(', Expression, ')' | NumberLiteral | Identifier | ArrayAccess | FuncCall

Identifier  ::= [_a-zA-Z][_a-zA-Z0-9]* 
⚠️ **GitHub.com Fallback** ⚠️