Skip to content

Rapter-cd/Syntax-Error-Recovery-Parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Universal C++ Syntax Error Recovery Parser

A full-stack web application that can parse ANY C++ code with intelligent error recovery capabilities. Built with Flex & Bison for the parser, Node.js for the backend, and a modern web frontend.

πŸ”₯ NEW: Universal C++ Support

This parser can now handle any C++ construct including:

  • Classes, templates, namespaces
  • Complex inheritance, virtual functions
  • STL containers, smart pointers
  • Modern C++ features (auto, lambdas, etc.)
  • Preprocessor directives
  • And much more!

πŸš€ Features

  • Intelligent Error Recovery: Parser continues after encountering syntax errors
  • Real-time Parsing: Web-based interface with instant feedback
  • Comprehensive Error Reporting: Detailed error messages with line numbers
  • Modern UI: Dark-themed interface with syntax highlighting
  • Sample Code Examples: Pre-built examples to test error recovery

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚    β”‚   Backend       β”‚    β”‚   C++ Parser    β”‚
β”‚   (Web GUI)     │───▢│   (Node.js)     │───▢│   (Flex/Bison)  β”‚
β”‚                 β”‚    β”‚                 β”‚    β”‚                 β”‚
β”‚ β€’ HTML/CSS/JS   β”‚    β”‚ β€’ Express.js    β”‚    β”‚ β€’ Lexical       β”‚
β”‚ β€’ Ace Editor    β”‚    β”‚ β€’ File I/O      β”‚    β”‚   Analysis      β”‚
β”‚ β€’ TailwindCSS   β”‚    β”‚ β€’ Process Exec  β”‚    β”‚ β€’ Error Recoveryβ”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“‹ Prerequisites

For the C++ Parser:

  • Flex (Fast Lexical Analyzer Generator)
  • Bison (GNU Parser Generator)
  • GCC/G++ compiler with C++11 support
  • Make utility

For the Backend:

  • Node.js (version 14 or higher)
  • npm (Node Package Manager)

πŸš€ Quick Start (Recommended)

Option 1: One-Click Startup

Double-click start.bat or run:

.\start.ps1

This script will:

  • βœ… Check all dependencies
  • βœ… Install Node.js packages if needed
  • βœ… Compile the parser if needed
  • βœ… Start the web server automatically
  • βœ… Open http://localhost:3000 in your browser

Option 2: VS Code Integration

  1. Open this folder in VS Code
  2. Press Ctrl+Shift+P
  3. Type "Tasks: Run Task"
  4. Select "Start C++ Parser Server"

πŸ”§ Manual Installation & Setup

Step 1: Install System Dependencies

On Windows:

  1. Install MSYS2 or MinGW-w64
  2. Install required tools:
    # Using MSYS2
    pacman -S mingw-w64-x86_64-gcc
    pacman -S mingw-w64-x86_64-flex
    pacman -S mingw-w64-x86_64-bison
    pacman -S make

On Ubuntu/Debian:

sudo apt update
sudo apt install flex bison gcc g++ make nodejs npm

On macOS:

# Using Homebrew
brew install flex bison gcc make node npm

Step 2: Compile the C++ Parser

Navigate to the parser directory and compile:

cd WebParserProject/parser
make

This will:

  • Generate parser.tab.c and parser.tab.h from parser.y
  • Generate lex.yy.c from lexer.l
  • Compile all files into the parser executable

Windows users: If compilation fails, try:

make clean-win  # Clean previous builds
make            # Rebuild

Step 3: Install Node.js Dependencies

Navigate to the backend directory and install dependencies:

cd ../backend
npm install

Step 4: Start the Application

From the backend directory, start the server:

npm start

The application will be available at: http://localhost:3000

🎯 Usage

Web Interface

  1. Open your browser to http://localhost:3000
  2. Type or paste C-like code in the editor
  3. Click "Run Parser" or use Ctrl+Enter
  4. View parsing results and error recovery in the output console

Sample Code Examples

Click the sample buttons to load different examples:

  • βœ“ Valid Code: Syntactically correct program
  • βœ— With Errors: Code with missing semicolons and braces
  • ⚑ Complex: Nested structures with multiple errors

Keyboard Shortcuts

  • Ctrl+Enter (or Cmd+Enter on Mac): Run parser
  • Ctrl+L (or Cmd+L on Mac): Clear output

πŸ“ Supported C-like Language Features

Keywords

  • int: Variable declaration
  • if, else: Conditional statements
  • print: Output statement

Operators

  • =: Assignment
  • >: Greater than comparison

Syntax Elements

  • ;: Statement terminator
  • (): Parentheses for conditions and function calls
  • {}: Braces for code blocks

Example Valid Code:

int x = 5;
int y = 10;
if (x > 3) {
    print(x);
    print(y);
}

πŸ› οΈ Error Recovery Features

The parser can recover from common syntax errors:

  1. Missing Semicolons: Continues parsing after reporting the error
  2. Missing Parentheses: Handles missing ( or ) in conditions
  3. Missing Braces: Recovers from missing { or } in blocks
  4. Invalid Statements: Skips invalid syntax until next semicolon

πŸ—‚οΈ Project Structure

WebParserProject/
β”œβ”€β”€ parser/                 # C++ Parser (Flex & Bison)
β”‚   β”œβ”€β”€ lexer.l            # Flex lexer definition
β”‚   β”œβ”€β”€ parser.y           # Bison parser with error recovery
β”‚   β”œβ”€β”€ parser_utils.h     # Utility functions header
β”‚   β”œβ”€β”€ parser_utils.cpp   # Utility functions implementation
β”‚   └── Makefile          # Build configuration
β”‚
β”œβ”€β”€ backend/               # Node.js Backend
β”‚   β”œβ”€β”€ server.js         # Express server
β”‚   └── package.json      # Node dependencies
β”‚
β”œβ”€β”€ public/                # Web Frontend
β”‚   β”œβ”€β”€ index.html        # Main HTML page
β”‚   └── script.js         # JavaScript client logic
β”‚
└── README.md             # This file

πŸ› Troubleshooting

Parser Compilation Issues

  • "flex: command not found": Install Flex
  • "bison: command not found": Install Bison
  • Linker errors: Install development libraries (build-essential on Ubuntu)

Runtime Issues

  • "Parser executable not found": Ensure make completed successfully
  • "Cannot open file": Check file permissions
  • Server connection errors: Verify Node.js server is running on port 3000

Windows-Specific Issues

  • Use forward slashes / in paths or escape backslashes properly
  • Ensure MSYS2/MinGW is in your PATH
  • Use make clean-win instead of make clean

πŸ”„ Development Workflow

Making Changes to the Parser:

  1. Edit .l or .y files
  2. Run make clean then make
  3. Restart the Node.js server if needed

Making Changes to the Frontend:

  1. Edit index.html or script.js
  2. Refresh the browser (no server restart needed)

Making Changes to the Backend:

  1. Edit server.js
  2. Restart the server: Ctrl+C then npm start

πŸ“Š Output Format

The parser provides structured output with different message types:

  • [Info]: General parsing information
  • [Success]: Successful operations
  • [Error on Line X]: Syntax errors with line numbers
  • [Warning]: Non-critical issues
  • [Fatal Error]: Unrecoverable errors

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test with various code samples
  5. Submit a pull request

πŸ“„ License

This project is released under the MIT License. Feel free to use, modify, and distribute as needed.

πŸ™ Acknowledgments

  • Flex and Bison for powerful parsing tools
  • Ace Editor for the code editor component
  • TailwindCSS for modern styling
  • Express.js for the backend framework

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published