If_else_parser is a C++ project designed to validate whether an input string confirms to the syntax of an if-else
conditional statement in C++. This tool is useful for programmers, students, and educators who want to ensure the correctness of if-else
constructs in their code.
The project performs the following tasks:
- Syntax Validation: It takes an input string and checks if it is a valid syntax for an
if-else
conditional statement in C++. - Parse Tree Generation: If the syntax is valid, the tool generates and prints all levels of the parse tree, with each level displayed on a separate line.
- Grammar Rules: It prints the context-free grammar rules used in the validation process, presented as an adjacency list.
This project is a collaborative effort by the following team members:
- Validation of if-else Syntax: The tool strictly adheres to the C++ syntax rules for
if-else
statements. - Parse Tree Visualization: It displays all the levels of the parse tree, making it easier to understand how the input is parsed.
- Grammar Rule Display: Lists all the context-free grammar rules applied during parsing, represented as an adjacency list for better comprehension.
- Support for Nested if-else Conditions: The tool also supports the validation of nested if-else conditions.
In developing this project, we have made the following assumptions:
- Only a single relational expression should be given as the condition of the if block.
(a >= b)
- The if and else blocks should be empty ({}).
if(condition){}else{}
- Variable names should be a single character only.
a, b, c,....
- The syntax is considered correct only if there is a corresponding else block for every if block.
"if(condition){}"
- This is considered as invalid syntax by our parser.
"if(condition){}else{}"
- This is valid.
To run this project, you need:
- A C++ compiler (e.g., GCC, Clang)
- Basic knowledge of C++ and context-free grammars
- Clone the repository:
git clone https://github.com/Vikas2171/If_else_parser.git
- Navigate to the Project Directory:
cd If_else_parser
- Compile the Program:
g++ -o if_else_parser if_else_parser.cpp
- Run the Program:
./if_else_parser
-
Input:
The program prompts you to enter a string representing an
if-else
conditional statement in C++. -
Output:
If the input is valid, the program will:
- Print "The given input is valid"
- Display the parse tree with each level on a separate line.
- List all the context-free grammar rules used, displayed as an adjacency list.
- If the input is invalid, it will print "The given input has Invalid Syntax".
- INPUT
if(condition){}else{}
- OUTPUT
We would like to express our sincere gratitude to Senior Professor Subhasis Bhattacharjee of IIT Jammu for his guidance and support throughout this course project. His expertise and insights have been invaluable in the development of this parser.