Errors after compiling

This is a discussion on Errors after compiling within the C++ Programming forums, part of the General Programming Boards category; hi all, the following code is for a SLR parser... after compiling i got some strange errors - could someone ...

  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    2

    Errors after compiling

    hi all,

    the following code is for a SLR parser... after compiling i got some strange errors - could someone pls take a look, or try compiling it... tnx alot

    Code:
    #include<iostream>
    #include<conio.h>
    #include<string.h>
    #include<process.h>
    #include<stdio.h>
    
    char in[30];
    char T[]={"i+*()$E"};
    char prod[4][5]={"EE+E","EE*E","E(E)","Ei"};
    
    char M[10][8]={"sbbsbbg","bssbbab","sbbsbbg",              //matrix to store shift,
    	       "brrbrrb","sbbsbbg","sbbsbbg",              //reduce,error and accept states
    	       "bssbsbb","brsbrrb","brrbrrb",
    	       "brrbrrb"};
    int S[10][7]={{3,0,0,2,0,0,1},{0,4,5,0,0,0,0},{3,0,0,2,0,0,6}, //matrix to store goto and action states
    	      {0,4,4,0,4,4,0},{3,0,0,2,0,0,7},{3,0,0,2,0,0,8},
    	      {0,4,5,0,9,0,0},{0,1,5,0,1,1,0},{0,2,2,0,2,2,0},
    	      {0,3,3,0,3,3,0}};
    
    
    
    class stack
    {
    char a[20]; //stores the terminals and states
    int b[20];  //stores the states
    int top;
    int topb;
    public:
    stack()
    {
    top=topb=0;
    }
    
    void push(char n)
    {
    a[top]=n;
    top++;
    }
    void pushb(int n)
    {
    b[topb]=n;
    topb++;
    }
    char pop()
    {
    if(top>0)
    return a[--top];
    else return -1;
    }
    int popb()
    {
    if(topb>0)
    return b[--topb];
    else return -1;
    }
    
    int tos()
    {
    return b[topb-1];
    }
    };
    
    int search(char c)
    {
     for(int i=0;i<strlen(T);i++)
     {
     if(c==T[i])
     return i;
     }
     return -1;
    }
    
    void print(int ser)
    {
    cout<<prod[ser][0]<<"->";
    for(int i=1;i<strlen(prod[ser]);i++)
    cout<<prod[ser][i];
    cout<<endl;
    }
    
    void main()
    {
    clrscr();
    stack s;
    int i=0,x,ser;
    char c;
    
    gets(in);
    s.pushb(0);
    int k=0;
    while(k<20)
    {k++;
     x=search(in[i]);
     if(x==-1)
     break;
     c=M[s.tos()][x];
     if(c=='b')
     break;
     if(c=='a')
     {
     printf("\naccepted!!!");
     getch();
     exit(0);
     }
     if(c=='s')
     {
     s.push(in[i]);
     i++;
     s.pushb(S[s.tos()][x]);
     continue;
     }
     ser=S[s.tos()][x];
     ser--;
     for(int j=0;j<strlen(prod[ser])-1;j++)
     {
     s.pop();
     s.popb();
     }
     s.push(prod[ser][0]);
     s.pushb(S[s.tos()][search(prod[ser][0])]);
     print(ser);
     }
     printf("Error!!!");
     getch();
    }
    ERROR log:
    http://img441.imageshack.us/img441/9344/62954061.png

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    399
    Add this after the include files:
    Code:
    using namespace std;
    There are numerous other problems with the code, like using gets() for example. The error log also clearly states that main() returns int, not void.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,457
    Indent your code! This is how it's supposed to look like:
    Code:
    #include<iostream>
    #include<conio.h>
    #include<string.h>
    #include<process.h>
    #include<stdio.h>
    
    using namespace std;
    
    char in[30];
    char T[]={"i+*()$E"};
    char prod[4][5]={"EE+E","EE*E","E(E)","Ei"};
    
    char M[10][8]={"sbbsbbg","bssbbab","sbbsbbg",              //matrix to store shift,
    	"brrbrrb","sbbsbbg","sbbsbbg",              //reduce,error and accept states
    	"bssbsbb","brsbrrb","brrbrrb",
    	"brrbrrb"};
    int S[10][7]={{3,0,0,2,0,0,1},{0,4,5,0,0,0,0},{3,0,0,2,0,0,6}, //matrix to store goto and action states
    {0,4,4,0,4,4,0},{3,0,0,2,0,0,7},{3,0,0,2,0,0,8},
    {0,4,5,0,9,0,0},{0,1,5,0,1,1,0},{0,2,2,0,2,2,0},
    {0,3,3,0,3,3,0}};
    
    
    
    class stack
    {
    	char a[20]; //stores the terminals and states
    	int b[20];  //stores the states
    	int top;
    	int topb;
    public:
    	stack()
    	{
    		top=topb=0;
    	}
    
    	void push(char n)
    	{
    		a[top]=n;
    		top++;
    	}
    	void pushb(int n)
    	{
    		b[topb]=n;
    		topb++;
    	}
    	char pop()
    	{
    		if(top>0)
    			return a[--top];
    		else return -1;
    	}
    	int popb()
    	{
    		if(topb>0)
    			return b[--topb];
    		else return -1;
    	}
    
    	int tos()
    	{
    		return b[topb-1];
    	}
    };
    
    int search(char c)
    {
    	for(int i=0;i<strlen(T);i++)
    	{
    		if(c==T[i])
    			return i;
    	}
    	return -1;
    }
    
    void print(int ser)
    {
    	cout<<prod[ser][0]<<"->";
    	for(int i=1;i<strlen(prod[ser]);i++)
    		cout<<prod[ser][i];
    	cout<<endl;
    }
    
    void main()
    {
    	stack s;
    	int i=0,x,ser;
    	char c;
    
    	gets(in);
    	s.pushb(0);
    	int k=0;
    	while(k<20)
    	{
    		k++;
    		x=search(in[i]);
    		if(x==-1)
    			break;
    		c=M[s.tos()][x];
    		if(c=='b')
    			break;
    		if(c=='a')
    		{
    			printf("\naccepted!!!");
    			//getch();
    			exit(0);
    		}
    		if(c=='s')
    		{
    			s.push(in[i]);
    			i++;
    			s.pushb(S[s.tos()][x]);
    			continue;
    		}
    		ser=S[s.tos()][x];
    		ser--;
    		for(int j=0;j<strlen(prod[ser])-1;j++)
    		{
    			s.pop();
    			s.popb();
    		}
    		s.push(prod[ser][0]);
    		s.pushb(S[s.tos()][search(prod[ser][0])]);
    		print(ser);
    	}
    	printf("Error!!!");
    	//getch();
    }
    Get rid of getch. Non-standard. Use std::cin.get().
    Gets is Evil. Never use it.
    Void main is non-standard. Don't use it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Jun 2010
    Posts
    2
    tnx... working now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strange errors when compiling.
    By twilight in forum C++ Programming
    Replies: 8
    Last Post: 08-05-2009, 03:20 PM
  2. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  3. Replies: 4
    Last Post: 03-10-2008, 07:03 AM
  4. Quincy 2005: Compiling Errors
    By Thileepan_Bala in forum C Programming
    Replies: 6
    Last Post: 01-18-2008, 07:26 PM
  5. Replies: 2
    Last Post: 12-07-2004, 01:31 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21