Skip to content

A project-based compiler implementing lexical analysis, parsing, AST construction, and semantic checking with error reporting and observability.

Notifications You must be signed in to change notification settings

naforoutan/compiler-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Compiler Project

Project Scope Notice

This project implements only the frontend of a compiler.

The original plan included a second phase focused on optimization and backend development. However, due to the digital blackout in Iran in 2026, development of the second phase was canceled and could not be completed. As a result, the project was finalized at the frontend stage.

The existing implementation remains complete and functional within its intended scope.


Overview

This compiler frontend includes the core components required to analyze and validate source programs, from lexical analysis through semantic checking. It is designed with a clear architecture and strong observability to support debugging, analysis, and future extensibility.


Features

  • Lexical analysis with line and column tracking\
  • Syntax analysis and AST construction\
  • Visitor-based AST design\
  • Semantic analysis (type checking, symbol validation, initialization checks)\
  • Detailed error reporting with precise source locations\
  • Execution tracing and observability support

Project Structure

.
├── code
│   ├── AST.h
│   ├── CodeGen.cpp
│   ├── CodeGen.h
│   ├── error.cpp
│   ├── error.h
│   ├── lexer.cpp
│   ├── lexer.h
│   ├── main.cpp
│   ├── Makefile
│   ├── observability.cpp
│   ├── observability.h
│   ├── parser.cpp
│   ├── parser.h
│   ├── semantic.cpp
│   ├── semantic.h
│   └── tests
│       ├── example.src
│       └── input.src
└── README.md

How to Build and Run

1. Prepare Your Source Code

Write your program in a .src file, following the same syntax as the examples in:

code/tests/

You may copy or modify:

code/tests/input.src

2. Build the Compiler

From the code directory, run:

make

This builds the compiler executable:

mycompiler

3. Run the Compiler

To compile and analyze a source file:

./mycompiler tests/input.src

This runs: - lexical analysis\

  • parsing\
  • semantic analysis\
  • frontend validation

and prints any errors with precise source locations.


4. Run with Observability (Optional)

To generate detailed observability and execution reports:

./mycompiler tests/input.src --observability --output-dir=./obs_output 2>&1

This enables internal tracing and writes observability data to ./obs_output.


TL;DR

make
./mycompiler tests/input.src
./mycompiler tests/input.src --observability --output-dir=./obs_output 2>&1

Status

  • Frontend: Complete\
  • Optimization: Not implemented\
  • Backend: Not implemented

About

A project-based compiler implementing lexical analysis, parsing, AST construction, and semantic checking with error reporting and observability.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •