maryamfatima25/pascal-mini-compiler
Pascal Mini Compiler
A fully integrated compiler for a custom Pascal-like language, featuring a Lexical Analyzer, Semantic Analyzer, Recursive Descent Parser (AST builder), Predictive LL(1) Parser, and a Canonical LR(1) Parser.
The project also includes a rich, web-based UI Dashboard to visualize the pipeline, traces, abstract syntax trees, and error handling.
Requirements
Backend / C++ Compiler
g++(Compiler with C++17 support)make(for building the project)- Linux / WSL (Recommended for standard building)
Frontend / Dashboard
python3(for running the local web server)
1. Building the Compiler
To build the compiler executable, open your terminal (e.g., WSL or Linux shell), navigate to this project folder, and run:
makeThis will compile the src/*.cpp files and generate an executable named mini_compiler.
To clean the compiled binaries:
make clean2. Running the Compiler (Terminal / Command Line)
Once compiled, you can run the compiler against any Pascal source file.
Basic Run:
./mini_compiler test/valid_nested.pascalRun Multiple Files:
./mini_compiler test/valid_nested.pascal test/duplicate_same_scope.pascalRun with LR Parser trace enabled: The LR parser trace can be very long. To enable it alongside the default parsers, use the --with-lr flag:
./mini_compiler --with-lr test/valid_nested.pascalGenerate Documentation (Grammar, Tables, etc.):
./mini_compiler --dump-docsThis will generate first_follow.txt, ll1_table.txt, lr_table.txt, and grammar_bnf.txt in the docs/ folder.
3. Running the Dashboard (Web UI)
The project comes with a beautiful web-based interface that allows you to write custom code or load test files, and view the entire compiler pipeline trace, visual AST trees, and semantic symbol table dumps.
To launch the dashboard:
- Open a terminal in the project root directory.
- Navigate to the
ui/directory:
cd ui- Run the Python server:
python3 server.py- Open your web browser and go to: http://localhost:7860
From the dashboard, you can click "Run sample" or write code in the editor and click "Run custom". Explore the Trace, AST Tree, Final Results, and Docs tabs.
