Cambridge Pseudocode to Python
Intro
This is a translator written in Haskell that translate a pseudocode source file into a Python script.
The adopted pseudocode language is from GCSE and Advanced Level's computer science textbook and 9618 syllabus.
How to Use?
Compile
- Install Glasgow Haskell Compiler.
- Run
compile.sh
on UNIX orcompile.cmd
on Windows. - An executable
campseudo-to-py
will be generated.
Translate Pseudocode
UNIX
./campseudo-to-py file_path
Windows
.\campseudo-to-py.exe file_path
e.g. If the source file is hello.whatever
,
then hello.whatever.py
will be generated.
Run Pseudocode
UNIX
./run.sh file_path
Windows
.\run.cmd file_path
Language Feature Supported
Data Type
-
INTEGER
(by value) -
REAL
(by value) -
STRING
(by value) -
CHAR
(by value) -
BOOLEAN
(by value) -
ARRAY
(by reference, multi-dimensional) -
TYPE
(by value, enumerated) -
TYPE
(by reference, composite)
Statement
- Assignment
-
DECLARE
-
INPUT
/READ
-
OUTPUT
/PRINT
-
RETURN
-
CALL
Control Flow
-
IF THEN ENDIF
-
IF THEN ELSE ENDIF
-
WHILE DO ENDWHILE
/WHILE ENDWHILE
-
REPEAT UNTIL
-
FOR TO NEXT
/FOR TO ENDFOR
-
FOR TO STEP NEXT
/FOR TO STEP ENDFOR
-
CASE OF OTHERWISE ENDCASE
- Predicate
TO
inCASE
Subroutine
Due to the severe side effect caused by BYREF
, BYREF
will not be
implemented. See Data Type for default passing method.
-
PROCEDURE ENDPROCEDURE
-
FUNCTION ENDFUNCTION
Pointer
Too many side effect! No pointers allowed!
File
-
OPEN FOR
/OPENFILE FOR
-
READFILE
-
WRITEFILE
-
EOF
-
CLOSEFILE
Built-in Functions
INT
CHR
ASC
LCASE
UCASE
TO_UPPER
TO_LOWER
LENGTH
LEFT
RIGHT
MID
NUM_TO_STRING
RAND