converts cambridge-style pseudocode to rtf with syntax highlighting. the pseudocode format follows the cambridge international syllabus - see the full guide for reference.
the colour scheme is based on xcode's prettyprint style in light mode. apple's design guidelines are available here.
run interactively:
python3 main.pypaste your pseudocode, then type END on its own line to finish.
or pipe input from a file:
python3 main.py < input.txtoutput files are written to the outputs/ folder.
rtf was chosen because it preserves syntax highlighting when pasted into microsoft word or apple pages.
colours are defined in core/constants.py in the COLOURS dictionary. each entry is (red, green, blue) in hex format, with inline comments indicating what each colour is used for.
IF, THEN, ELSE, ENDIF
FOR ... TO ... STEP ... NEXT
WHILE ... ENDWHILE
REPEAT ... UNTIL
CASE ... OF ... OTHERWISE ... ENDCASE
CALL
FUNCTION ... ENDFUNCTION
PROCEDURE ... ENDPROCEDURE
CLASS ... ENDCLASS
TYPE ... ENDTYPE
DECLARE
INPUT, OUTPUT, PRINT
OPENFILE, READFILE, WRITEFILE, CLOSEFILE
GETRECORD, PUTRECORD
RAND, RANDOM
RETURN
AND, OR, NOT
TRUE, FALSE
x ← 5
name ← "alice"
count ← count + 1
single-line comments using //:
// this is a comment
delimited by double quotes:
PRINT "hello world"
message ← "enter your name: "
DECLARE x : INTEGER
DECLARE name : STRING
DECLARE is_valid : BOOLEAN
DECLARE price : REAL
DECLARE ch : CHAR
DECLARE today : DATE
- arithmetic:
+,-,*,/,DIV,MOD - comparison:
=,<>,<,>,<=,>= - logical:
AND,OR,NOT
| element | colour |
|---|---|
| keywords | bold purple |
| strings | red |
| calls / procedures | bold purple |
members (after .) |
blue |
| comments | grey |
indices (after .) |
dark blue |
input:
// calculate factorial
DECLARE n : INTEGER
DECLARE result : INTEGER
INPUT n
result ← 1
FOR i ← 1 TO n
result ← result * i
NEXT i
OUTPUT result