Author Topic: My BCXPP.DLL issues  (Read 277 times)

jcfuller

  • Full Member
  • ***
  • Posts: 167
    • View Profile
My BCXPP.DLL issues
« on: July 17, 2020, 01:45:54 PM »
This is my bcxpp.bas
Code: [Select]

'cl /LD bcxpp.cpp

$CPP

$DLL STDCALL
$ONEXIT "BUILDBCXPP.BAT"
$HEADER
#include <regex>
#include <vector>
#include <iostream>
#include <string>
using namespace std;
$HEADER



''==============================================================================
''Case insensitive comparison - MatchStr$ to Arg$
'' mt = 0, 1 or 2 Match left, whole word, right
''----------------------------------------------
CONST iMatchLft(A,B) = iMatch(A,B,0)
CONST iMatchWrd(A,B) = iMatch(A,B,1)
CONST iMatchRgt(A,B) = iMatch(A,B,2)

FUNCTION iMatch(Arg$, MatchStr$, mt)

  IF mt = 2 THEN
    DIM RAW L1, L2
    L1 = LEN(Arg$) : L2 = LEN(MatchStr$)
    IF L1 < L2 THEN FUNCTION = FALSE
    Arg = (Arg + L1) - L2
  END IF

  WHILE *MatchStr
    'If we run out string to match against then return no match
    IF *Arg = 0 THEN FUNCTION = FALSE
    'bit ORing a character with 0x20 produces the lower case of it
    IF (*Arg BOR 32) <> (*MatchStr BOR 32) THEN FUNCTION = FALSE
    INCR Arg
    INCR MatchStr
  WEND
  IF mt AND *Arg <> 0 THEN FUNCTION = FALSE
  FUNCTION = TRUE
END FUNCTION
''==============================================================================
 FUNCTION ProcessLine( Src$) AS LONG EXPORT
  static As Integer IfUseFlag,IfUseOk,InUseBlock
static AS Integer i
static As Integer j
Dim As integer pc
DIM stemp$,s2$,s3$
static As Integer ClsMthdBlock
static clsname$
'==============================================================================
'We are starting a class method block where we need to add the class name to Function/Sub
'Get the class name -> clsname$ (It's in the format Class_Methods_Start classname)
If iMatchLft(Src$,"Class_Methods_Start") Then
ClsMthdBlock = TRUE
clsname$ = Trim$(Remain$(Src$," "))
? "'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*"
? "Class_Methods_Start"
? "'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*"
Src$ = ""
Function = 1
End If
'==============================================================================
If ClsMthdBlock Then 'we are in a Class_Methos block
If iMatchLft(Src$,"Class_Methods_End") Then
ClsMthdBlock = FALSE
clsname$ = ""
Src$ = ""
Function = 1
End if
If iMatchLft(Src$,"Constructor") Then
stemp$ = clsname$ + "::" + clsname$
Replace clsname$ With  stemp$ In Src$
Function = 1
ElseIf iMatchLft(Src$,"Destructor") Then
stemp$ = clsname$ + "::~" + clsname$
Replace clsname$ With  stemp$ In Src$
Function = 1
'==============================================================================
'This creates the complete method name and prints it.
' but the x_vector:: is stripped on return
ElseIf iMatchLft(Src$,"Function") Then
s2$ = STRIM$(Src$)
If Strtoken$(s2$," ",2) = "="  Then
Function = 1
End If
stemp$ = Right$(s2$,Len(s2$)-9)
Src$ = "Function " + clsname$ + "::" + stemp$
? "'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*"
? Src$
? "'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*"
Function = 1
'==============================================================================
ElseIf iMatchLft(Src$,"Sub") Then
s2$ = STRIM$(Src$)
stemp$ = Right$(s2$,Len(s2$)-4)
Src$ = "Sub " + clsname$ + "::" + stemp$
Function = 1
End If
End If

 '====================================================================
 ' Return a zero to throw an error back to BCX or you could just
 ' change Src$ to an illegal statement! and BCX would throw
 ' an error on its own.  Return 2 if you want to run this line
 ' back thru from the top just remember that you may get it again
 ' as the next line to process, depends on what line contains.
 '====================================================================
   FUNCTION = 1
 END Function
'==============================================================================


This is a modified C20.bas C++ example with the method wraped with CLASS_METHOD_START/END
Code: [Select]
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'Chapter 20. The method bodies can be defined below the class definition
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
$CPP
$CPPHDR
$NOMAIN
'$ONEXIT "VSCPP.BAT $FILE$ -m64 con"
$PP
'==============================================================================
Class x_vector
public:
Raw As double x,y
Dim Function surface() as double
End Class
'------------------------------------------------------------------------------
'This is my class method wrapper
CLASS_METHODS_START x_vector

Function surface() AS double
Raw As double s = 0

xFor double i = 0 While i < x By i++
s = s + y
xNext

Function = s
End Function
CLASS_METHODS_END 'x_vector

$PP
'==============================================================================
Function main () As int
Raw As x_vector k

k.x = 4
k.y = 5

std::cout << "Surface: " << k.surface() << std::endl
Pause

End Function



And this is the relavant c++ output
Code: [Select]
class x_vector
  {
  public:
    double   x;
    double   y;
    double   surface(void);
  };



// *************************************************
//               User's Prototypes
// *************************************************

double  x_vector (int (*) (void));
int     main (void);

// *************************************************
//            User's Global Initialized Arrays
// *************************************************



// *************************************************
//                 Runtime Functions
// *************************************************

void Pause(void)
{
  printf("\n%s\n","Press any key to continue . . .");
  _getch();
}



// *************************************************
//            User's Subs and Functions
// *************************************************

double x_vector (int (*surface) ())
{
  double   s=0;
    {
    double   i;
    for(i=0;i<x;i++)
      {
        s+=   y;
      }
      }

  return s;
}


int main ()
{
  x_vector  k;
  k.x= 4;
  k.y= 5;
  std::cout<<"Surface: "<<k.surface()<<std::endl;
  Pause();
  return 0;
}

« Last Edit: July 17, 2020, 05:07:20 PM by jcfuller »

Robert

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
Re: My BCXPP.DLL issues
« Reply #1 on: July 18, 2020, 03:57:25 PM »
BCXPP.bas

Code: [Select]

$DLL STDCALL
FUNCTION ProcessLine (Src$) AS LONG EXPORT
  IF Src$ = "DISPLAY MESSAGE" THEN
    Src$ = "Function x_vector::surface() AS double"
  END IF
  FUNCTION = 1
END FUNCTION


Test.bas

Code: [Select]

$PP
DISPLAY MESSAGE
$PP


BCXPP.bas translates and compiles correctly.

Test.bas, not so much ...

Code: [Select]

bcx Test -c

BCX BASIC to C/C++ Translator (c) 1999-2020 by Kevin Diggins
Version 7.5.0 (2020/07/18)  Compiled for 64-bit Windows using MS Visual C++
BCXPP.DLL Successfully Loaded
Error!
Test.bas
Possible missing END IF before END of program at line 3 in Module: Test.bas
Original line
$PP
==============
Current Tokens
==============
  1 $PP
===============
Original Tokens
===============
  1 $PP


jcfuller

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: My BCXPP.DLL issues
« Reply #2 on: July 18, 2020, 05:04:51 PM »
I made the call to DoJcfStuff() right after The 'Fix Brackets line (~2689) in bc9 (which does about the same as $PP)
Try moving the "IF PPFlag THEN" lines up there to see if it works.

James


jcfuller

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: My BCXPP.DLL issues
« Reply #3 on: July 18, 2020, 05:08:14 PM »
I just tried it and for my example it worked.

James

Robert

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
Re: My BCXPP.DLL issues
« Reply #4 on: July 18, 2020, 05:25:22 PM »
I just tried it and for my example it worked.

James

Hi James:

Tried it? What is it?

In BCX 7.5.0, you moved what lines to where?

jcfuller

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: My BCXPP.DLL issues
« Reply #5 on: July 18, 2020, 05:59:43 PM »
Robert,
  Move:
    IF PPFlag THEN           ' PreProcess the line
      GLOBAL ppret AS LONG
      ppret = PPProc(Src$)   ' Error in PP returns error message in Src$
      IF ppret = 0 THEN Abort(Src$)
    END IF

Up to ~line 2689
Next line after
IF INCHR(Src$,"[") THEN CALL BracketHandler(Src$,0)       'Fix Brackets

James



Robert

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
Re: My BCXPP.DLL issues
« Reply #6 on: July 18, 2020, 06:02:36 PM »
Robert,
  Move:
    IF PPFlag THEN           ' PreProcess the line
      GLOBAL ppret AS LONG
      ppret = PPProc(Src$)   ' Error in PP returns error message in Src$
      IF ppret = 0 THEN Abort(Src$)
    END IF

Up to ~line 2689
Next line after
IF INCHR(Src$,"[") THEN CALL BracketHandler(Src$,0)       'Fix Brackets

James

Excellent!

Thank you.

Sometimes we forget that others do not know the things we take for granted.

Robert

  • Sr. Member
  • ****
  • Posts: 448
    • View Profile
Re: My BCXPP.DLL issues
« Reply #7 on: July 18, 2020, 06:18:21 PM »
BCXPP.bas

Code: [Select]

$DLL STDCALL
FUNCTION ProcessLine (Src$) AS LONG EXPORT
  IF Src$ = "DISPLAY MESSAGE" THEN
    Src$ = "Function x_vector::surface() AS double"
  END IF
  FUNCTION = 1
END FUNCTION


Test.bas

Code: [Select]

$PP
DISPLAY MESSAGE
$PP


BCXPP.bas translates and compiles correctly.

Test.bas, not so much ...

Code: [Select]

bcx Test -c

BCX BASIC to C/C++ Translator (c) 1999-2020 by Kevin Diggins
Version 7.5.0 (2020/07/18)  Compiled for 64-bit Windows using MS Visual C++
BCXPP.DLL Successfully Loaded
Error!
Test.bas
Possible missing END IF before END of program at line 3 in Module: Test.bas
Original line
$PP
==============
Current Tokens
==============
  1 $PP
===============
Original Tokens
===============
  1 $PP


The above Test.bas is absolutely functionally inadequate.

It, that is, Test.bas, should be

Code: [Select]

$PP
DISPLAY MESSAGE
END FUNCTION
$PP




jcfuller

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: My BCXPP.DLL issues
« Reply #8 on: July 19, 2020, 04:24:23 AM »
My old memory has been jarred now and I remember in bc9 I take advantage of the:

 
Code: [Select]
      IF MacroCheck() = FALSE THEN
        IF SplitLines(Src$) THEN Src$ = SplitStk$[++SplitCur]   'Split statements separated by
      END IF
    ELSE                                                        'colons and single line if/then
      Src$ = SplitStk$[++SplitCur]
    END IF

    IF SplitCur = SplitCnt THEN SplitCur = SplitCnt = 0

To pass back multi-line statements for translation

James

jcfuller

  • Full Member
  • ***
  • Posts: 167
    • View Profile
Re: My BCXPP.DLL issues
« Reply #9 on: July 19, 2020, 09:53:28 AM »

Well I managed to get a CWindow example to compile and run but I also had to change char* to const char* for ucase, left,and mid in the BCX source.

James