MiniPascal is a compiler for a largely simplified version of Pascal. It is fundamentally a toy for learning the workings of compilers, and shouldn't be taken seriously.
Authors: Joe Jones, Charles Randolph.
Compiling takes only a couple of steps.
- Build frontend and backend executables in top-level directory:
make subsystem
- Build the top level program (mpc) with:
make
That's it, the program should be ready to go. Simply invoke with ./mpc <inputfile> <outputfile>
Running Valgrind requires both the semantic analysis stage and intermediate code generation stage be run independently.
- Use
make
to produce the frontend's./a.out
. It is already compiled with-g
, so you can test it with:valgrind ./a.out < inputFile
. - Use
make
to produce the backend's./a.out
. It is already compiled with-g
, so you can test it with:valgrind ./a.out outputFile < inputFile
.
And that's it!
Variables may share identifiers so long as they are of a unique token-class. The possible token-classes are as follows:
- Scalar.
- Vector.
- Routine.
Only Scalar and Vector class variables may be assigned to. Variables with the Routine class may not be assigned.
Routines are defined as either Functions or Procedure. A Procedure is simply a function with no return value. MiniPascal treats Procedures as Functions with undefined return types. Function return values are scalar class variables which share the same name as the function. They are installed automatically.
Note: Routines only accept scalar and vector arguments.
You are required to provide routines with all their defined arguments. There are two exceptions to this.
readln(...)
writeln(...)
The above procedures accept a variable number of arguments. Neither writeln
or readln(...)
may be given constant or vector arguments, however.
- Constant expressions are reduced/folded where possible.
- Division-by-zero errors are thrown when division by a constant expression which is equivalent to zero (may be derived).
- Cascading errors are displayed for arithmetic operations involving undefined types.
- Boolean expressions are treated as integer arithmetic expressions where zero and nonzero define false and true respectively.
- Function calls and array indexes are reduced to their primitive types (Integer/Real).
- Variable type-classes are checked to ensure they may be assigned to.
- Assigned expressions are checked to ensure they are defined.
- A warning is displayed for assignments which truncate the assigned expression.
- An error is displayed for assignments declared above the maximum scope level.
- Variables being assigned another variable directly (i.e: x := y) will throw warnings if y is uninitialized.
- Checks that the number of arguments supplied are not equal to the defined amount (exceptions for
readln
,writeln
). - Checks that correct argument types are provided.
- A warning is displayed for argument expressions which will be truncated.
- Guard expressions in conditional statements are checked for proper integer type.
- An error is displayed if function return variables are left uninitialized. This is scope specific.