Skip to content

anass-srk/pascal-compiler

Repository files navigation

Description

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).

Compilation

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.

Interpretation

The interpreter (pascal) is responsible for running the bytecode (*.bin file) generated by the compiler.

Execution

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

About

A simple pascal compiler. It generates custom bytecode that runs on our vm.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published