Skip to content

eirinigri/HY340--Compilers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

195 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Alpha Compiler & Virtual Machine (HY340)

Overview

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.

Workflow

  1. Parse Alpha source code (parser.ypp, scanner.l)
  2. Generate intermediate quads (control flow, expressions, etc.)
  3. Generate VM instructions (generate.cpp)
  4. Write binary output (output.abc)
  5. Run on AVM (avm)

Build & Run Instructions

Build

make clean
make parser
make avm
make run-{name for the txt file}

Run a Test

./parser text.txt      # Compiles Alpha source to output.abc
./avm output.abc       # Runs the binary on the AVM
  • You can use any .asc or .txt Alpha source file as input.
  • The output binary is written as output.abc (see parser.ypp).

Project Structure

  • 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

Supported Features

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

Missing Features

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

Contributing / Contact

  • For questions or contributions, please contact the course staff or open an issue.
  • See the code comments and the project-overview.mdc for architectural details.

Georgios Marios Souladakis - csd5070 Sylvana Anastasia Kakarontza - csd5196 Eirini Griniezaki - csd5111

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors