Possible missing END

Started by Robert, December 18, 2023, 11:22:00 PM

Previous topic - Next topic

Robert

translating the attached file, unzipped, with

bc Exp

errors

BCX BASIC to C/C++ Translator (c) 1999-2023 by Kevin Diggins
Version 8.0.7 (12/09/2023) Compiled using MS Visual C++ for 64-bit Windows Systems
Error!
Exp.Bas
Possible missing (4) END statements in SUB/FUNCTION at line 238 in Module: Exp.Bas
Original line
end function
==============
Current Tokens
==============
  1 endfunction
===============
Original Tokens
===============
  1 endfunction

MrBcx

#1
Hi Robert,

I believe the problem stems from Wayne's error checking that was added after this code
was written. Specifically, Wayne's tests do not adequately account for BASIC "IF" statements
inside conditional "$IF" statements. 

When Wayne's tests detect what it thinks is an error, it aborts the BCX translation
with the error messages that you see.  But if I replace that abort sequence with a simple
PRINT statement, the BCX translation completes and the c/c++ code can be compiled, albeit
with no UI provided in your code.

So, I understand the source of the bug, fixing it will be challenging but I'll give it a go.








MrBcx

I cannot figure out a general purpose internal algorithm that will easily solve this problem.

Two workarounds that should work to overcome this particular example:

* Rewrite so that each IF - END IF is entirely contained within the $IF - $ENDIF block.

or

* Rewrite into separate C and C++ functions 


Robert

Quote from: MrBcx on December 22, 2023, 11:02:59 AM
I cannot figure out a general purpose internal algorithm that will easily solve this problem.

Two workarounds that should work to overcome this particular example:

* Rewrite so that each IF - END IF is entirely contained within the $IF - $ENDIF block.

or

* Rewrite into separate C and C++ functions

Sounds good. Thank you for investigating.


MrBcx

#4
One more easy option ...

I could replace the targeted ABORT sequences with simple PRINT statements that displays the existing:

"Possible missing (#) END statements ... "

which should allow translation to complete except in cases of genuinely flawed code.

Robert

Quote from: MrBcx on December 22, 2023, 05:23:49 PM
One more easy option ...

I could replace the targeted ABORT sequences with simple PRINT statements that displays the existing:

"Possible missing (#) END statements ... "

which should allow translation to complete except in cases of genuinely flawed code.

There may be other instances that coders may experience but in this case Jeff was optimizing the code so that duplication would not be needed in the if ... end if C vs. C++ blocks.

I got the code compiling with some GOTOs and labels and avoided duplicating code. The whole program compiled with pre 6.5.0. translators. Later versions of BCX got tangled up in the makefile with incomprehensible output from the Microsoft compiler.

I suspect that the program itself, in today's systems, is lethal and I should have left it in oblivion.

We used to be able to get away with things back in the day. No so anymore.

Abort is pretty desperate. I like the warning message idea.

MrBcx

Quote from: Robert on December 22, 2023, 06:10:17 PM

Abort is pretty desperate. I like the warning message idea.


I'll initially convert only the "Possible missing ..." aborts into warnings and run my regressions.
Hopefully the regression tests will remain quiet.  I'll soon find out ...

MrBcx

Quote from: MrBcx on December 22, 2023, 06:36:53 PM
Quote from: Robert on December 22, 2023, 06:10:17 PM

Abort is pretty desperate. I like the warning message idea.


I'll initially convert only the "Possible missing ..." aborts into warnings and run my regressions.
Hopefully the regression tests will remain quiet.  I'll soon find out ...

Robert,

The regression tests executed perfectly and your original BUG code gets correctly translated with one warning.

I'm calling this a keeper ...