C++ Programming Blog

 
 
 
#include <iostream.h>
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>


typedef struct treenode
{
    char info;
    treenode *left;
    treenode *right;
}node;


    node * proc_e(char input[],int &ssm);
    node * proc_t(char input[],int &ssm);
    node * proc_v(char input[],int &ssm);
    void traversal(node *temp);

void main()
{
    char input[20];
    int ssm=0;
    node *root;
//    clrscr();

    cout<<endl<<\"ENTER THE STRING TO BE PARSED:\";
    cin>>input;

    root = proc_e(input,ssm);
    cout<<endl<<\"CONTENTS OF THE PARSE TREE:\";
    traversal(root);


    getch();
}


void traversal(node *temp)
{


   if(temp != NULL)
   {
    traversal(temp->left);
    cout<<temp->info;
    traversal(temp->right);
    }
}


//PROCEDURE FOR NT E:

node * proc_e(char input[],int &ssm)
{
    node *a,*b;

    a=proc_t(input,ssm);

    while(input[ssm]==\'+\')
    {
        ssm++;
        b=proc_t(input,ssm);

        node *temp;
        temp=new node; //(node*)malloc(sizeof(node));
        temp->info=\'+\';
        temp->left=a;
        temp->right=b;

        a=temp;

    }

    return a;
}





//PROCEDURE FOR NT T:

node * proc_t(char input[],int &ssm)
{
    node *a,*b;

    a=proc_v(input,ssm);
    ssm = ssm + 1;

    while(input[ssm] == \'*\')
    {
        ssm++;

        b=proc_v(input,ssm);
        node *temp;

        temp=new node;//(node *)malloc(sizeof(node));
        temp->info=\'*\';
        temp->left=a;
        temp->right=b;

        a=temp;
        ssm = ssm +1;
    }

    return a;


}



//PROCEDURE FOR NT V:

node * proc_v(char input[],int &ssm)
{
    node *a;

    if(input[ssm]==\'I\')
    {
        node *temp;
        temp=new node; //(node*)malloc(sizeof(node));
        temp->info=\'I\';
        temp->left=NULL;
        temp->right=NULL;
        return temp;
    }
    else
    {
        cout<<endl<<\"ERROR. INVALID SYMBOL \"<<input[ssm];
        getch();
        exit(0);
    }
}

    Related Post:
  1. Program that takes input of 2 matrix rows and columns data and displays addition of it using + operator overloading

  2. Program to illustrate the use of call-by-refrence method using pointers

  3. Program to estimate the value of Second Derivative of the function at the given points from the given data using Central Difference Formula of order 2

  4. Program of declaration of default arguments during creation of function

  5. Program to illustrate the implementation of Scaling Transformation along a Fixed Point

  6. Program to illustrate the implementation of Scaling Transformation

  7. Program to show the simulation of the Solar System

  8. Program that takes input of vector elements and performs multiplication operation, and input/output (&gt;&gt;, &lt;&lt;) using operator overloading

  9. FUNCTION WITH ALIAS NAME OR REFERENCE VARIABLE IN C++

  10. Program to illustrate the implementation of Translation Transformation

  11. Program of Education System that maintains Institute Database using multilevel inheritance

  12. Program to solve the Towers of Hanoi Problem (using Recursive Algorithm)

  13. Program to illustrate the implementation of X-Direction Shear Transformation

  14. Program to illustrate the implementation of 3D Rotation Transformation along x-axis

  15. Program to implement Add and Subtract functions on Big Number Class

  16. Program to computes the n_th term of the fibonacci series using Toplogical Odering and Dynamic Programming Technique

  17. Program to illustrate printing data on the printer

  18. Tic-Tac-Toe game

  19. Program that creats a 3D solid object using Rotational Sweep Representatiom Method

  20. Program to tokenized a given string

 
 
Didn't find what you were looking for? Find more on PROGRAM TO IMPLEMENT RECURSIVE DESCENT PARSER