Author Topic: BCX Online For 21 Years !  (Read 75 times)

Robert

  • Hero Member
  • *****
  • Posts: 710
    • View Profile
BCX Online For 21 Years !
« on: July 09, 2021, 12:20:40 AM »
First post on the Yahoo Forum.

From: kdiggins@uswest.net
Date: Sun Jul 9, 2000 4:32 am
Subject: Welcome!   kdiggins@uswest.net
        
Okay ... here it is!  Start Posting!

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 959
    • View Profile
Re: BCX Online For 21 Years !
« Reply #1 on: July 09, 2021, 07:35:47 AM »
Below is the very first version of the translator that I wrote in July 1999.

It wasn't called BCX yet, it could not compile itself, and it was written in PowerBASIC for DOS.



Code: [Select]

$COMPILE EXE
DIM STK$(1024)

DIM Varname$(1024)
indent = 0

INFILE$  = EXTRACT$(UCASE$(COMMAND$),".BAS") + ".BAS"
OUTFILE$ = EXTRACT$(UCASE$(COMMAND$),".BAS") + ".C"
OPEN INFILE$  FOR INPUT AS 1
OPEN OUTFILE$ FOR OUTPUT AS 2
CALL EMITPROLOG
WHILE NOT EOF(1)
   LINE INPUT #1,SRC$
   CALL PARSE (SRC$)
   CALL GetVariables
   CALL EMIT
WEND
CALL EmitEpilog
CLOSE

OPEN outfile$ FOR INPUT AS 1
OPEN "$t$e$m$p" FOR OUTPUT AS 2

FOR a = 1 TO 13
   LINE INPUT #1,a$
   ? #2,a$
NEXT

FOR a = 1 TO allocated
   ? #2,"static float "; varname$(a) ; ";"
NEXT
WHILE NOT EOF(1)
   LINE INPUT #1,a$
   ? #2,a$
WEND
CLOSE
KILL outfile$
name "$t$e$m$p" AS outfile$





SUB Parse (Arg$)
   ' ===============================================
   ' Stk$() and Ndx must be declared global
   ' These are re-initialized with each invocation
   ' ? is converted to PRINT
   ' All non-quoted text is converted to upper case
   '================================================
   SHARED Stk$(),Ndx
   REDIM Stk$(100)
   Ndx = 0

   LOCAL Char$,Counter,Strlit$,Anyword$

   DO UNTIL Counter = LEN(Arg$)
      INCR Counter
      Char$ = MID$(Arg$,Counter,1)

      SELECT CASE Char$

         CASE CHR$(34)
         StrLit$ = Char$
         Char$ = ""
         DO UNTIL Char$ = CHR$(34)
            INCR Counter
            Char$ = MID$(Arg$,Counter,1)
            StrLit$ = StrLit$ + Char$
         WEND
         INCR Ndx
         Stk$(Ndx) = StrLit$


         CASE " "
         IF Anyword$ > "" THEN
            INCR Ndx
            Stk$(Ndx) = UCASE$(Anyword$)
            Anyword$ = ""
         END IF


         CASE "(", ")" , "," , "+" , "-" , "*", "/", "=" , "?"
         IF Anyword$ > "" THEN
            INCR Ndx
            Stk$(Ndx) = UCASE$(Anyword$)
            Anyword$ = ""
         END IF
         INCR Ndx
         IF Char$ = "?" THEN Char$ = "PRINT"
         Stk$(Ndx) = Char$


         CASE ELSE
         Anyword$ = Anyword$ + MID$(Arg$,Counter,1)

      END SELECT

   LOOP

   IF Anyword$ > "" THEN
      INCR Ndx
      Stk$(Ndx) = UCASE$(Anyword$)
   END IF

   IF Stk$(2) = "=" THEN SWAP Stk$(1),Stk$(2)
END SUB




SUB EmitProlog
   ? #2,"/* _________________________________________ */
   ? #2,"/* Created with the Basic to C translator    */
   ? #2,"/*            by Kevin Diggins 1999          */
   ? #2,"/* ----------------------------------------- */
   ? #2,"
   ? #2,"#include <stdio.h>
   ? #2,"#include <string.h>
   ? #2,"#include <stddef.h>
   ? #2,"#include <stdlib.h>
   ? #2,"#include <ctype.h>
   ? #2,
   ? #2, "void main()"
   ? #2, "{"
END SUB



SUB EmitEpilog
   ? #2,"}"
END SUB



SUB Emit
   SHARED Stk$(),Ndx,Indent

   SELECT CASE (Ucase$(Stk$(1)))

      CASE "="
      ? #2,SPACE$(indent);Stk$(2);"=";
      FOR A = 3 TO Ndx
         ? #2,Stk$(a);
      NEXT
      ? #2,";"


      CASE "WHILE"
      ? #2,SPACE$(indent);"while(";
      FOR A=2 TO Ndx
         ? #2,Stk$(a);
      NEXT
      ? #2,")"
      INCR indent,2
      ? #2,SPACE$(indent);"{"



      CASE "WEND"
      ? #2,SPACE$(indent);"}"
      DECR indent,2


      CASE "IF"
      ? #2,SPACE$(indent);"if(";
      Tmp = 2
      WHILE Ucase$(Stk$(Tmp)) <> "THEN"
         ? #2,Stk$(Tmp);
         IF Stk$(Tmp) = "=" THEN ? #2,"=";
         INCR Tmp
      WEND
      ? #2,")"
      INCR indent,2
      ? #2,SPACE$(indent);"{"
      Tmp = 0


      CASE "END"
      IF UCASE$(STK$(2)) = "IF" THEN
         ? #2,SPACE$(indent);"}"
         DECR indent,2
      END IF



      CASE "PRINT"

      FOR Tmp = 2 TO Ndx
         SELECT CASE Vartype(Stk$(Tmp))
            CASE 1
            ? #2,SPACE$(indent);"printf("+CHR$(34)+"%s"+CHR$(34) + "," + Stk$(Tmp) +");"
            CASE 2
            ? #2,SPACE$(indent);"printf("+CHR$(34)+"%d"+CHR$(34) + "," + Stk$(Tmp) +");"
            CASE 3
            ? #2,SPACE$(indent);"printf("+CHR$(34)+"% .7g "+CHR$(34) + "," + Stk$(Tmp) +");"
         END SELECT
      NEXT
      ? #2,SPACE$(indent);"printf(" +CHR$(34) + "\n" +CHR$(34) + ");"

   END SELECT

END SUB




FUNCTION Vartype(A$)
   IF INSTR(a$,CHR$(34)) THEN Vartype = 1 : EXIT FUNCTION ' strlit
   IF INSTR(a$,"%")      THEN Vartype = 2 : EXIT FUNCTION ' integer
   Vartype = 3                 ' default to float
END FUNCTION




SUB GetVariables
   LOCAL Var$, a,b
   SHARED VarName$()
   SHARED Ndx
   SHARED Stk$()
   SHARED Allocated

   FOR a = 1 TO Ndx

      Var$ = Stk$(a)

      FOR b = 1 TO 1024
         IF Var$ = "IF"    THEN EXIT FOR
         IF Var$ = "THEN"  THEN EXIT FOR
         IF Var$ = "END"   THEN EXIT FOR
         IF Var$ = "WHILE" THEN EXIT FOR
         IF Var$ = "WEND"  THEN EXIT FOR
         IF Var$ = "PRINT"  THEN EXIT FOR

         IF IsNumber(Var$) THEN EXIT FOR
         IF INSTR(Var$,CHR$(34)) THEN EXIT FOR
         IF INSTR(Var$, any "+-*/\|=<>") THEN EXIT FOR

         IF Var$ = VarName$(b) THEN EXIT FOR     'Already allocated
         IF VarName$(b) = "" THEN
            VarName$(b) = Var$                    'not allocated, Add to table
            INCR allocated
            EXIT FOR
         END IF
      NEXT

   NEXT
END SUB



FUNCTION IsNumber(A$)
   X = VERIFY(A$,".-0123456789")
   IF X = 0 THEN
      IsNumber = -1
   ELSE
      IsNumber = 0
   END IF
END FUNCTION


rexxitall

  • Newbie
  • *
  • Posts: 33
    • View Profile
Re: BCX Online For 21 Years !
« Reply #2 on: July 09, 2021, 11:26:19 AM »
Every journey starts like that :) My ACAD monster thing was first a simple routine running on a sharp PC 1402 which interpolates hights :D But somehow those babys becommes bigger and bigger by time :)