CPCWiki forum

General Category => Programming => Topic started by: Devilmarkus on 00:56, 10 March 10

Title: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 00:56, 10 March 10
Hi coders!
I want to know the "real wanted result" of a simple ASM function:
DS &3318-&3301+4*14

I used 3 emulators with 3 different results!!!  :o :o :o

WinAPE:
WinAPE Z80 Assembler V1.0.13

000001  0000  00 00 00 00   DS &3318-&3301+4*14
        0004  00 00 00 00
        ....
        0174  00 00 00 00
        0178  00 00

378x "00" !!!

WinCPC:
000001 8000  00 00 00 00                        ds      &3318-&3301+4*14
000001 8004  00 00 00 00
....
000001 8040  00 00 00 00
000001 8044  00 00 00 00
000001 8048  00 00 00 00
000001 804C  00 00 00   


79x "00"!!! (most exact because * should be calculated first but why 79?)

JavaCPC:
000001 0000  DS &3318-&3301+4*14 
                        00 00 00 00
                        00 00 00 00
                        .......
                        00 00 00 00
Assembled in 0.047s from &0000 to &0126 length is &0126

294x "00"

(When I enable exact math parsing I get 73x "00")

So which is the correct value now???

Please help...
Title: Re: Parsing mathematics seems to be problematic.
Post by: Octoate on 01:03, 10 March 10
The correct value is - of course - the mathmatical one. Which means multiplication before addition / substraction.
This means that the result is DS &3318-&3301+&38 = DS &4F.
Title: Re: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 01:08, 10 March 10
Quote from: Octoate on 01:03, 10 March 10
The correct value is - of course - the mathmatical one. Which means multiplication before addition / substraction.
This means that the result is DS &3318-&3301+&38 = DS &4F.
Maxam creates this: (like WinApe)
(http://cpcwiki.eu/forum/index.php?action=dlattach;topic=599.0;attach=381;image)
but why????
Title: Re: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 01:30, 10 March 10
Got it now....
My new parser had too much old code inside :D
Bug was: all & were removed in String before parsing it...  ???

Now I get the same results like WinApe (Or if I use exact maths I get the same result than WinCPC)
Title: Re: Parsing mathematics seems to be problematic.
Post by: Executioner on 01:51, 10 March 10
Quote from: Octoate on 01:03, 10 March 10
The correct value is - of course - the mathmatical one. Which means multiplication before addition / substraction.
This means that the result is DS &3318-&3301+&38 = DS &4F.

That's only correct if you have operator precedence, which Maxam doesn't, and therefore WinAPE doesn't for compatability. All Maxam/WinAPE expressions are evaluated left-to-right regardless of operator.
Title: Re: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 01:53, 10 March 10
Quote from: Executioner on 01:51, 10 March 10
That's only correct if you have operator precedence, which Maxam doesn't, and therefore WinAPE doesn't for compatability. All Maxam/WinAPE expressions are evaluated left-to-right regardless of operator.

I have this optional.
Left-to-right is "default" and also operator predence + other operations, too when precision is true in my parser.
View Source (http://javacpc.svn.sourceforge.net/viewvc/javacpc/JavaCPC/src/jemu/util/ass/Parser.java?revision=58&view=markup)
Title: Re: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 02:09, 10 March 10
Thanks to the improved parser I can compile most files properly now...
Example screenshot:
Assembled original source for "Synergy II" demo
Title: Re: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 15:50, 10 March 10
I build a Scientific calculator in java as applet:

Scientific Calculator Applet (http://cpc-live.com/calc/)

Have fun....
(It uses the math parser I made for JavaCPC)
Title: Re: Parsing mathematics seems to be problematic.
Post by: Gryzor on 09:12, 11 March 10
Hmmm! Can you compile it to run as an exe? I'm having troubles here at work...

Any screenies? If it's CPC-themed it'd be super fun to use it at work!!!

For the time being I'm looking for a Sharp PC14xx programmable calculator (since they broke into my car and stole the last one), anyone might have one they wanna part with?
Title: Re: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 12:22, 11 March 10
You can download the .jar file and double-click it... should work.
Or, if you don't have java installed, you'll get no cookies.

[Screen for Gryzor]
Title: Re: Parsing mathematics seems to be problematic.
Post by: Gryzor on 15:09, 12 March 10
Heh :) It looks cute, but it ain't no CPC!

I did try executing the jar (duh), but it doesn't work - it's as if the Java bin is not in the system paths for some reason... weird.
Title: Re: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 15:31, 12 March 10
Quote from: Gryzor on 15:09, 12 March 10
Heh :) It looks cute, but it ain't no CPC!

I know. But also if it dont look like a CPC , the sun will keep rotating around the earth :D :D :D

Edit: Sorry, I forgot, the earth is like a disc :(
Title: Re: Parsing mathematics seems to be problematic.
Post by: Devilmarkus on 15:40, 12 March 10
I hope you like my sarkasm...
In fact, the calculator was only a tool I coded to test my parser.

Then I thought "Hey this could be useful as single app"
(I'll also add it as JavaCPC Desktop tool)
Powered by SMFPacks Menu Editor Mod