Translates BBC BASIC to Acorn ANSI C.

HTML Manual Edition 2.1 for !BBC_C Version 8.36

May, 2002

Martin Carradus

Copyright © 2002 Leaf Mindcraft and Melotech

5. Tips for Avoiding !BBC_C Syntax Errors.

5.1. Determining return values of FNs.

As mentioned above, reversing inequalities with FNs in them often avoids syntax errors. Also !BBC_C 'remembers' the return value of a FN that has been previously defined above the point in the code where the FN is being called. FNs returning numerics are taken differently to those returning character strings.

5.2. Bitwise ANDs, ORs, NOTs and EORs.

As mentioned above, expressions after IF, WHILE and UNTIL are taken to be C logical expressions. In all other cases (e.g. in assignments), the expressions are taken to be calculated in a bitwise manner using '&', '|', '~' and '^'. For these purposes, the BBC BASIC construct TRUE is translated to a #define macro _TRUE, which has the value -1. Similarly FALSE becomes _FALSE with the value 0. Note that ANSI C returns the value of +1 in logical expressions that are true, but BBC BASIC returns a value of -1.

Also, where the code is expecting a logical expression, !BBC_C can distinguish between those expressions that require to be taken in a logical or bitwise manner. Mixed expressions will cause !BBC_C to emit syntax error messages.

5.3. Badly bracketed programming structures.

!BBC_C attempts to close higher programming structures when lower ones close, but sometimes can't cope. In particular not closing DEF PROC with a final ENDPROC can cause problems. If your program causes !BBC_C to produce a blank output file, then it could be due to bad structure bracketing.

5.4. Returning values from FNs.

Returning a value from a FN using '=' via an IF statement can cause problems when the THEN is omitted. The only solution is to insert the THEN into the BBC BASIC code.

Similarly a test for equality in an IF statement (e.g. IF a%=b% c%+=1) should be bracketed (i.e. IF (a%=b%) c%+=1) because of the same conflict as to whether the '=' is being used as a test for equality or for returning a value from a function.

5.5. EVAL, Variable GOTOs and Variable GOSUBs.

!BBC_C is unable to cope with these constructs. EVAL produces an error message in the code. Variable GOTOs and GOSUBs result in meaningless C code. 'Structured Programming' techniques demonstrate that you should be able rewrite your program to avoid these sorts of construct.

This document was generated on 20th May 2002 for !BBC_C distributed by Melotech for Martin Carradus.