Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone help me here. The code for parenthesis is missing. If someone could

ID: 663236 • Letter: C

Question

Can someone help me here. The code for parenthesis is missing. If someone could help implement code for parenthesis i would appreciate it. i.e. where it says    P -> I | L | UI | UL | (E)     there should be code for parenthesis and i tried all possible way but could not figure what is going wrong. I would appreciate any help.

/*
A -> I = E | E
E -> P O P | P
O -> + | - | * | / | **
P -> I | L | UI | UL | (E)
U -> + | - | !
I -> C | CI
C -> a | b | ... | y | z
L -> D | DL
D -> 0 | 1 | ... | 8 | 9
*/

#include
#include
#include

using namespace std;

  

int A();
int E();   //changing
int P(int k);   //changing
int L();
int I(); //not changing
int UI();   //not changing
int UL();   //not hanging

string data;
int i,j;


int main()
{
  
ifstream infile;
infile.open("input.txt");
   
    while(!infile.eof())
{
   i=0;
       j=0;
        infile >> data;
       if(A()!=-1&&i==data.length())
            cout<<"The string "<

int A()
{
   //cout<<" A()";
   if(I()!=-1)
   {
       i=j;
       if(data[i++]=='=')
       {
           if(E()!=-1)
               return 0;
       }else
       {
           i=0;
           if(E()!=-1)
           return 0;
       }
          
      
   }else
       {
           i=0;
           if(E()!=-1)
           return 0;
       }
   return -1;
}

int E()
{
   //cout<<" E()";
if(P(-1)!=-1)
{
   if(i==data.length())
       return 0;
   else
   {
       if(data[i]=='+'||data[i]=='-'||data[i]=='*'||data[i]=='/')
       {
           i++;
           if(P(1)!=-1)
               return 0;
       }
   }
}
return -1;
}


int P(int k)
{
   //cout<<" P()";
   if(I()!=-1)
   {
  
       if(k==-1)
           {
               i=j;
               return 0;
           }
       else
           {
               if(j==data.length())
                   {
                       i=j;
                       return 0;
                   }
               else
                   return E();
           }
          
   }
      
   else if(L()!=-1)
   {
       if(k==-1)
           {
               i=j;
               return 0;
           }
       else
           {
               if(j==data.length())
                   {
                       i=j;
                       return 0;
                   }
               else
                   return E();
           }
   }
      
   else if(UI()!=-1)
   {
       if(k==-1)
           {
               i=j;
               return 0;
           }
       else
           {
               if(j==data.length())
                   {
                       i=j;
                       return 0;
                   }
               else
                   return E();
           }
   }
      
   else if(UL()!=-1)
   {
       if(k==-1)
           {
               i=j;
               return 0;
           }
       else
           {
               if(j==data.length())
                   {
                       i=j;
                       return 0;
                   }
               else
                   return E();
           }
   }
   /*else if(P(-1)!=-1)
   {
       if(data[i]=='+'||data[i]=='-'||data[i]=='*'||data[i]=='/')
           {
               i++;
               if(P(1)!=-1)
                   return 0;
           }
   }*/
           else if(k==1)
               return E();
           else
               return -1;
   return -1;
}


int L()
{
   //cout<<" L()";
   j=i;
   while(j    {
       if(data[j]>='0'&&data[j]<='9')
           j++;
       else
           break;
   }
   if(j==i)
       return -1;
   else
       return 0;
}

int I()
{
   //cout<<" I()";
   j=i;
   while(j    {
       if(data[j]>='a'&&data[j]<='z')
           j++;
       else
           break;
   }
   if(j==i)
       return -1;
   else
       return 0;

}

int UI()
{
   //cout<<" UI()";
   j=i;
   int k=i;
   if(j        {
           j++;
           i=j;
           if(I()!=-1)
           {
               i=j;
               return 0;
           }
       }
       i=k;
       return -1;
}

int UL()
{
   //cout<<" UL()";
   j=i;
   int k=i;
   if(j        {
           j++;
           i=j;
           if(L()!=-1)
           {
               i=j;
               return 0;
           }
       }
       i=k;
       return -1;
}

Explanation / Answer

parantheses ar good. you can run and try again.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote