https://github.com/rutpiv/conditional-command-parser
Implementing a Lexical and Syntactic Analyzer with First/Follow in Spring Boot
https://github.com/rutpiv/conditional-command-parser
grammar-checker java lexer-parser maven semantic-analysis sintaxis-analyzer spring-boot university-project
Last synced: 4 days ago
JSON representation
Implementing a Lexical and Syntactic Analyzer with First/Follow in Spring Boot
- Host: GitHub
- URL: https://github.com/rutpiv/conditional-command-parser
- Owner: Rutpiv
- License: bsd-3-clause
- Created: 2025-03-26T09:44:35.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-31T05:09:09.000Z (12 months ago)
- Last Synced: 2025-05-31T16:51:22.404Z (12 months ago)
- Topics: grammar-checker, java, lexer-parser, maven, semantic-analysis, sintaxis-analyzer, spring-boot, university-project
- Language: Java
- Homepage:
- Size: 146 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Authors: AUTHORS
Awesome Lists containing this project
README
# ๐ ConditionalCommandParser โ Conditional Command Parsing Utility

_Tokyo Night Theme (Dark & Light Modes)_
## ๐๏ธ Table of Contents
- [โญ Features](#-features)
- [๐ธ Screenshots](#-screenshots)
- [๐๏ธ Technical Implementation](#๏ธ-technical-implementation)
- [โ๏ธ Technologies](#๏ธ-technologies)
- [๐ Getting Started](#-getting-started)
- [๐งช Testing](#-testing)
- [๐ License](#-license)
- [๐ฅ Authors](#-authors)
---
## โญ Features
**A modular conditional command parsing utility with semantic analysis:**
- โ
**Advanced Parsing Engine**
- Implements a Recursive Descent Parser to handle conditional commands, assignments, and expressions with clear grammar structure.
- ๐ **Custom Lexer & Grammar Analysis**
- Robust Lexer for tokenization and type recognition (supporting `float`, `string`, `char`, and `int`).
- First and Follow set calculations to support predictive parsing and error handling.
- **Supports comments** in the input:
- `// line comments`
- `/* block comments */`
- ๐ง **Semantic Analysis**
- Enforces semantic rules such as type consistency in assignments and expressions.
- Symbol table management for identifier tracking and type binding.
- ๐จ **Syntax Tree Visualization**
- TreePrinter utility provides a clear, labeled printout of the abstract syntax tree (AST), including node types and relationships.
- ๐ฅ๏ธ **Modern Web Interface**
- Web controller (ParserController) and a responsive `index.html` interface styled with Tailwind CSS.
- Includes light/dark themes inspired by the TokyoNight palette and a toggle switch for user preference.
- ๐งช **Test-Driven Development**
- Extensive unit tests for Lexer, ParserService, Semantic Analysis, and FirstFollowCalculator ensure correctness and robustness.
---
## ๐ธ Screenshots
### Syntax Tree Visualization

_Visual output from TreePrinter displaying the parsed conditional command tree_
---
## ๐๏ธ Technical Implementation
### Grammar Specification
The parser is built using the following context-free grammar:
```bnf
S โ if ( E ) S else S | id = E
E โ E + T | E - T | T
T โ T * F | T / F | F
F โ ( E ) | id
```
**Note:** In this grammar:
- `id` represents either an **identifier** (e.g., variable names) or a **literal** of supported types: `float`, `string`, `char`, or `int`
- `if`, `else`, and operators (`+`, `-`, `*`, `/`) are terminal symbols
### Project Structure & Component Roles
```bash
src/
โโโ main
โ โโโ java/br/edu/fesa/Conditional_Command_Parser
โ โ โโโ ConditionalCommandParserApplication.java # Main Spring Boot entry point
โ โ โโโ exception
โ โ โ โโโ LexicalException.java # Custom lexical error handling
โ โ โ โโโ SemanticException.java # Custom semantic error handling
โ โ โ โโโ SyntaxException.java # Custom syntax error handling
โ โ โโโ controller
โ โ โ โโโ ParserController.java # REST API endpoint handler
โ โ โโโ model
โ โ โ โโโ Assignment.java # 'id = E' assignment nodes
โ โ โ โโโ BinOp.java # Binary operations (+,-,*,/)
โ โ โ โโโ CharLiteral.java # Char literal node
โ โ โ โโโ FloatLiteral.java # Float literal node
โ โ โ โโโ Identifier.java # ID nodes (variables/numbers)
โ โ โ โโโ IfStatement.java # If-else control structures
โ โ โ โโโ NumberLiteral.java # Numeric literal node
โ โ โ โโโ ParserResponse.java # API response wrapper
โ โ โ โโโ StringLiteral.java # String literal node
โ โ โ โโโ SyntaxNode.java # Base AST interface
โ โ โ โโโ Token.java # Token type/value storage
โ โ โโโ semantic
โ โ โ โโโ Symbol.java # Symbol representation for semantic analysis
โ โ โ โโโ SymbolTable.java # Symbol table for variable scope management
โ โ โโโ service
โ โ โ โโโ ParserService.java # Core parsing logic orchestration
โ โ โโโ utils
โ โ โโโ FirstFollowCalculator.java # Grammar analysis utilities
โ โ โโโ Lexer.java # Source code tokenization
โ โ โโโ RecursiveDescentParser.java # Syntax tree construction
โ โ โโโ SemanticAnalyzer.java # Semantic analysis for type checking
โ โ โโโ TreePrinter.java # AST visualization generator
โ โโโ resources
โ โโโ application.properties # Spring configuration
โ โโโ static
โ โ โโโ styles.css # TokyoNight theme styling
โ โโโ templates
โ โโโ index.html # Web interface template
โโโ test
โโโ java/br/edu/fesa/Conditional_Command_Parser
โโโ ConditionalCommandParserApplicationTests.java
โโโ service
โ โโโ ParserServiceTest.java # Service layer tests (7 tests)
โโโ utils
โ โโโ FirstFollowCalculatorTest.java # Grammar analysis tests (2 tests)
โ โโโ LexerTest.java # Tokenization tests (18 tests)
โ โโโ RecursiveDescentParserTest.java # Recursive descent parser tests (14 tests)
โ โโโ SemanticAnalyzerTest.java # Semantic analysis tests (6 tests)
```
---
## โ๏ธ Technologies
- **Backend**: Spring Boot 3.4.4 + Java 17
- **Frontend**: Thymeleaf + Tailwind CSS
- **Parsing Techniques**: Recursive descent parsing, custom lexer/tokenization, first/follow calculations
- **Build**: Maven 3.9+
- **Testing**: JUnit 5 (47 Total Tests)
---
## ๐ Getting Started
### Prerequisites
- Java Development Kit (JDK) 17
- Maven 3.9+
### Installation
Clone the repository and build the project:
```bash
git clone git@github.com:Rutpiv/Conditional-Command-Parser.git
cd Conditional-Command-Parser
mvn clean install
```
### Running the Application
Start the application:
```bash
mvn spring-boot:run
```
Access the web interface at: ๐ [http://localhost:8080](http://localhost:8080)
---
## ๐งช Testing
**Comprehensive validation coverage:**
```bash
mvn test
```
- โ
**ParserService:** 7 tests ensuring correct parsing logic
- โ
**FirstFollowCalculator:** 2 tests validating grammar analysis
- โ
**Lexer:** 18 tests verifying tokenization accuracy
- โ
**RecursiveDescentParser:** 14 tests for syntax tree generation
- โ
**SemanticAnalyzer:** 6 tests validating type checking and symbol management
---
## ๐ License
Distributed under the **[BSD 3-Clause License](./LICENSE)**.
---
## ๐ฅ Authors
Students from **Engenheiro Salvador Arena College**:
โก๏ธ [Complete Contributors List](./AUTHORS)
---
Built with โฅ by Computer Engineering students
Compilers Course Project โข 2025 Semester