summaryrefslogblamecommitdiffstats
path: root/doc/mylang.ebnf
blob: 0ab786d889475947230a2ac0a269609ef4b14420 (plain) (tree)
1
2
3
4
5
6
7
8
9
10


                                                                                                                                                                            
 





                                                                  




                                                                                                                                        
                                                                

                                                           
 

                                                

                                             
 
                                                                                 
                                                                                                     
 

                                                                                                   
                                  
                                        
                                                  

                        
lowercaseLetter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z".
uppercaseLetter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z".
letter = lowercaseLetter | uppercaseLetter.

digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9".
nl = "\n".

ident = letter { letter | digit }.
integer = digit { digit }.

bool = bool "||" join | join.
join = join "&&" equality | equality.
equality = equality "==" relation | equality "!=" relation | relation.
relation = expression "<" expression | expression "<=" expression | expression ">=" expression | expression ">" expression | expression.
expression = expression "+" term | expression "-" term | term.
term = term "*" unary | term "/" unary | term "%" unary | unary.
unary = "!" unary | "-" unary | factor.
factor = "(" bool ")" | ident | integer | "true" | "false".

ident_list = ident { "," ident }.
expression_list = expression { "," expression }.
function_list = function { [ nl ] function }.
statement_list = statement { nl statement }.

function = "fun" ident "[" [ ident_list ] "]" [ nl ] statement_list [ nl ] "end".
statement = [ if_statement | while_statement | assign_statement | function_call | return_statement ].

if_statement = "if" expression [ nl ] statement_list [ nl ] [ "else" statement_list [ nl ] ] "end".
while_statement = "while" expression [ nl ] statement_list [ nl ] "end".
return_statement = "@" expression.
assign_statement = ident "=" expression.
function_call = ident "[" [ expression_list ] "]".

program = function_list.