Write a grammar not necessarily LL1 that recognizes various

Write a grammar (not necessarily LL(1)) that recognizes various forms of variables in C++, which should include the simple variable (e.g. a, b, c, array variables (e.g. a[10], a[10][10], a[10][10][10]), class members (e.g. a.data, a data name, ...), pointer variables (e.g. a rightarrow data, a- >data name), and composite variables that are combinations of the above forms (e.g. a rightarrow bb[100][200][300].data rightarrow mdata.bb[100]). You can assume the array index can only be a number

Solution

// Program that implements queue as a linked list
# include <iostream.h>
# include <conio.h>
class queue
{
   private :

       struct node
       {
           int data ;
           node *link ;
       } *front, *rear ;

   public :

       queue( ) ;
       void addq ( int item ) ;
       int delq( ) ;
       ~queue( ) ;
} ;

// initialises data member
queue :: queue( )
{
   front = rear = NULL ;
}

// adds an element to the queue
void queue :: addq ( int item )
{
   node *temp ;

   temp = new node ;
   if ( temp == NULL )
       cout << \"\ Queue is full\" ;

   temp -> data = item ;
   temp -> link = NULL ;

   if ( front == NULL )
   {
       rear = front = temp ;
       return ;
   }

   rear -> link = temp ;
   rear = rear -> link ;
}

// removes an element from the queue
int queue :: delq( )
{
   if ( front == NULL )
   {
       cout << \"\ Queue is empty\" ;
       return NULL ;
   }

   node *temp ;
   int item ;

   item = front -> data ;
   temp = front ;
   front = front -> link ;
   delete temp ;
   return item ;
}

// deallocates memory
queue :: ~queue( )
{
   if ( front == NULL )
       return ;
   node *temp ;
   while ( front != NULL )
   {
       temp = front ;
       front = front -> link ;
       delete temp ;
   }
}

void main( )
{
   queue a ;
   clrscr();
   a.addq ( 34 ) ;
   a.addq ( 46 ) ;
   a.addq ( 23 ) ;
   a.addq ( 29 ) ;
   a.addq ( 15 ) ;
   a.addq ( 33 ) ;
   a.addq ( 28 ) ;

   int i = a.delq( ) ;
   cout << \"\ Item extracted: \" << i ;

   i = a.delq( ) ;
   cout << \"\ Item extracted: \" << i ;

   i = a.delq( ) ;
   cout << \"\ Item extracted: \" << i ;
   getch();
}

 Write a grammar (not necessarily LL(1)) that recognizes various forms of variables in C++, which should include the simple variable (e.g. a, b, c, array variab
 Write a grammar (not necessarily LL(1)) that recognizes various forms of variables in C++, which should include the simple variable (e.g. a, b, c, array variab

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site