brainfuck/grammar.ebnf

37 lines
1.1 KiB
EBNF
Raw Normal View History

2019-09-01 23:26:06 +02:00
program = statement, {statement}
block = "{",{statement}, "}"
statement = short_statement | while_block | if_block | function_def | function_bf
short_statement = print | return | input | declaration | assignement | expression | inc-dec | import, ";"
2019-09-05 21:00:08 +02:00
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
import = "import", string
2019-09-05 21:00:08 +02:00
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}
2019-09-01 23:26:06 +02:00
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
function_bf = 'bf',name, '{', brainfuck_code, '}'
brainfuck_code = {'<'|'>'|'+'|'-'|'.'|','|'['|']'}
2019-09-01 23:26:06 +02:00
bin_op = "+"|"-"|"*"|"/"|"**"
compar_op = ">"|">="|"<"|"<="|"=="
assignement_symbol = "="|"+="|"-="|"/="|"*="