summaryrefslogtreecommitdiffstats
path: root/doc/mylang.ebnf
blob: f84869f1b68fabfe932adb3abadad23bb221d990 (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
34
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.

function_call = "call" ident "[" [ expression_list ] "]".

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 ).

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

program = function_list.