dzieje-khorinis / DaedalusCompiler

Daedalus ( Gothic I & II scripting language ) Compiler to DAT
MIT License
66 stars 2 forks source link

Parse correctly assignments and expressions #1

Closed arturkasperek closed 6 years ago

arturkasperek commented 6 years ago

We need parse expression like here:

x = 12 + 9 * ( 2 + otherFunc(1 + 7 * 3, 4 + 5) )

correctly ( we need remember about braces and operators importance ex ( '*' > '+' ) ), for that case we should generate assembler like here:

pushi    3
pushi    7
mul      
pushi    1
add      
pushi    5
pushi    4
add      
call     otherFunc
pushi    2
add      
pushi    9
mul      
pushi    12
add      

I added tests for that task. You should look for tests named CorrectlyPassBasicExpression and CorrectlyPassComplexExpression. After implementing that feature tests should pass without problems

arturkasperek commented 6 years ago

We should use https://en.wikipedia.org/wiki/Reverse_Polish_notation

arturkasperek commented 6 years ago
zrzut ekranu 2018-05-08 o 08 56 43

https://stackoverflow.com/questions/24279027/usage-of-functions-with-rpn-form