A project for Year 12 Software Design and Development which will allow students to explore:
- Machine code and the CPU
- Metalanguages
- Translation, specifically:
- lexical analysis including token generation
- syntactical analysis including parsing
- code generation
Theoretical discussion of metalanguages, and lexical and syntactical analysis can be quite dry and often the importance is lost on students who wonder why the hell they are learning this stuff that they will never use. The intent here is to introduce these concepts through the challenge of developing their own executable language. It also addresses the issue that a syntactically rigid pseudocode like that specified in the SDD Course Specifications defeats the whole purpose of pseudocode (don't get me started)
The initial task is to write an executable version of pseudocode that can print out the fibonacci series. The PseudoExe scripts will have a suffix of *.pse. The script for the ultimate goal is fibonacci.pse
is:
BEGIN Fibonacci
LET currentNumber = 0
DISPLAY currentNumber
LET prevNumber = currentNumber
LET currentNumber = prevNumber + 1
DISPLAY currentNumber
FOR LET counter = 0 TO 20 STEP 1
LET tempNumber = currentNumber
LET currentNumber = currentNumber + prevNumber
LET prevNumber = tempNumber
DISPLAY currentNumber
NEXT counter
END Fibonacci
This project is very heavily based on Marcelo Andrade's work Writing your own programming language and compiler with Python
You will need to install the following:
- LLVMLite A lightweight LLVM python binding for writing JIT compilers
pip install llvmlite
- RPLY A pure Python parser generator
pip install rply
ATM this project is compLETely untested - we are on this journey together