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.
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!
- 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
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β 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β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
- Flex (Fast Lexical Analyzer Generator)
- Bison (GNU Parser Generator)
- GCC/G++ compiler with C++11 support
- Make utility
- Node.js (version 14 or higher)
- npm (Node Package Manager)
Double-click start.bat or run:
.\start.ps1This 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
- Open this folder in VS Code
- Press
Ctrl+Shift+P - Type "Tasks: Run Task"
- Select "Start C++ Parser Server"
- Install MSYS2 or MinGW-w64
- 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
sudo apt update
sudo apt install flex bison gcc g++ make nodejs npm# Using Homebrew
brew install flex bison gcc make node npmNavigate to the parser directory and compile:
cd WebParserProject/parser
makeThis will:
- Generate
parser.tab.candparser.tab.hfromparser.y - Generate
lex.yy.cfromlexer.l - Compile all files into the
parserexecutable
Windows users: If compilation fails, try:
make clean-win # Clean previous builds
make # RebuildNavigate to the backend directory and install dependencies:
cd ../backend
npm installFrom the backend directory, start the server:
npm startThe application will be available at: http://localhost:3000
- Open your browser to
http://localhost:3000 - Type or paste C-like code in the editor
- Click "Run Parser" or use
Ctrl+Enter - View parsing results and error recovery in the output console
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
Ctrl+Enter(orCmd+Enteron Mac): Run parserCtrl+L(orCmd+Lon Mac): Clear output
int: Variable declarationif,else: Conditional statementsprint: Output statement
=: Assignment>: Greater than comparison
;: Statement terminator(): Parentheses for conditions and function calls{}: Braces for code blocks
int x = 5;
int y = 10;
if (x > 3) {
print(x);
print(y);
}The parser can recover from common syntax errors:
- Missing Semicolons: Continues parsing after reporting the error
- Missing Parentheses: Handles missing
(or)in conditions - Missing Braces: Recovers from missing
{or}in blocks - Invalid Statements: Skips invalid syntax until next semicolon
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
- "flex: command not found": Install Flex
- "bison: command not found": Install Bison
- Linker errors: Install development libraries (
build-essentialon Ubuntu)
- "Parser executable not found": Ensure
makecompleted successfully - "Cannot open file": Check file permissions
- Server connection errors: Verify Node.js server is running on port 3000
- Use forward slashes
/in paths or escape backslashes properly - Ensure MSYS2/MinGW is in your PATH
- Use
make clean-wininstead ofmake clean
- Edit
.lor.yfiles - Run
make cleanthenmake - Restart the Node.js server if needed
- Edit
index.htmlorscript.js - Refresh the browser (no server restart needed)
- Edit
server.js - Restart the server:
Ctrl+Cthennpm start
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
- Fork the repository
- Create a feature branch
- Make your changes
- Test with various code samples
- Submit a pull request
This project is released under the MIT License. Feel free to use, modify, and distribute as needed.
- Flex and Bison for powerful parsing tools
- Ace Editor for the code editor component
- TailwindCSS for modern styling
- Express.js for the backend framework