Skip to content

Krol-X/MySimpleCalc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

My Simple Calculator v.1.0

Written on Lua 5.2 & Python 3.7


Syntax in EBNF:

<digit>  = '0'...'9'
<number> = <digit>, {<digit>}, ['.', <digit>, {digit}]
<fun2>   = ['+' | '-'], {('(', <expr>, ')') | <number>}
<fun1>   = <fun2>, {('*' | '/'), <fun2>}
<expr>   = <fun1>, {('+' | '-'), <fun1>}

Example:

5/(10.5+3)
^ start of current position

<expr> -> <fun1> -> <fun2>
                    '5' != ['+' | '-']
                    '5' != '('
                    <fun2> -> <number>
                              '5' == <digit>
                              '/' != <digit> | '.'
          <fun1> <- <fun2> <- <number>
          '/' == ('*' | '/')
          <fun1> -> <fun2>
                    ... (brackets)
       <----------- (in recursion)