VinayHajare / SyntaxForge

A Parser Generator Framework

Repository from Github https://github.comVinayHajare/SyntaxForgeRepository from Github https://github.comVinayHajare/SyntaxForge

๐Ÿ”  SyntaxForge: A Parser Generator Framework ๐Ÿ”

Project Overview

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.

๐ŸŽฏ Features

  • โœ… 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

๐Ÿ“š Project Structure

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

๐Ÿš€ Getting Started

Prerequisites

  • Java JDK 11 or higher
  • Maven or Gradle (for building)

Installation

# Clone the repository
git clone https://github.com/VinayHajare/SyntaxForge.git
cd SyntaxForge

# Build the project
mvn clean install

Usage

Specifying Grammars

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

Running the LL(1) Parser

java LLParserTest.java --grammar path/to/grammar.txt

Running the LR Parser

java LRParserTest.java --grammar path/to/grammar.txt

๐Ÿ“ Grammar Format

  • Each production must be on a separate line
  • Use ->to separate the left and right sides of a production
  • Use | to separate alternatives
  • Use ฮต or epsilon for the empty string
  • Use # for comments

๐Ÿ”„ Workflow Example

  1. Parse the grammar file
  2. Check and eliminate left recursion and perform left factoring (for LL)
  3. Compute FIRST and FOLLOW sets (for LL)
  4. Build parsing tables
  5. Parse the input string
  6. Generate and display the parse tree

๐Ÿ”ฎ Future Work

  • ๐Ÿงฉ 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

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

๐Ÿ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ“š References

  • Compilers: Principles, Techniques, and Tools (Dragon Book)
  • Modern Compiler Implementation in Java
  • Engineering a Compiler

About

A Parser Generator Framework

License:Apache License 2.0


Languages

Language:Java 100.0%