Author Topic: GOSUB RETURN a bug of parser?  (Read 3348 times)

0 Members and 1 Guest are viewing this topic.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
GOSUB RETURN a bug of parser?
« on: August 22, 2020, 08:54:13 am »
Hi guys and gals

following the code of Dav in another thread I have fallen into this feature / bug of the parser that comes out in runtime.

please copy paste and run this code to get the same experience
Code: QB64: [Select]
  1. COLOR 12, 1
  2. PRINT "I'm before the GOSUB"
  3. COLOR 15, 3
  4. PRINT "I'm in the main after all Gosubs"
  5. PRINT "After me it will be triggered a runtime error for three times"
  6.  
  7. ' END REM it seems that END is a must  if there is a GOSUB before and after
  8. '         the last line of code of the main program
  9.  
  10.  
  11. 1:
  12. PRINT "I'm into the GOSUB 1"
  13.  
  14. 2:
  15. c = "I'm a string"
  16.  
  17. 3:
  18. COLOR 14, 4
  19. PRINT c; " it is a global string"
  20. COLOR 12, 1

So with the goal of distinguish between a starting point of a GOSUB and a call of a GOSUB it must be the use of the END to point out the end of the main program.
waiting feedbacks
Programming isn't difficult, only it's  consuming time and coffee

Offline Unseen Machine

  • Forum Regular
  • Posts: 158
  • Make the game not the engine!
    • View Profile
Re: GOSUB RETURN a bug of parser?
« Reply #1 on: August 22, 2020, 09:22:46 am »
Well, the code runs line after line, as they are GOSUB's and not actual SUB's/FUNCTION's they get run after your main code block. Hence the return command has no idea of where it should return to, so yes you'll need to use END or SYSTEM afterwards or simply add a SkipGosubs line
Code: QB64: [Select]
  1. COLOR 12, 1
  2. PRINT "I'm before the GOSUB"
  3. COLOR 15, 3
  4. PRINT "I'm in the main after all Gosubs"
  5. PRINT "After me it will be triggered a runtime error for three times"
  6.  
  7. ' END REM it seems that END is a must  if there is a GOSUB before and after
  8. '         the last line of code of the main program
  9.  
  10. GOTO SkipGosubs
  11.  
  12. 1:
  13. PRINT "I'm into the GOSUB 1"
  14.  
  15. 2:
  16. c = "I'm a string"
  17.  
  18. 3:
  19. COLOR 14, 4
  20. PRINT c; " it is a global string"
  21. COLOR 12, 1
  22.  
  23. SkipGosubs:
  24.  

Unseen

FellippeHeitor

  • Guest
Re: GOSUB RETURN a bug of parser?
« Reply #2 on: August 22, 2020, 09:57:30 am »
Yeah, not a bug in the parser. A bug in your code ;-)

Use END or SYSTEM.
« Last Edit: August 22, 2020, 10:01:43 am by FellippeHeitor »

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: GOSUB RETURN a bug of parser?
« Reply #3 on: August 23, 2020, 03:10:05 am »
Thanks
So my deprecated lazyness  to type is the real bug of this code! :-)

I thank you also for the alternative to END to solve the issue so your main message to me is control the flow of your program! and you can do this control using canonical ways like END  SYSTEM or alternative ways like the jump of GOSUB blocks.
I have found the deprecated STOP keyword that in an interpreted BASIC was useful for debug but here in QB64 is a duplicated of END.
It is not possible to write a modern code block (SUB/FUNCTION) before the Block of GOSUB!
Programming isn't difficult, only it's  consuming time and coffee