brainfuck/grammar.ebnf

32 lines
951 B
EBNF
Raw Normal View History

2019-09-01 23:26:06 +02:00
program = statement, {statement}
block = "{",{statement}, "}"
2019-09-05 21:00:08 +02:00
statement = short_statement | while_block | if_block | function_def
short_statement = print | return | input | declaration | assignement | expression | inc-dec, ";"
2019-09-01 23:26:06 +02:00
assignement = name, assignement_symbol, expression
2019-09-05 21:00:08 +02:00
declaration = "var" , name , {",",name}
return = "return", expression
expression = compar_op | function_call
function_call = name, '(',[expression,{','expression,}]
2019-09-01 23:26:06 +02:00
compar = calcul, [compar_op, calcul]
calcul = terme, [('+'|'-'), terme]
terme = factor [("*"|"/"), factor]
factor = val ["**", val]
val = name | number | "(", expression, ")"
inc-dec = name, ("++" | "--")
condition = '(', expression, ')'
while_block = "while", condition, block
if_block = "if", condition, block, ["else", block]
2019-09-05 21:00:08 +02:00
function_def = "def", name, '(',[name,{',',name}],')',block
2019-09-01 23:26:06 +02:00
bin_op = "+"|"-"|"*"|"/"|"**"
compar_op = ">"|">="|"<"|"<="|"=="
assignement_symbol = "="|"+="|"-="|"/="|"*="