maxtype-language
v1.4.1
Published
```ebnf maxtypeProgram = { function_declaration | statement | function_call | variable_declaration } ;
Downloads
6
Readme
EBNF Grammar
maxtypeProgram = { function_declaration | statement | function_call | variable_declaration } ;
function_declaration = 'fun' ID '(' parameter_list '):' block ;
variable_declaration = 'type' ID ':' type [ '=' expression ] ';' ;
parameter_list = parameter { ',' parameter } ;
parameter = ID ':' type ;
type = 'number' | 'boolean' | 'string' ;
block = '{' statement* '}' ;
statement = assignment
| function_call
| if_statement
| while_statement
| return_statement ;
assignment = ID '=' expression ';' ;
function_call = ID '(' argument_list ')' ';' ;
argument_list = expression { ',' expression } ;
if_statement = 'if' '[' expression ']' ':' block
{ 'elif' '[' expression ']' ':' block }
[ 'else' ':' block ] ;
while_statement = 'while' '[' expression ']' ':' block ;
return_statement = 'return' expression ';' ;
expression = logical_or ;
logical_or = logical_and { 'or' logical_and } ;
logical_and = equality { 'and' equality } ;
equality = relational [ ( '==' | '!=' ) relational ] ;
relational = additive [ ( '<' | '>' | '<=' | '>=' ) additive ] ;
additive = multiplicative { ( '+' | '-' ) multiplicative } ;
multiplicative = unary { ( '*' | '/' | '%' ) unary } ;
unary = [ '-' | 'not' ] primary ;
primary = '(' expression ')'
| ID
| NUMBER
| STRING
| BOOLEAN ;
ID = [a-zA-Z_][a-zA-Z0-9_]* ;
NUMBER = [0-9]+ ;
STRING = '"' .*? '"' ;
BOOLEAN = 'true' | 'false' ;
WS = [ \t\r\n]+ ;