Pętlik is a small programming language, which syntax is defined by the following grammar with the start symbol Program:
Program → InstructionSequence
InstructionSequence → ε | InstructionSequence Instruction
Instruction → Increment | Repeat
Increment → Variable
Repeat → '(' Variable InstructionSequence ')'
Variable → 'a' | ... | 'z'
Instructions:
Increment: equivalent to++variablein C, incrementing the variable by 1.Repeat: equivalent to a C-stylewhileloop:while (variable > 0) { --variable; ... }
The project consist of two components:
- An optimizing compiler that converts Pętlik programs into bytecode for a virtual machine.
- An interpreter for executing the bytecode.
Machine instructions:
INC Variable: increment the value ofVariableby 1.ADD Variable0 Variable1: add the value ofVariable1toVariable0.CLR Variable: set the value ofVariableto 0.JMP Address: jump to the instruction at the givenAddress.DJZ Variable Address: ifVariableis 0, jump to the specifiedAddress; otherwise, decrementVariableby 1.HLT: halt execution.
The program supports printing the values of variables and running Pętlik programs.