Skip to content

VartikaChauhan/C_compiler

Repository files navigation

Simple C Compiler Using Flex, Bison, and C

📝 Overview

This project is a fully functional mini C compiler developed from scratch using:

  • Flex for lexical analysis
  • Bison for syntax parsing
  • C for compiler logic and semantic analysis

It is designed to parse a subset of the C language and includes a full pipeline from tokenization to semantic analysis and AST evaluation.


Features

  • Lexical Analysis using Flex
  • Syntax Parsing with Bison (LALR parser)
  • Abstract Syntax Tree (AST) construction and traversal
  • Symbol Table Management for scoped variables and function identifiers
  • Type Checking for expressions, assignments, and operations
  • Undeclared Variable Detection
  • Function Declaration & Call Validation
  • Error Handling with informative messages
  • AST Evaluation & Visualization Support

Requirements

Install the following dependencies:


For Ubuntu/Debian-based systems:

sudo apt update
sudo apt install flex bison gcc build-essential git -y

Build the Compiler

make

Run the Compiler

./compiler test.c

This will parse test.c and perform lexical, syntax, and semantic analysis.


.gitignore — Ignored Files

This project uses a .gitignore file to exclude automatically generated files from version control, ensuring a clean and portable codebase. Ignored Binary and Generated Files:

  • compiler — The compiled output binary.
  • *.o — Object files generated during compilation.
  • lex.yy.c — File generated by Flex.
  • parser.tab.c, parser.tab.h — Files generated by Bison.

These files are regenerated automatically when you run the make command, so they do not need to be tracked in the repository.

About

A simple C compiler made using Flex, Bison, and GCC

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published