This project is a Multi-Language Code Parser built using Tree-sitter, capable of parsing and visualizing code from multiple programming languages. It features an intuitive web-based UI powered by Flask, automatic language detection, and generates both text-based and visual Abstract Syntax Trees (AST).
Supported Languages:
- C
- C++
- Java
- JavaScript
- Python
The system automatically detects the language based on file extension, parses the code into an Abstract Syntax Tree (AST), and generates both a text-based parse tree and a visual diagram.
- β Automatic Language Detection - Identifies language by file extension
- β Multi-Language Parsing - Supports 5 programming languages
- β AST Generation - Uses Tree-sitter for accurate parse trees
- β Visual Representation - Generates beautiful parse tree diagrams using Graphviz
- β Web-Based Interface - Easy-to-use Flask UI for file uploads
- β
Dual Output - Text (
tree.txt) and visual (tree.png) parse trees
lpccProj/
β
βββ app.py # Flask backend & web server
βββ parser.sh # Core parsing script (multi-language dispatcher)
βββ visualize.py # Converts AST β Graphviz output
β
βββ grammers/ # Language grammars (Tree-sitter parsers)
β βββ tree-sitter-c/ # C language parser
β βββ tree-sitter-cpp/ # C++ language parser
β βββ tree-sitter-java/ # Java language parser
β βββ tree-sitter-javascript/ # JavaScript parser
β βββ tree-sitter-python/ # Python language parser
β
βββ samples/ # Sample code files for testing
βββ uploads/ # Directory for uploaded files
βββ templates/ # HTML templates
β βββ index.html # Web UI
βββ static/ # Static assets
βββ tree.txt # Output: Raw parse tree
βββ tree.dot # Output: Graphviz format
βββ tree.png # Output: Visual parse tree diagram
β
βββ README.md # This file
User uploads code file
β
App extracts file extension
β
Parser selects appropriate Tree-sitter grammar
β
Tree-sitter generates Parse Tree
β
tree.txt created (raw output)
β
visualize.py converts to tree.dot (Graphviz format)
β
Graphviz renders tree.png
β
Web UI displays results
Linux / WSL Environment:
sudo apt update
sudo apt install -y nodejs npm python3 python3-venv graphviz build-essentialKey Dependencies:
- Tree-sitter - Parser generator framework
- Graphviz - Graph visualization tool
- Flask - Python web framework
- Node.js & npm - For building Tree-sitter parsers
git clone <repository-url>
cd lpccProjpython3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install flaskNavigate to each grammar directory and build:
cd grammers/tree-sitter-c
npm install
npm run build
cd ../..Repeat for other language parsers if needed.
Test the parser with a sample file:
echo "samples/test.c" | ./parser.shYou should see tree.txt and tree.png generated in the project root.
Parse a single file:
echo "path/to/your/code.py" | ./parser.shThis will generate:
tree.txt- Text representation of the parse treetree.dot- Graphviz formattree.png- Visual diagram
| Extension | Language |
|---|---|
.c |
C |
.cpp |
C++ |
.java |
Java |
.js |
JavaScript |
.py |
Python |
python app.pyServer runs at: http://localhost:5000
- Open
http://localhost:5000in your browser - Click "Choose File" and select a code file
- Click "Submit"
- View the generated parse tree diagram
def greet(name):
return f"Hello, {name}!"module
function_definition
name: greet
parameters
identifier: name
block
return_statement
f_string
The system generates a Graphviz diagram showing the hierarchical structure of your code.
chmod +x parser.sh# Ubuntu/Debian
sudo apt install graphviz
# macOS
brew install graphvizsource venv/bin/activate
pip install flaskEnsure you have Node.js 14+ and npm installed:
node --version
npm --versionWe welcome contributions! Here's how to get involved:
- Create a feature branch:
git checkout -b feature/your-feature - Make your changes and commit:
git commit -am 'Add new feature' - Push to the branch:
git push origin feature/your-feature - Submit a Pull Request
- Add support for new languages
- Improve the web UI design
- Optimize parsing performance
- Add more visualization options
- Enhance error messages
- Use clear, descriptive variable names
- Add comments for complex logic
- Follow Python PEP 8 conventions for Python files
- Test changes with the provided sample files
This project is provided as-is for educational and development purposes. Please refer to the LICENSE file for full details.
For questions, issues, or suggestions:
- Check Existing Issues - Browse GitHub Issues for solutions
- Create a New Issue - Report bugs or request features
- Discussion Forum - Use Discussions tab for general questions
This project demonstrates:
- Compiler Construction - AST generation and parsing
- Language Processing - Multi-language support
- Web Development - Flask backend integration
- Graph Visualization - Graphviz output generation
- Shell Scripting - Dynamic language detection
Perfect for students learning about parsing, compilers, or code analysis tools!
- Support for additional languages (Go, Rust, TypeScript)
- Interactive tree visualization
- Symbol table generation
- Code metrics analysis
- Docker containerization
- REST API endpoints
Made with β€οΈ for code visualization enthusiasts
Verify installations:
node -v
npm -v
python3 --version
dot -Vgit clone <your-repo-url>
cd lpccProjsudo npm install -g tree-sitter-cliVerify:
tree-sitter --versionpython3 -m venv venv
source venv/bin/activatepip install flask --break-system-packagespython app.pyOutput:
Running on http://127.0.0.1:5000
Go to:
http://127.0.0.1:5000
Upload any file:
.c.cpp.java.js.py
- Raw AST in text format
- Shows hierarchical structure of code
Example:
(function_definition
(for_statement
(if_statement
- Visual representation of AST
- Generated using Graphviz
- Intermediate graph format
- Used to generate PNG
Handles:
- Language detection
- Grammar selection
- Parsing execution
- Converts text AST β graph
- Uses Graphviz
- Flask backend
- Handles file upload
- Triggers parsing pipeline
| Language | Extension |
|---|---|
| C | .c |
| C++ | .cpp |
| Java | .java |
| JavaScript | .js |
| Python | .py |
sudo npm install -g tree-sitter-clinode -vInstall if missing.
pip install flask --break-system-packagesUse Windows Explorer:
explorer.exe tree.pngYou can explain like this:
"This project uses Tree-sitter to parse multiple programming languages. It dynamically selects grammar based on file extension, generates an abstract syntax tree, and visualizes it using Graphviz for better understanding of code structure."
- Interactive tree visualization
- Syntax highlighting in UI
- Real-time parsing
- Support for more languages
This project demonstrates:
- Compiler design concepts
- Multi-language parsing
- AST visualization
- Real-world tool usage