Skip to content

Latest commit

 

History

History
74 lines (54 loc) · 1.17 KB

File metadata and controls

74 lines (54 loc) · 1.17 KB

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