This is a pseudo-code compiler for the CIE IGCSE and AS&A Levels Computer Science course. It is designed to be used with 0478/9718/9708.
I am using the official CIE pseudo-code specification as a reference for this compiler. You can find the specification here.
WHY IS IT CALLED PSEUDOCODE IF IT CAN BE COMPILED? IT'S NOT PSEUDOCODE IF IT CAN BE COMPILED. IT'S A REAL PROGRAMMING LANGUAGE. IT'S NOT PSEUDO.
The compiler is not exactly a compiler, I am using ply
(Python Lex-Yacc) to parse the pseudo-code and convert it to an abstract syntax tree (AST).
I then use the AST to generate C++ code, and call g++
to compile the generated C++ code.
- Write your pseudo-code in a file (e.g.
code.psc
) - Run the compiler with the file as an argument (e.g.
python main.py code.psc
) - The generated C++ code will be in
temp/temp.cpp
- The compiled binary will be in
temp/temp(.exe)
- If the
-r
flag is used, the compiled binary will be run
- Python 3
- gcc (for compiling the generated C++ code)
- No PEMDAS/BODMAS support, use brackets to enforce order of operations
- Only the following are supported right now
IF
statements (with or withoutELSE
)REPEAT
loopsFOR
loopsWHILE
loops- All data types except
DATE
- All variable types except
CONSTANT
OUTPUT
andINPUT
statements- Multi-expression
OUTPUT
statements - All arithmetic operators
AND
,OR
,NOT
logical operators- All comparison operators
DECLARE
and<-
assignment operators- More things I can't remember right now
PROCEDURE
definitions with or without parametersFUNCTION
definitions with or without parameters- expression evaluation of function calls
CALL
statements with or without parameters
- Haven't tested on linux or mac yet, probably won't work
$ python main.py -h
usage: main.py [-h] [-o OUTPUT] [-c CFILE] [-r] [-d] file
positional arguments:
file The file to compile
options:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
The output file
-c CFILE, --cfile CFILE
The C file to generate
-r, --run Run the compiled file
-d, --debug Debug output