As hjalfi said before, FastBasic is really close to COMAL already, and could be made more compatible with some changes.
The "small" differences are:
- Multi-line "IF" and the "ELIF" statement don't require the "THEN" keyword.
- "CASE" is not implemented. I did not implement "CASE" as it need to store the value of the CASE to compare with all the WHEN clauses, making it complicated. And, using IF/ELIF/ELSE/ENDIF seems more intuitive to the programmer.
- Procedures don't support "REF" parameters, all parameters are passed by value. Implementing "REF" parameters is possible, creating new variable types (ref-to-*).
- Procedures don't have local variables (i.e., are always "OPEN" in COMAL parlance). Implementing local variables is not difficult, but FastBasic currently has a limit of 256 total variables in a program - this is or performance, as the interpreter uses the variable number as an index into the variable storage.
- Floats can't be converted to integers automatically, you need to use "INT()". This is a personal preference, it avoids a lot of programming errors, and makes the parser faster.
And more fundamental "limitations" are, in order of difficulty of implementation:
- FastBasic does not have "runtime errors", you must check math or I/O errors in your program using the "ERR()" function. The only error is "out of memory", this terminates the program. This is by design, as good programs should check errors and proceed
- There is no "GOTO". This makes the parser simpler and less error-prone. COMAL restricts the GOTO keyword so that you can't transfer into a structured statement, procedure or function, but detecting this in a single-pass parser would be difficult. Also, implementing a GOTO out of a structured statement would mean the parser should emit code depending on the target, also very difficult in a single pass.
- "DATA" statements don't work like BASIC - they simply define arrays in memory with all the data initialized. There is no "READ" statement. IMHO, this is simpler, faster and more useful
- FastBasic does not support multi-dimensional arrays or changing array lower bounds. This is for performance and simplicity, as arrays are stored as pointers to the first element, the parser converts "PRINT A(X)" to "PRINT DPEEK(&A + 2 * X)" directly in the generated code. To support multi-dimensional arrays, the interpreter will need to store the array dimensions in a bloc of memory, and the array stored as a pointer to this array block, so all array accesses would be slower.
- Implementing functions is more complicated, because the FastBasic parser assumes that values in one statement are assigned only once and there are no side effects in the evaluation of expressions. For example, most string functions returns a string in a fixes memory location, and array or string assignments use a register to store the address on which to store the expression value. This means that a function could not contain any assignments.
- Also, recursive functions would need "stack variables". FastBasic currently only has a small evaluation stack - with an 8 bit stack-pointer. Using a bigger stack-pointer would make the interpreter considerably slower. IMHO, recursive functions are a bad idea in an 8-bit computer.
Have Fun!