Skip to content

About

Lab works on the course "Compilers design", BMSTU, IU9, 6th term

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Compiler Construction Labs

Laboratory assignments for the BMSTU IU9 compiler construction course, 2024. The labs are independent programs, from lexers to parser generation and type checking. Most use C++20; the AST transformation uses Go, and two parsers use Python.

Labs

Lab Task Tools Report
1-1 Modify and bootstrap the P5 Pascal compiler Pascal RU
1-2 Regular-expression lexer C++, Boost.Regex RU
1-3 Hand-written lexer for numbers and strings C++ RU
1-4 Table-driven DFA lexer C++ RU
1-5 Lexer for chemical equations C++, Flex RU
2-1 Instrument a Go AST to count loop iterations Go RU
2-2 Grammar and AST of a functional language Python, parser EDSL RU
2-3 Table-driven predictive parser C++, Flex RU
2-4 Recursive-descent parser with JSON AST output C++, Flex, Boost.JSON RU
3-1 Self-applicable LL(1) parser-table generator and calculator C++, Flex, Boost RU
3-2 AST-based source formatter C++, Flex, Bison RU
3-3 Semantic analysis and type checking Python, parser EDSL RU

Build and test in a container

Run from the repository root. The image contains the build tools; the checkout is mounted read-only, and build products and caches stay inside the container.

docker build -f Containerfile.dev -t iu9-compilers-dev .
docker run --rm -v "$PWD:/workspace:ro" iu9-compilers-dev

With rootless Podman on Fedora:

podman build -f Containerfile.dev -t iu9-compilers-dev .
podman run --rm --userns=keep-id -v "$PWD:/workspace:ro,Z" iu9-compilers-dev

Pass -e SANITIZE=1 -e BUILD_TYPE=Debug to either run command to check C++ with AddressSanitizer and UndefinedBehaviorSanitizer. Both modes are run in CI.

The check script builds nine C++ executables, runs their regression cases, builds and tests the Go tools, and checks valid and invalid Python inputs. The historical P5 bootstrap (lab1-1) is not automated: its original tooling is not included as a runnable environment.

Run individual labs

With the dependencies installed, ./scripts/check.sh performs the same checks locally. BUILD_ROOT=build keeps build products; BUILD_JOBS=4 sets parallelism. Without BUILD_ROOT, the script uses a temporary directory and removes it on exit.

For example, build and run the calculator:

cmake -S lab3-1/apps/calculator/src -B build/calculator
cmake --build build/calculator
./build/calculator/calculator lab3-1/apps/calculator/examples/example.txt
# 15
ctest --test-dir build/calculator --output-on-failure

The generator, formatter, JSON parser, and Go transformer have separate run instructions.

Dependencies: CMake 3.22.1+, a C++20 compiler, Flex 2.6 (including FlexLexer.h), Bison 3.8.2+, Boost 1.75+ (Regex, JSON, Program_options), Go 1.22+, and Python 3.10+. The Python parser EDSL is included; no pip packages are needed.

Original submissions

Reports are retained as submitted, including their historical source listings. The current source files include later fixes and may differ from those listings. P5 and the parser EDSL are supplied course materials; see provenance. No repository-wide license has been assigned.

About

Lab works on the course "Compilers design", BMSTU, IU9, 6th term

Resources

Stars

1 star

Watchers

1 watching

Forks

Used by

Contributors

Languages