This repository contains a Python implementation of an LR(0) parser. The LR(0) parser is a type of bottom-up parser for analyzing context-free grammars used in compilers and interpreters.
- Computes the closure of a production
- Handles state transitions with the
goto
function - Generates parsing tables for terminals and non-terminals
- Parses and validates input strings
- Python 3.6 or higher (3.9.12 recommended)
termtables
library for displaying parsing tablescollections
library for counting occurences
-
Clone the repository:
git clone https://github.com/yourusername/LR0-parser.git cd LR0-parser
-
Install required packages:
pip install termtables pip install collections
-
Run the script:
python lr0_parser.py
-
Enter productions: You will be prompted to enter grammar productions one by one. Type
end
when you are done. -
View augmented grammar and states: The script will display the augmented grammar and the generated states.
-
Parsing table: The parsing table will be displayed.
-
Enter the string to be parsed:
Enter the string to be parsed: aabb
-
Parsing result: The script will display whether the string is parsable and provide the parsing table.