Skip to content

VittorioRossetto/ImpLanCompiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPProj2

Overview

This project implements a small compiler pipeline for a toy language called ImpLan and a corresponding stack-based virtual machine (SVM).

The main pipeline is:

  1. Parse ImpLan source with ANTLR4
  2. Build an AST
  3. Build a symbol table and perform type checking
  4. Generate SVM assembly code
  5. Assemble SVM code into bytecode
  6. Execute the bytecode on the SVM

During execution, the program prints the generated AST, the inferred program type, the generated SVM code, and the final result.

Requirements

  • Java (JDK) 8
  • Maven 3.x

Build

From the repository root:

mvn -DskipTests package

This runs the ANTLR generation step and compiles the Java sources.

Run

The entry point is Main.

Run from a file

mvn -DskipTests package exec:java -Dexec.mainClass=Main -Dexec.args="<ImplanFile>"

Pass any file containing a single ImpLan program.

Run from standard input

mvn -DskipTests package exec:java -Dexec.mainClass=Main

Then paste an ImpLan program and finish with an empty line.

ImpLan

  • Types: int, bool, void
  • Declarations:
    • Variables: type id = exp;
    • Functions (supports nesting): type id(type p1, ...) { dec* (stm* exp)? }
  • Statements: assignment, function call, if, while, block { ... }
  • Expressions: arithmetic, comparisons, equality, logical operators, unary -, +, !, and conditional expressions

A program is delimited by outer braces and ends with a final expression whose value is the program result.

Samples

Example programs are available in samples.txt. And one program file in test.implan

Project layout

  • src/main/antlr/ ANTLR grammars for ImpLan and the SVM assembler
  • src/main/java/ Java sources (compiler pipeline, AST, SVM assembler/VM)

About

This project implements a compiler pipeline for a toy language called ImpLan and a corresponding stack-based virtual machine (SVM).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors