Skip to content

Chinmykumar/Intermediate-Code-Generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ThreeAddrGen

Intermediate Code Generator for C-like Programs

An educational compiler that performs lexical analysis, syntax analysis, semantic validation, and three-address code generation for a C-like language.

Architecture

ThreeAddrGen/
├── backend/           # Python Flask + PLY compiler
│   ├── app.py         # Flask API server
│   └── compiler/      # Compiler pipeline modules
│       ├── lexer.py       # Tokenizer (PLY)
│       ├── parser.py      # LALR parser (PLY yacc)
│       ├── ast_nodes.py   # AST node definitions
│       ├── symbol_table.py # Symbol table with scoping
│       ├── semantic.py    # Semantic analyzer
│       ├── tac_generator.py # Three-address code gen
│       └── postfix.py     # Postfix notation gen
├── frontend/          # React + TypeScript + Vite
│   └── src/
│       ├── components/    # UI components
│       ├── hooks/         # useCompiler hook
│       └── utils/         # API client
└── start.sh           # Launch script

Quick Start

# 1. Set up Python virtual environment
cd ThreeAddrGen
python3 -m venv .venv
source .venv/bin/activate
pip install -r backend/requirements.txt

# 2. Install frontend dependencies
cd frontend && npm install && cd ..

# 3. Start both servers
./start.sh

Open http://localhost:5173 in your browser.

Compiler Pipeline

Phase Description
Lexical Analysis Tokenizes source code into keywords, identifiers, numbers, operators, delimiters
Syntax Analysis Builds AST using LALR(1) parsing (PLY yacc)
Semantic Validation Checks for undefined variables, redeclarations, type mismatches
TAC Generation Produces three-address code with proper label/goto control flow, short-circuit boolean evaluation, and backpatching
Postfix Generation Converts AST to postfix notation

Language Features

  • Types: int, float, char, bool, void
  • Control flow: if/else, while, for
  • Operators: arithmetic, relational, logical (&&, ||, !)
  • Functions with parameters
  • Nested blocks with scoped variables
  • Comments: // and /* */
  • Short-circuit boolean evaluation in TAC

API Endpoints

  • POST /api/compile — Compile source code, returns JSON with tokens, AST, TAC, symbols, errors
  • GET /api/samples — Returns sample C-like programs

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors