Author Topic: Parsing mathematics seems to be problematic.  (Read 3519 times)

0 Members and 1 Guest are viewing this topic.

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Parsing mathematics seems to be problematic.
« on: 01:56, 10 March 10 »
Hi coders!
I want to know the "real wanted result" of a simple ASM function:
Code: [Select]
DS &3318-&3301+4*14
I used 3 emulators with 3 different results!!!  :o :o :o

WinAPE:
Code: [Select]
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:
Code: [Select]
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:
Code: [Select]
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...
« Last Edit: 02:00, 10 March 10 by Devilmarkus »
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Octoate

  • CPC6128
  • ****
  • Posts: 290
  • Country: de
    • Octoate.de
  • Liked: 62
  • Likes Given: 327
Re: Parsing mathematics seems to be problematic.
« Reply #1 on: 02: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.
--

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Re: Parsing mathematics seems to be problematic.
« Reply #2 on: 02:08, 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)

but why????
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Re: Parsing mathematics seems to be problematic.
« Reply #3 on: 02: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)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Executioner

  • Supporter
  • 6128 Plus
  • *
  • Posts: 785
  • Country: au
  • WinAPE Developer
    • WinAPE
  • Liked: 394
  • Likes Given: 60
Re: Parsing mathematics seems to be problematic.
« Reply #4 on: 02:51, 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.

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Re: Parsing mathematics seems to be problematic.
« Reply #5 on: 02:53, 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
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Re: Parsing mathematics seems to be problematic.
« Reply #6 on: 03: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
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Re: Parsing mathematics seems to be problematic.
« Reply #7 on: 16:50, 10 March 10 »
I build a Scientific calculator in java as applet:

Scientific Calculator Applet

Have fun....
(It uses the math parser I made for JavaCPC)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 17.012
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 4087
  • Likes Given: 7386
Re: Parsing mathematics seems to be problematic.
« Reply #8 on: 10: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?

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Re: Parsing mathematics seems to be problematic.
« Reply #9 on: 13: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]
« Last Edit: 13:32, 11 March 10 by Devilmarkus »
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 17.012
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 4087
  • Likes Given: 7386
Re: Parsing mathematics seems to be problematic.
« Reply #10 on: 16: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.

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Re: Parsing mathematics seems to be problematic.
« Reply #11 on: 16:31, 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 :(
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release

Offline Devilmarkus

  • Vivid source of indefiniteness
  • 6128 Plus
  • ******
  • Posts: 4.035
  • Country: de
  • WebCPC / JavaCPC developer
    • index.php?action=treasury
    • CPC-Live website
  • Liked: 1018
  • Likes Given: 926
Re: Parsing mathematics seems to be problematic.
« Reply #12 on: 16: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)
When you put your ear on a hot stove, you can smell how stupid you are ...

Amstrad CPC games in your webbrowser

JavaCPC Desktop Full Release