This is a simple pascal compiler + interpreter for our school project at ENSIAS (2A GL 2023-2024).
The grammar is located in gram.txt (reduced grammar from http://www.felix-colibri.com/papers/compilers/pascal_grammar/pascal_grammar.html).
The compiler (pascalc) runs 4 tasks :
Lexical analysis : dividing the input into lexemes/words.
Synataxial analysis : grouping lexemes and matching them against synataxial/production rules to form sentences.
Semantic analysis : checking whether these sentences are valid (meaningful).
Code generation : generates bytecode (custom opcodes) equivalent to the instructions of the pascal source code provided.
The interpreter (pascal) is responsible for running the bytecode (*.bin file) generated by the compiler.
First of all,a c++ compiler supporting c++20 should be installed.
Compile the pascalc and pascal as follows (clang++ for example) :
clang++ -std=c++20 lexer.cxx parser.cxx vm.cxx pascalc.cxx -o pascalc
clang++ -std=c++20 vm.cxx pascal.cxx -o pascal
To compile and run an pascal program provide the filename without extension as an argument.
For instance :
pascalc test/say_hello
pascal test/say_hello