
BBC BASIC to GW-BASIC Converter Version 1.4  Martin Carradus  May 1993
----------------------------------------------------------------------

*** THIS IS PD SOFWARE - YOU MAY COPY AND DISTRIBUTE IT FREELY.           ***
*** THE AUTHOR DOES NOT GUARANTEE ITS ACCURACY OR USEFULNESS              ***
*** FOR ANY PURPOSE.                                                      ***

Converts program files from BBC BASIC to GW-BASIC format.

Converter:
  
  1. Converts line numbers and "next line" positions - coded at the
  beginning of each line.
  
  2. Converts key word tokens to their nearest equivalents.
  (Key words are coded into bytes by the line editor - key words are
  words such as IF, ENDIF, FOR, NEXT, GOTO etc.)
  
  3. Converts references to line numbers within the program (e.g. after
   GOTOs). Both BASICs have a special way of coding these.
  
  4. Converts numeric literals e.g. 123, -7 to their GW-BASIC representation.
  Also converts hex literals to GW-BASIC hex literals, but binary literals
  to octal literals.
  
  5. Converts variable names to upper case and removes underscores -
  beware if in doing so two names are made the same.
  
  6. Leaves assembler alone - it is not converted.
  
  7. Leaves DATA statements, REMs and string literals e.g. "Some String"
  alone - as it should. (i.e. does not convert to upper case or remove
  underscores).
  
  8. Converts the operators +,-,*,/,^,=,>,< to their GW-BASIC tokens, but
  does not convert any other operators.                                 
  
  9. Offers the option of setting the converted file type to DOS.
  
  10. Does not convert OSCLI, *FX or VDU commands (apart from VDU 7 to
  BEEP). In particular does not deal with VDU 2 and VDU 3.
  
  11. Produces statistics of the BBC BASIC program, which can be sent
  to the VDU, Printer or to a file. 

  12. The syntax of the BBC BASIC program is not checked. A bad BBC
  BASIC program will produce a bad GW-BASIC program. However the
  format is checked - absolute garbage should be detected.                 
         --
  
  It was found to be difficult to translate file handling commands and
  some token values may have been missed - the program indicates if this
  happens.
    
  If anything has been missed and the GW interpreter indicates a
  syntax error, usually retransmitting the line converts it to
  GW-BASIC format.
  
  The program attempts to offer the user the option of getting the output
  file name into MSDOS format i.e. uppercase, not more than eight 
  characters and with the Acorn extension \BAS if one is not given.
  
  Program structures are not converted. This is what you do with them.
  
  1. FOR ... NEXT
     ------------
     This is converted, but note that GW-BASIC FOR loops are not executed
     from the start if the end condition has been met. BBC BASIC FOR loops
     are always executed at least once. You may have to alter the end 
     condition to force the loop to execute at least once in GW-BASIC.       
     
  2. WHILE ... ENDWHILE
     ------------------
     Converted to WHILE ... WEND
   
  3. IF ... THEN ... ELSE ... ENDIF
     ------------------------------
     
     i.e.
     
     IF condition THEN
     
     statements
     
     ELSE
     
     statements
     
     ENDIF
  
  
    
     Alter this to:
       
     IF condition THEN GOTO line1 ELSE GOTO line2
line1
     statements
     
     GOTO endline
line2 REM ELSE

     statements
     
endline REM ENDIF

     If there is no ELSE, make line2 equal to endline, and get rid of the
     extra GOTO endline.
          
  4. REPEAT ... UNTIL
     ----------------
     i.e.
     
     REPEAT
     
     statements
     
     UNTIL condition
                     
   
     
     Alter this to:
       
line1 REM REPEAT

      statements
      
      IF condition GOTO line2
      GOTO line1
line2 REM UNTIL condition

  
   5. CASE ... OF ... WHEN ..... OTHERWISE ... ENDCASE
      ------------------------------------------------
      
      i.e.
      
      CASE expression OF
      WHEN expression, expression...: statements
      
      statements
      
      WHEN expression, expression...: statements                      
      
      statements
      ......
      ......
      OTHERWISE statements
      
      statements
      
      ENDCASE
      
      
      Alter this to:
        
      REM CASE expression OF
      I=expression            (where I is an unused variable of the right
                               type - i.e. float, string or integer)
      REM WHEN expression, expression...:statements
      IF I=expression OR I=expression ... THEN statements ELSE GOTO line1
     
      statements
      
      GOTO endline
line1 REM WHEN expression, expression   :statements
      IF I=expression OR I=expression ... THEN statements ELSE GOTO line2
      
      statements
      
      GOTO endline
line2 REM WHEN expression, expression   :statements
      IF ....

      ......
      ......
      
endline REM OTHERWISE:statements
        statements
        REM ENDCASE                                                
        
      If there is no OTHERWISE, make the last ELSE GOTO point to the line
      of the REM ENDCASE and endline is also that of REM ENDCASE.
      
   6. PROCs
      -----
      
      Convert these to GOSUBs.
      
   7. FNs
      ---
      If it is a single line, then nothing need be done. If it is
      multi-line, the best that can be done is to convert it into a
      GOSUB.

      Final Comments
      --------------
      
      It would be easier translating the other way around, since BBC BASIC
      is higher level than GW-BASIC and downwardly compatible. Also the
      Acorn Archimedes is a 32 bit machine, whereas the IBM PC is sixteen
      bit. Some accuracy may be lost with floating point numbers and very
      large integer literals cannot be translated. Some programs may 
      overflow (numbers get too large for sixteen bits).
      
      Lastly the constructs:
        
      Variable+=SomeValue   e.g. I+=1    - means I=I+1
      
      and
      
      Variable-=SomeValue   e.g. J-=2    - means J=J-2 
      
      ARE converted, BUT
      
      Array()=SomeValue     e.g. A()=-1  - sets all of the array A to -1
      
      is not converted.
      
      Pretty crummy, Eh? It is hoped to improve on this if time allows.
      
      I have included the header for the C program  in "h", which
      contains a full list of BBC BASIC tokens. 
      
      BBCTEST is a test BBC BASIC program.
      
      All comments, queries, curses to:-
      
      Martin Carradus,
      3, Connaught Road,
      Ilkley,
      West Yorkshire.
      LS29 8QW.
      U.K.
      
      Enclose s.a.e. if you want a reply.
      
      Good Luck in your conversions!
      