This is a manual rekeying of Jeremy Ruston's simple Pascal compiler in his book Pascal for Human Beings published in 1982.
The original copyright to the book and original code is Copyright (c) Jeremy Ruston, January 1982. But I imagine it's listed in the book with the intention that you type it in and learn from it.
- The compiler is a BASIC programme which is compatible with BBC BASIC.
- It contains data statements at the beginning from 1 to 999 - these are used to contain the Pascal program
- The compiler itself resides from 1000 to 4870
- It "compiles" or converts the Pascal code into BBC BASIC compitable code
- The code is not written to a file, just written to the screen
It's based on Pascal as it was in 1982 (!) and will convert most Pascal programs of that era into an equivalent BASIC program. The book lists these limitations:
- No user defined functions or procedures
- No user defined data types
- No sets
- No arrays/matrices
- No true integer arithmetic
- No numerical output formatting
- No file handling
- No nest 'IF-THEN' statements
- No more than one statemetn is allowed the 'THEN' section of an 'IF' statement
- No spaces are allowed in expressions. Brackets can always be used to make up for this shortcoming.
- The layout of VAR and CONST section sof a program is crucial, see example program
- The colon in a VAR section, the equals sign in a CONST section and the ':=' symbols in an assignment must all be flanked by spaces
- Very little syntax checking is carried out - you can write an incorrect Pascal program, and the compiler will not tell you, but the error routines in the BASIC interpreter which executes the compiled BASIC program should do
- The compiler outputs to the screen only, so you need a means to capture the output
- No case statement
- Variable names are limited to those accepted by the version of BASIC you are using
- Notice BEGIN and END are obligatory in WHILE and FOR loops
- The compiler relies heavily on GOTO and GOSUB statements rather than procedures - would be easy to convert and make it a little more understandable
- It's actually pretty straight forwared to see what it's doing, Jeremy took time to comment the code with REM statements back in the day
- The code is described in detail on (book) pages 57 - 64 of Pascal for Human Beings
- Takes about 20 seconds to complete on a BBC Model B and almost instant on a modern computer
You can use the compiler.bbc file to generate basic code using a real BBC Micro, an emulator such as BeebEm, beebjit, B-Em (or many others) or a native BBC BASIC implementation for a modern operating system
The compiler.bbc and basic.bbc are pre-tokenised BBC BASIC files that can be loaded into e.g. the native BBC BASIC tools
The compiler.txt and basic.txt files are untokenised and raw text files. These can be cut and paste in any tool or migrated into an appropriate operating system (not just BBC BASIC).
The pascal.ssd file can be loaded into any BBC Micro Emulator and the compiler executed with '''CHAIN "COMPILE"''. The compiled output is also pre-stored and can be run with '''CHAIN "BASIC"'''