Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

fesa-academic-projects/Conditional-Command-Parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

36 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“š ConditionalCommandParser – Conditional Command Parsing Utility

Tokyo Night Theme Preview Tokyo Night Theme (Dark & Light Modes)

Java Version Maven Version Tests Passed License

πŸ—‚οΈ Table of Contents


⭐ 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

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:

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

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:

git clone git@github.com:Rutpiv/Conditional-Command-Parser.git
cd Conditional-Command-Parser
mvn clean install

Running the Application

Start the application:

mvn spring-boot:run

Access the web interface at: 🌐 http://localhost:8080


πŸ§ͺ Testing

Comprehensive validation coverage:

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.


πŸ‘₯ Authors

Students from Engenheiro Salvador Arena College: ➑️ Complete Contributors List


Built with β™₯ by Computer Engineering students
Compilers Course Project β€’ 2025 Semester