Skip to content

A Mini-Python compiler project for the PCL1 module, implementing a lexer, a recursive-descent parser, and an abstract syntax tree (AST) without using generator tools.

Notifications You must be signed in to change notification settings

Emine-Bassoum/MiniPython-Compiler-Project

Repository files navigation

PCL1 Compiler Project

Contributors

  • BRIBER Kenza
  • GUEMIMI Marouane
  • Bassoum Mohamed-Emine
  • HISLEUR Guillaume

Project Overview

This project, part of the PCL1 module, focuses on designing and implementing a compiler. It consists of two main phases: PCL1 (October to mid-January) and PCL2.

The PCL1 phase is dedicated to developing:

  1. A lexical analyzer to identify lexical units.
  2. A syntax analyzer using recursive functions.
  3. An abstract syntax tree (AST) to represent parsed structures.

Key Constraint: No generator tools are allowed during the development of lexical and syntax analyzers.


Tasks

  1. Lexical Analysis:

    • Implement an automaton to recognize lexical units.
    • Ensure correct tokenization of the input source code.
  2. Syntax Analysis:

    • Develop a recursive-descent syntax analyzer.
    • Perform validation of grammar rules.
  3. Abstract Syntax Tree (AST):

    • Construct an AST to visually and structurally represent syntax analysis results.

File Descriptions

File Description
main.py Entry point for the compiler.
tester.py Testing framework for compiler validation.
parser.py Syntax analysis functions and terminal definitions.
ll1_table.py LL(1) parsing table used for syntactic rules.
Lexer.py Implementation of the lexer.
Lib_lex.py Auxiliary functions for the lexer.
syntaxic_tree_builder.py Functions for building the syntax tree.
AST.py Functions to construct and manipulate the abstract syntax tree.

Usage

Installing necessary library

execute this command:

pip install -r ./requirements.txt

Running the Compiler

To execute the mini compiler:

python ./main.py <input_file>

Replace <input_file> with the path to the file you want to compile.

exemple:

python ./main.py ./tests/test1.py

Running Tests

To generate ASTs for all test cases and corresponding log files (./AST and ./log directories):

python tester.py

About

A Mini-Python compiler project for the PCL1 module, implementing a lexer, a recursive-descent parser, and an abstract syntax tree (AST) without using generator tools.

Resources

Stars

Watchers

Forks

Languages