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 to implement a Translator that reads an Infix Expression translates it into a Postfix Expression and evaluate the Postfix Expression

  2. Program to illustrate the implementation of Arithmetic Expression Evaluater accepting {} & [] also

  3. Program to show the projection of 3D objects using Cabinet Oblique Parallel Projection onto xy-plane (i.e. angle=30 deg)

  4. Program to capitalize the first charcter of every word in a string

  5. Program of moving message box like windows

  6. Program to implement the Kurskals Algorithm to solve Minimum Cost Spanning Tree Problem (MST) using Graphics with Mouse Support

  7. Program to illustrate the Merge Sort

  8. Program to illustrate unary operator(decrement operator) overloading without return type

  9. PROGRAM OF OVERLOADING ARITHMETIC OPERATORS ON OBJECTS OF CLASS FLOAT HAVING AN DATA MEMBERS OF TYPE FLOAT

  10. Program to illustrate the implementation of arrays as a Stack in graphics

  11. Program to solve the mystery of Towers of Hanoi using recursion

  12. Program to draw a circle using Bresenhams Circle Algorithm

  13. Program to illustrate array of objects in classes

  14. Program to estimate the Differential value of a given function using Trapezoidal Rule [Predictor-Corrector Scheme (PC2)]

  15. Example of Date

  16. Program for electricity board charges calculation

  17. Program to read a Linear System of Equations,then evaluate it by using Jacobis Itrative Method and show the result

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

  19. Program to illustrate the Bubble Sorting of arrays

  20. Program to illustrate classes without using inline functions

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