EgonOlsen71 / basicv2

A Commodore (CBM) BASIC V2 interpreter/compiler written in Java
https://egonolsen71.github.io/basicv2/
The Unlicense
84 stars 15 forks source link

Is PI supported ? #51

Closed viteisele closed 1 year ago

viteisele commented 1 year ago

I normally use text files as input for compiler/interpreter. But I have a problem when I want to use the character for PI (chr$(126) in Commodore Basic) as function (result 3.1415...), e. g. for print or as part of a calculation. When I try the usual solution as "~", ALT-960 or ALT-227, then there is either a syntax error or zero is returned.

EgonOlsen71 commented 1 year ago

You can use Π in text sources.

viteisele commented 1 year ago

With following line: 10 print Π console prints 3.14159265, but the output of compiled code is still 0.

BTW: The console accepts both forms of PI: the Greek Capital Letter Pi (Π, U+03A0, &Pi) and the Greek Small Letter Pi (π, U+03C0, &pi), which looks like the PI in Commodore Basic.

EgonOlsen71 commented 1 year ago

You are right...strange. I guess I've never tested it in this context, because I really dislike the idea of having an extra symbol for PI in the first place hence I never use it but write 3.1415...directly. I'll have a look. Most likely some kind of encoding conversion issue...

EgonOlsen71 commented 1 year ago

Should be fixed now.

viteisele commented 1 year ago

The function PI is now working :-) But there is one little difference between compiler and console when printing character PI (print "π") with text files: with compiled code it is printed as expected, but with console the is something like "|PI|". Could you also fix this ?

EgonOlsen71 commented 1 year ago

I'll have a look. That should actually happen inside strings only...

EgonOlsen71 commented 1 year ago

I can't reproduce this. Can you give me an example, please?

viteisele commented 1 year ago

Here is the testprogram: 0 print chr$(126) 1 print "Π" 2 print "π"

With compiler and emulator there are 3 π printed, as expected. But with console there is the output with bash (I use wsl):

$ ./run_gui.sh com.sixtyfour.extensions.textmode.ConsoleSupport registered as a BASIC extension! com.sixtyfour.extensions.graphics.GraphicsBasic registered as a BASIC extension! 3 commands compiled in: 56ms ~ {pi} {pi}

The output for line 1 and 2 in the gui is the same as for 'print "{pi}"' , line 0 has correct output. Sorry, I don't know how to add a screenshot.

EgonOlsen71 commented 1 year ago

I see. That's actually "by design"...which doesn't mean, that it's a good design. I'll have a look at it...

EgonOlsen71 commented 1 year ago

Should behave better now...

viteisele commented 1 year ago

Yes, now compiler and console have the same correct behavior :-)