This project implements a full compiler and stack-based virtual machine (AVM) for the Alpha programming language, as part of the HY340 course. The system parses Alpha source code, generates intermediate code (quads), translates them to VM instructions, serializes them to a binary file, and finally executes them on a custom AVM.
- Parse Alpha source code (
parser.ypp,scanner.l) - Generate intermediate quads (control flow, expressions, etc.)
- Generate VM instructions (
generate.cpp) - Write binary output (
output.abc) - Run on AVM (
avm)
make clean
make parser
make avm
make run-{name for the txt file}
./parser text.txt # Compiles Alpha source to output.abc
./avm output.abc # Runs the binary on the AVM
- You can use any
.ascor.txtAlpha source file as input. - The output binary is written as
output.abc(seeparser.ypp).
- parser.ypp, scanner.l: Front-end (parsing, symbol table, error checking)
- target.cpp/hpp, backpatch.cpp/hpp: Intermediate code (quads), backpatching
- generate.cpp, instruct.hpp, vmargs.cpp/hpp: Target code (VM instructions), constant pools
- binary_writer.cpp/hpp: Serializes VM instructions and constants to binary
- avm.cpp/hpp, avm_execute.cpp/hpp, avm_state.hpp, avm_loader.cpp/hpp, avm_libfuncs.cpp: The Alpha Virtual Machine (AVM)
- Tests/, phase5Tests/: Test programs
- Lexical and syntactic analysis for Alpha
- Symbol table with scope and type management
- Intermediate code (quads) for all major constructs: assignments, expressions, if/else, while, for, function calls, tables
- Backpatching for control flow
- Translation to stack-based VM instructions
- Constant pools for numbers, strings, user/library functions
- Binary output format (
output.abc) - AVM with support for:
- Arithmetic, relational, and logical operations
- Function calls and returns
- Library functions (e.g.,
print,typeof) - Table creation and manipulation (partially)
- Control flow (if, while, for, break, continue)
- Table operations: Table creation is stubbed, get/set element is not fully implemented in the AVM.
- Error handling: Some runtime and compile-time errors may not be fully reported or handled (e.g. usser functions).
- Memory management: Reference counting for tables is not fully implemented.
- Advanced library functions: Some library functions may be incomplete.
- For questions or contributions, please contact the course staff or open an issue.
- See the code comments and the
project-overview.mdcfor architectural details.
Georgios Marios Souladakis - csd5070 Sylvana Anastasia Kakarontza - csd5196 Eirini Griniezaki - csd5111