Author Topic: Small bug in QB64 expression parser  (Read 4603 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline Ed Davis

  • Newbie
  • Posts: 40
    • View Profile
Small bug in QB64 expression parser
« on: December 10, 2020, 01:27:01 pm »
This works in QBASIC:
Code: QB64: [Select]
  1. print "abc" = "a" + "bc"
  2. -1
  3.  

But in QB64, I get:
Code: QB64: [Select]
  1. QB64 Compiler V1.4
  2.  
  3. Beginning C++ output from QB64 code... first pass finished.
  4. Translating code...
  5. [.........................                         ] 50%
  6. Expected variable/value before '='
  7. Caused by (or after):PRINT "abc",3 = "a",1 + "bc",2
  8. LINE 1:print "abc" = "a" + "bc"
  9.  

Not a big deal for me - I happened on this by chance.  But, I thought I would report it just in case.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Small bug in QB64 expression parser
« Reply #1 on: December 10, 2020, 01:28:47 pm »
@Ed Davis
I don't think is a bug so much as it is just not allowed in QB64. I recommend coding in the IDE so you can see syntax errors immediately. It would stink to have to wait until compile to find out if what you are writing is "syntax friendly" or not. If you are trying to compare two strings like that then do this and I believe you will get your desired results:

Code: QB64: [Select]
  1. PRINT ("abc") = ("a" + "bc")
I get -1 just like your QBASIC code.
« Last Edit: December 10, 2020, 01:43:51 pm by SpriggsySpriggs »
Shuwatch!

Offline Ed Davis

  • Newbie
  • Posts: 40
    • View Profile
Re: Small bug in QB64 expression parser
« Reply #2 on: December 10, 2020, 02:05:52 pm »
As I noted in my post, not a big deal for me.  This is not code that I would ever write.

A user of a product that I created a long time ago (and still support), reported this bug in the products macro language.  I started testing it on various other compiler/interpreters, to see if it was handled.

Again, no big deal for me.  It is a difference from QBASIC, so I reported it.  And if the expression parser is anything like the one in my product, it might be a chore to fix it, and maybe not worth the time.

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Small bug in QB64 expression parser
« Reply #3 on: December 10, 2020, 02:06:57 pm »
Well again it isn't really a bug. Some syntax from QBASIC just isn't allowed in QB64 but that (the code I showed) would get you the same results, at least.
Shuwatch!

Marked as best answer by Ed Davis on December 10, 2020, 10:26:24 am

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Small bug in QB64 expression parser
« Reply #4 on: December 10, 2020, 02:28:32 pm »
PRINT is its own beast — basically a sublanguage inside the language.  I doubt any glitch in PRINT will ever be fixed, just from the complexity of the statement itself and how it translates to c. 

I’m not at the PC right now, but does the error appear elsewhere, like in an IF statement?

IF “abc” = “a” + “bc” THEN PRINT “TRUE” ELSE PRINT “FALSE”

If it works in IF, you’ve narrowed the glitch down to PRINT itself, and not the expression parser, and as I said above, I wouldn’t hold my breath expecting to see PRINT overhauled anytime soon.

If it glitches in IF as well, then I’ll dig into it later and see what I can come up with, once I get some free time again after the holidays.  ;)
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline Ed Davis

  • Newbie
  • Posts: 40
    • View Profile
Re: Small bug in QB64 expression parser
« Reply #5 on: December 10, 2020, 02:37:29 pm »
I’m not at the PC right now, but does the error appear elsewhere, like in an IF statement?

IF “abc” = “a” + “bc” THEN PRINT “TRUE” ELSE PRINT “FALSE”

If it works in IF, you’ve narrowed the glitch down to PRINT itself, and not the expression parser, and as I said above, I wouldn’t hold my breath expecting to see PRINT overhauled anytime soon.

Yep, your if example works fine.  So the problem is relegated to print.  Again, not an issue for me, and not something anyone would ever hit.  I'm even sorry I brought it up. :)

Offline doppler

  • Forum Regular
  • Posts: 241
    • View Profile
Re: Small bug in QB64 expression parser
« Reply #6 on: December 11, 2020, 08:33:57 am »
Print is the bread & butter of basic.  Unless you just want to manage a bit of code, data or records.  Visual output "Print" is used.  No wonder it's a beast under the hood.  It has to take all kinds of data and make it presentable.  I have seen other languages (specialized use, military etc)  break output in categories to speed up code.  A print like command for numeric, alphabetical, string and memory, all separate codes.  What fun to find out you used the wrong print variant in relation to the data.  ie: Numeric print used on string data.  I have not used that convoluted code myself, but my friends have.  This was back in the day of "Assembly needed" and very little expensive memory available.  Everything was in code modules, pull the modules needed and use the I/O interfaces.  Made for interesting programs.  You would be amazed what could happen in less than 32K total memory.  Even more amazed when you realize it started with only 4K before expanding to 32k.


Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Small bug in QB64 expression parser
« Reply #7 on: December 11, 2020, 11:13:36 am »
 
Code: QB64: [Select]
  1. 'Example 10. Dez. 2020
  2.  
  3. '1. OK
  4. PRINT abc = a + bc
  5.  
  6. '2. OK
  7. IF "abc" = "a" + "bc" THEN PRINT "TRUE" ELSE PRINT "FALSE"
  8.  
  9. '3. Ergibt: Falsch -> 0
  10. IF abc = a + bc THEN PRINT TRUE ELSE PRINT FALSE
  11.  

Compiler and output 1 + 2

  [ You are not allowed to view this attachment ]  
 
Compiler and output 1, 2, + 3

  [ You are not allowed to view this attachment ]  
« Last Edit: December 11, 2020, 11:24:03 am by Kernelpanic »
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Small bug in QB64 expression parser
« Reply #8 on: December 11, 2020, 11:22:19 am »
Why aren't you doing string comparisons for the other two tests, @Kernelpanic ?
Shuwatch!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Small bug in QB64 expression parser
« Reply #9 on: December 11, 2020, 11:26:16 am »
Which tests?
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Small bug in QB64 expression parser
« Reply #10 on: December 11, 2020, 11:28:24 am »
The ones you just posted, @Kernelpanic

Shouldn't they be:

Code: QB64: [Select]
  1. PRINT "abc" = "a" + "bc"
  2.  
  3. IF "abc" = "a" + "bc" THEN PRINT "TRUE" ELSE PRINT "FALSE"
  4.  
  5. TRUE = 1
  6. FALSE = 0
  7. IF "abc" = "a" + "bc" THEN PRINT TRUE ELSE PRINT FALSE

If you don't define TRUE and FALSE then it will be a result of 0 no matter what.
« Last Edit: December 11, 2020, 11:32:07 am by SpriggsySpriggs »
Shuwatch!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Small bug in QB64 expression parser
« Reply #11 on: December 11, 2020, 11:36:54 am »
Sorry, I don't know what you just mean.

Ok, now I see your example. I have to look again.
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Small bug in QB64 expression parser
« Reply #12 on: December 11, 2020, 11:53:24 am »
So without "" the result is always 0.

Code: QB64: [Select]
  1. 'Forumsbeispiel 10. Dez. 2020
  2.  
  3. 'OK
  4. PRINT abc = a + bc
  5.  
  6. 'OK
  7. IF "abc" = "a" + "bc" THEN PRINT "TRUE" ELSE PRINT "FALSE"
  8.  
  9. 'Ergibt: Falsch -> 0
  10. IF abc = a + bc THEN PRINT TRUE ELSE PRINT FALSE
  11.  
  12. TRUE = -1
  13. FALSE = 0
  14. IF abc = a + bc THEN PRINT TRUE ELSE PRINT FALSE
  15.  
  16.  

Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Small bug in QB64 expression parser
« Reply #13 on: December 11, 2020, 11:59:10 am »
@Kernelpanic

You are comparing 0 to 0 on line 10

Code: QB64: [Select]
  1. IF abc = a + bc THEN PRINT TRUE ELSE PRINT FALSE
abc is undefined so it is equal to zero
a is undefined so it is equal to zero
bc is undefined so it is equal to zero
TRUE is undefined so it is equal to zero
FALSE is undefined so it is equal to zero

The code is literally:
Code: QB64: [Select]
  1. IF 0 = 0 + 0 THEN PRINT 0 ELSE PRINT 0
« Last Edit: December 11, 2020, 12:01:00 pm by SpriggsySpriggs »
Shuwatch!

Offline Kernelpanic

  • Newbie
  • Posts: 94
    • View Profile
Re: Small bug in QB64 expression parser
« Reply #14 on: December 11, 2020, 05:15:49 pm »
I think you mean this:
"IF abc = a + bc THEN PRINT TRUE ELSE PRINT FALSE"

Yes, but I don't understand what the meaning of the "" is here. Why this effect?
With " " it is correct, without no. Why?
« Last Edit: December 11, 2020, 05:18:32 pm by Kernelpanic »
Mark Twain
"Als wir das Ziel endgültig aus den Augen verloren hatten, verdoppelten wir unsere Anstrengungen."
„Having lost sight of our goals, we redoubled our efforts.“