summaryrefslogtreecommitdiffstats
path: root/doc/mylang.ebnf
blob: 04db743376bb8b2290989802ed7cd4d824e867f1 (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
24
25
26
27
28
29
30
31
32
33
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 }.

boolean = join { "||" join }.
join = relation { "&&" relation }.
relation = expression [ ( "==" | "!=" | "<" | "<=" | ">=" | ">" ) expression ].
expression = term [ ( "+" | "-" ) term ].
term = unary [ ( "*" | "/" | "%" ) unary ].
unary = "!" unary | "-" unary | factor.
factor = "(" boolean ")" | ident | integer | "true" | "false" | function_call.

ident_list = ident { "," ident }.
expression_list = boolean { "," boolean }.
function_list = function { function }.
statement_list = statement { statement }.

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

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

program = function_list.