Skip to content

If_else_parser is a C++ tool that validates the syntax of if-else conditional statements. It checks for correctness, generates parse trees, and displays the grammar rules used. This project supports nested conditions and provides an educational resource for understanding if-else constructs in C++.

Notifications You must be signed in to change notification settings

Vikas2171/If_else_parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

If_else_parser

Introduction

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:

  1. Syntax Validation: It takes an input string and checks if it is a valid syntax for an if-else conditional statement in C++.
  2. 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.
  3. Grammar Rules: It prints the context-free grammar rules used in the validation process, presented as an adjacency list.

Team Members

This project is a collaborative effort by the following team members:

Features

  • 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.

Assumptions

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.

Getting Started

Prerequisites

To run this project, you need:

  • A C++ compiler (e.g., GCC, Clang)
  • Basic knowledge of C++ and context-free grammars

Installation

  1. Clone the repository:
git clone https://github.com/Vikas2171/If_else_parser.git
  1. Navigate to the Project Directory:
cd If_else_parser
  1. Compile the Program:
g++ -o if_else_parser if_else_parser.cpp
  1. Run the Program:
./if_else_parser

Usage

  1. Input:

    The program prompts you to enter a string representing an if-else conditional statement in C++.

  2. 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".

Example Run

  • INPUT
if(condition){}else{}
  • OUTPUT

output

Acknowledgements

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.

About

If_else_parser is a C++ tool that validates the syntax of if-else conditional statements. It checks for correctness, generates parse trees, and displays the grammar rules used. This project supports nested conditions and provides an educational resource for understanding if-else constructs in C++.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages