Logo 
Search:

C++ Programming Articles

Submit Article
Home » Articles » C++ Programming » ParsingRSS Feeds

Program of LL Parser

Posted By: Madeleine Hughes     Category: C++ Programming     Views: 5769

Write a Program of LL Parser.

Code for Program of LL Parser in C++ Programming

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


int main()
     {
       char tmp[15];
       char str[15], csf[15]={"E"};
       int ssm=0, i, j, v, k, pos=0, a;
       clrscr();

       char pt[6][5][4]={"" , "i" , "+" , "*" , "/",
             "E", "TX", "n" , "n" , "n",
             "X", "n" , "TX", "n" , "" ,
             "T", "VY", "n" , "n" , "n",
             "Y", "n" , ""  , "VY", "" ,
             "V", "i" , "n" , "n" , "n"};
     cout<<"\n Enter An Expression: "<<endl;
     cin>>str;

     while(str[ssm]!='/')
    {
      pos=0;
      while(csf[pos]!='E' &&
        csf[pos]!='X' &&
        csf[pos]!='T' &&
        csf[pos]!='Y' &&
        csf[pos]!='V' && csf[pos]!='\0')
        pos++;
    if (csf[pos]=='\0')
       break;

    for(i=1; i<6; i++)
      {
        if(csf[pos]==pt[i][0][0])
           break;
      }
       for(j=1; j<5; j++)
      {
         if(str[ssm]==pt[0][j][0])
        break;
      }
       if(strcmp(pt[i][j], "n")==0)
       {
          cout<<"\n Null Value: "<<endl;
          cout<<pt[i][j];
          exit;
       }

       for(k=0; k<pos; k++)
       tmp[k]=csf[k];
       tmp[k]='\0';
       strcat(tmp, pt[i][j]);

       int l= strlen(tmp);
       k=l;

       for(a=pos+1; csf[a]!='\0'; a++, k++)
       tmp[k]=csf[a];
       strcpy(csf, tmp);
    }


       strcat(csf, "/");
     if(strcmp(csf, str)==0)
         {
         cout<<"\t csf"<<csf;

         cout<<"\tstr"<<str;

         cout<<"\n Valid Expression: "<<endl;


         }

     else
         {
          cout<<"\n Invalid Expression:"<<endl;

         }


      getch();
      return 0;
}
  
Share: 

 
 

Didn't find what you were looking for? Find more on Program of LL Parser Or get search suggestion and latest updates.

Madeleine Hughes
Madeleine Hughes author of Program of LL Parser is from London, United Kingdom.
 
View All Articles

 

Other Interesting Articles in C++ Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!