This project is a Lexer and Parser built for a custom language called TinyPie. It provides a graphical interface using tkinter to tokenize and parse input code, displaying the results and parse trees in real-time. The system follows a simplified grammar and uses anytree to visualize parse trees.
- Lexical Analysis: Tokenizes input code into keywords, identifiers, operators, separators, and literals.
- Syntax Parsing: Builds and visualizes parse trees based on predefined grammar.
- Real-time Processing: Processes input line-by-line with on-screen updates.
- Tree Visualization: Displays the generated parse tree for each line of code.
The project supports the following simplified grammar:
- Mathematical Expressions:
math_exp -> key id = math math -> multi + multi multi -> float * multi | int * multi | float | int - Conditional Statements:
if_exp -> if(comparison_exp): comparison_exp -> id > id - Print Statements:
print_exp -> print("str_literal")
- Clone the repository:
git clone https://github.com/jacobalmon/Lexer-Parser-Project.git
- Install the required Python packages:
pip install tkinter anytree
- Run the application:
python source.py
- Enter source code in the Source Code text box.
- Click Next Line to process each line and view tokens.
- View the generated parse tree in the Tree Visualization section.
- Click EXIT to close the application.
- Python 3.x
- tkinter: For the GUI interface.
- anytree: For parse tree visualization.
- re: For regular expression-based tokenization.
No special configuration is needed. You can modify the grammar or tokenization logic by editing the cutOneLineTokens function and parser methods.
Hannah Gonzalez
Natalie Pedroza