Below is a screenshot of our Mini Python Compiler interface. On the left side, you can see an example of Mini Python code, and on the right side, the corresponding Abstract Syntax Tree (AST) generated by our compiler:
The Mini Python Compiler is a Java-based compiler project focusing on:
- Lexical and Syntactic Analysis: We tokenize Mini Python code and build a parse tree.
- Abstract Syntax Tree (AST) Construction: We transform the parse tree into an AST suitable for further processing.
This compiler demonstrates how Mini Python fragments can be parsed and analyzed. We do not rely on extra Java dependencies.
However, Graphviz must be installed on your system for generating the graphical representation of the AST.
- Lucine GIRAUD
- Lina LEKBOURI
- Julien MARLAND
- Hugo WERCK
- Straightforward Setup: Managed via a Makefile, no special Java libraries needed.
- Interactive UI: Utilizes Java's built-in
HttpServer
to serve an HTML interface for viewing the source and AST. - Graphical AST: Automatically generated using Graphviz.
- Cross-platform: Works on Linux, macOS, and Windows.
- AST Generation: Displays a real-time visualization of the parsed AST via Graphviz.
- Error Reporting: Helpful syntax error messages for debugging.
- Extensible: Easily add new language features or optimizations.
- Java (any reasonably recent version should work).
- Graphviz software installed on your system :
pip install graphviz
Clone the repository:
git clone [URL of project]
cd mini-python-compiler
Ensure that the prerequisites are met, particularly that Java and Graphviz are properly installed.
A Makefile
is provided to simplify compilation, execution, and cleanup. The primary targets are run
and clean
.
- Compile the project:
make compile
- Execute the compiler:
make execute
- Build and run the compiler:
make run
- Clean the build artifacts:
make clean
To compile and run the compiler along with the web interface, simply execute: make
This command will:
- Compile the Java source code.
- Execute the
Main
class, which starts an HTTP server locally (by default on http://localhost:8080/).
Open your web browser and navigate to the address above to see the interface:
- On the left: A sample Mini Python code snippet.
- On the right: The automatically generated AST or a list of the errors.
Although the primary usage is via the HTML interface, you can adapt the project to run lexical and syntax analysis in a purely command-line manner by modifying the Java classes and bypassing the HTTP server calls. Currently, the recommended (and simplest) approach is to use the provided Makefile
targets to build and run the project.
Within the HTML interface, you’ll find various test scripts (Arbres, exemples d'erreurs etc.):
- Arbre 1: Demonstrates the base of the langage with list initialization, arithmetic, and if/else, loop...
- Arbre 2: Showcases a simpler exemple.
- Erreurs Syntaxiques 3 and 4: Additional usage scenarios with multiple syntax errors.
- Erreurs Lexicales: Showcases most of the lexical errors.
You can quickly modify the code snippet on the left pane and observe the updated AST or errors on the right.
In-depth details of the operation of the compiler are documented in the report located at docs/gestion_de_projet/Rapport.pdf
, as well as the meeting reports in CR_reunions.pdf
.
- Graphviz for the AST visualization.
- Java's HttpServer for the lightweight web server integration.
- Special thanks to our professors, peers, and any external libraries that made this project possible.