Skip to content

Ashus222/mini-compiler-cpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

Mini Compiler Frontend (C++)

Overview

This project implements a mini compiler frontend in C++ that performs lexical analysis, parsing, AST construction, optimization, and intermediate code generation for arithmetic expressions.

Features

  • Lexical Analyzer (Tokenizer) using finite automata concepts
  • Recursive Descent Parser for syntax analysis
  • Abstract Syntax Tree (AST) construction
  • Symbol Table for variable handling
  • Multi-statement program support
  • Constant Folding optimization
  • Intermediate Representation (IR) generation (PTX-style)
  • Support for integer and floating-point expressions

Example

Input

x = 5.5;
y = x * 2;
x + y;

Output

IR:
MOV x, 5.5
MUL t0, x, 2
MOV y, t0
ADD t1, x, y

Result:
5.5
11
16.5

Compiler Pipeline

Input → Lexer → Parser → AST → Optimization → IR → Evaluation

Future Scope

  • Semantic Analysis (Type Checking)
  • Dead Code Elimination
  • Function Support
  • Advanced IR (register allocation)

Tech Stack

  • C++
  • Data Structures (Trees, Maps)
  • Compiler Design Concepts

How to Run

g++ main.cpp -o compiler
./compiler

Then enter:

x = 5.5;
y = x * 2;
x + y;
run

About

This project implements a mini compiler frontend in C++ that performs lexical analysis, parsing, AST construction, optimization, and intermediate code generation for arithmetic expressions.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages