Skip to content

A simple compiler for a Python-like language ("MiniPy") using Flex and Bison. Includes lexical analysis, parsing, symbol tables, and intermediate code generation.

Notifications You must be signed in to change notification settings

b-fatma/minipy-compiler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compiler Construction Project

This project is a simple compiler for a subset of the Python language ("MiniPy"), built using Flex (lexical analyzer) and Bison (parser generator). It demonstrates key concepts in compiler design, including lexical analysis, syntax analysis, symbol tables, and intermediate code generation. The key challenge is handling indentation.

Files

  • projet.l — Flex specification for lexical analysis.
  • projet.y — Bison specification for syntax analysis and parsing.
  • TS.h — Symbol table implementation.
  • quad.h — Quadruple/intermediate code representation.
  • pile.h — Stack utilities for parsing or code generation.
  • exemple.txt — Example MiniPy source code for testing.
  • minipy.bat — Batch file for building or running the project (Windows).
  • readme.md — Project documentation.

Requirements

  • Flex
  • Bison
  • GCC (or compatible C compiler)

Build Instructions

  1. Generate the lexer and parser:
    flex projet.l
    bison -d projet.y
    gcc -o minipy lex.yy.c projet.tab.c -lfl
  2. Run the compiler on an example file:
    ./minipy exemple.txt

Features

  • Tokenizes and parses a subset of Python syntax.
  • Builds a symbol table for variables and functions.
  • Generates intermediate code using quadruples.
  • Demonstrates basic error handling.

Usage

Edit exemple.txt with your MiniPy code and run the compiler as shown above. The output will display parsing results and intermediate code.

License

For educational use.

About

A simple compiler for a Python-like language ("MiniPy") using Flex and Bison. Includes lexical analysis, parsing, symbol tables, and intermediate code generation.

Topics

Resources

Stars

Watchers

Forks