SyntaxForge is a comprehensive parser generator framework that implements various parsing techniques used in compiler design. The project serves as both an educational tool for understanding parsing algorithms and a practical utility for building parsers.
- โ Grammar specification through simple text files
- โ
LL(1) Parser implementation
- Left recursion elimination
- Left factoring
- FIRST and FOLLOW set computation
- Parsing table construction
- Predictive parsing
- โ
LR(0)/SLR Parser implementation
- Items and states generation
- ACTION and GOTO table construction
- Shift-reduce parsing
- โ Parse tree visualization
- โ Detailed error reporting
src/
โโโ utils/ # Common utilities shared between parsers
โ โโโ Grammar.java # Grammar representation
โ โโโ Production.java # Production rules
โ โโโ Symbol.java # Grammar symbols (terminals/non-terminals)
โ โโโ GrammarReader.java # File parser for grammar specifications
โ โโโ GrammarTest.java # Grammar Testing class
โ
โโโ ll/ # LL(1) parser implementation
โ โโโ LLParser.java # Main LL parser class
โ โโโ FirstFollowCalculator.java # FIRST/FOLLOW set computation
โ โโโ LLParserTest.java # LLParser testing class
โ โโโ ParsingTable.java # LL(1) parsing table
โ
โโโ lr/ # LR parser implementation
โโโ LRParser.java # Main LR parser class
โโโ Item.java # LR(0) items
โโโ ItemSet.java # Set of Items
โโโ LRParsingTable.java # LR parsing table
โโโ CanonicalCollections.java # Collection of canonical items
โโโ LRParserTestTable.java # LLParser Testing class
- Java JDK 11 or higher
- Maven or Gradle (for building)
# Clone the repository
git clone https://github.com/VinayHajare/SyntaxForge.git
cd SyntaxForge
# Build the project
mvn clean install
Create a grammar file with production rules:
# Example grammar file: arithmetic.txt
E -> T E'
E' -> + T E' | ฮต
T -> F T'
T' -> * F T' | ฮต
F -> ( E ) | id
java LLParserTest.java --grammar path/to/grammar.txt
java LRParserTest.java --grammar path/to/grammar.txt
- Each production must be on a separate line
- Use
->
to separate the left and right sides of a production - Use
|
to separate alternatives - Use
ฮต
orepsilon
for the empty string - Use
#
for comments
- Parse the grammar file
- Check and eliminate left recursion and perform left factoring (for LL)
- Compute FIRST and FOLLOW sets (for LL)
- Build parsing tables
- Parse the input string
- Generate and display the parse tree
- ๐งฉ Operator precedence parser implementation
- ๐ง LALR(1) parser implementation
- ๐ Automatic syntax diagram generation
- ๐ Recovery strategies for syntax errors
- ๐ฅ๏ธ Integration with lexical analyzer to form a complete front-end
- ๐งช Unit testing framework for grammar validation
- ๐ฑ GUI for interactive parse tree visualization
- ๐ฆ AST (Abstract Syntax Tree) construction
- ๐ Plugin system for custom semantic actions
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Compilers: Principles, Techniques, and Tools (Dragon Book)
- Modern Compiler Implementation in Java
- Engineering a Compiler