LPC is a simple Pascal compiler, primarly intended as a sandbox to experiment with compiler construction ideas. It grew from a toy compiler for a small subset of Pascal (originally generating 80206 assembly, although the code for that backend is now lost)
Currently it supports the core ISO 7185 features and it generate C++ code or MSIL (CIL) assembly targeting .NET CLR.
It was never meant to be a production compiler, and the design decissions reflect that. It's not an "optimizing compiler" either. Instead, the main goals are:
- A simple and clean architecture
- Explicit grammar specification (Lex/Yacc style lexer and parser)
- Intuitive data structures (AST, symbol table and type system)
- Clear separation between the front end and the backend (using an AST visitor interface)
- Small language support runtime
- Reasonably clean code generation (human readable and preserving the structure of the original Pascal code as much as possible)
- Visual C++ 2017 or later (the Community edition should suffice)
- Flex++/Bison++. Must be added to the PATH.
- Python 3 (needed to run the tests)
Important: Flex++ may require a small manual patch. If the build complains about a missing
osfcn.h
header, comment out or remove the corresponding#include <osfcn.h>
from theflexskel.cc
file (located next to the flex++.exe binary)
- Load
lpc.sln
in Visual Studio, then build (ex. Build/Build Solution) lpc.exe
is the executable (by default located in the Debug or Release subdirectory)- The
lpc.exe
has a very simple command line interface:lpc [options...] <inputFile>
- Run
lpc -?
for the list of options
The tests are under the test
directory (Python3 is required to run the tests)
-
Setup the Visual C++ command line environment
- Option 1: From the IDE, use "Tools / Visual Studio Command Prompt"
- Option 2: Run vcvarsall.bat from a command line window
-
Execute runTests.py from the
test
directoryThe build flavor (debug/release) and the code generation target must be selected (currently cpp or clr). For example:
python runtest.py debug clr
- standardpascal.org
- Pascal-P5 compiler
- Compiling for the .NET Common Language Runtime (CLR)
- .NET IL Assembler
- CIL Programming: Under the Hood of .NET
A special thank you to Scott A. Moore, the creator of standardpascal.org for maintaining one of the best collection of materials about ISO 7185 (Standard Pascal).
This is not an officially supported Google product