User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,759 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,692 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 764 | Replies: 2
Reply
Join Date: Dec 2004
Posts: 465
Reputation: Acidburn is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 5
Acidburn Acidburn is offline Offline
Posting Pro in Training

code driving me nuts!

  #1  
Feb 9th, 2006
#include <iostream>
#include <fstream>

using namespace std;

char RW[10];
char id[10];

void populateArray(char ch, int &i, char * array);
void valid(char *array,  int i);


#define MINUS '-'
#define PLUS '+'
#define TIMES '*'
#define DIVIDE '/'
#define EQL '='
#define LP '('
#define RP ')'
#define SEMIC ';'
#define LSS '<'
#define GTR '>'
#define COMMA ','
#define DOLLAR '$'

// parser
char getsym();
void func_e(char &sym);
void funcc_t(char &sym);
void func_S(char &sym);
void func_E(char &sym);
void func_T(char &sym);
void func_F(char &sym);

int main()
{
    int i = 0;
    char ch = 'i';
	char nextsym;
    char array[10];

    ifstream infile;

    cout << "welcome to the Lexical Scanner" << endl;

		//this bit is the lexcial scanner input from a file. Not used


    /* infile.open("new.txt");
        if(infile.fail())
          {
           cout << "unable to load sourcefile" << endl;
           exit(1);
          }
        else
			{
			while((ch = infile.get()) != EOF )
            {
            if ( ch != ' ') // strip out whitespaces from txt
			   {
               populateArray(ch, i, array);
              }  
            }
          }*/

		valid(array,i);

	cout << "\n\n\nHandling input to the parser \n\n"<<endl;

	nextsym = getsym();
	func_T(nextsym);

return 0;
}


char getsym()
{
	static char array[5] = "a*b$";
	static int i = -1;
	++i;

return array[i];
	
}
	

void func_e(char &sym)
{
	cout << "in funct_e, checking for +: " << sym << endl;
	if(sym == '+')
	{
		sym=getsym();
		func_T(sym);
		func_e(sym);
	}

}
void funcc_t(char &sym)
{	cout << "In funct_t, checking for * = " << sym << endl;
	if(sym=='*')
	{
		sym=getsym();
		func_F(sym);
		func_T(sym);
	}
}
void func_S(char &sym)
{
	//func_E(sym);

	if(sym!='$')
	{
		cout << "error missing dollar"<<endl;
		exit(1);
	}
	else
	{
		cout << "Parse sucesfful" << endl;
		exit(1);
	}
}
void func_E(char &sym)
{
	funcc_t(sym);
	func_e(sym);
}

void func_T(char &sym)
{
	func_F(sym);
	funcc_t(sym);
}
void func_F(char &sym)
{
	//cout << "In funct_F, checking for id: = " << sym << endl;
	//char id;
//	for(int i = 0; i<3; i++)
//	{
	//	cout << "going through the loop" << endl;
		//if(sym==RW[i])
		//{
			cout << "Error on the input stream, ID expected" << endl;
		//	func_S(sym);
		//}	
	//}
	
	/*id = sym;

	if(sym==id){}
		//sym=getsym();

	else
		if(sym=='(')
		{
			//sym=getsym();
		//	func_E(sym);
			if(sym==')'){}
			//	sym=getsym();
			else
			{
				cout << "error missing brackets" <<endl;
				exit(1);
			}
		}
		else
		{
		cout << "error missing id" <<endl;
		exit(1);
		}
*/
}

void populateArray(char ch, int &i ,char *array)
{
    array[i] = ch;
    i++;
	
}

void valid(char * array,  int i )
{
	int j = 0;
	int h = 0;
	int c = 0;

while(j<i)
    {
      switch(array[j])
           {
            case PLUS:
              cout << "its a plus" <<endl;
						  RW[h] = PLUS;
						  h++;
             break;

            case MINUS:
              cout << "minus found" <<endl;
							RW[h] = MINUS;
							h++;
             break;

            case TIMES:
              cout << "Times found" <<endl;
					  	RW[h] = TIMES;
						  h++;
             break;

            case DIVIDE:
             cout << "Divide found" <<endl;
						 RW[h] = DIVIDE;
						 h++;
            break;

            case EQL:
             cout << "Equals found " <<endl;
						 RW[h] = EQL;
					   h++;
            break;

            case LP:
             cout << "LP ( found" << endl;
						 RW[h] = LP;
						 h++;
            break;

            case RP:
             cout << "RP ) found" << endl;
						 RW[h] = RP;
						 h++;
            break;

            case SEMIC:
             cout << "semiclon found" << endl;
						 strcpy(&RW[h],"SEMIC");
						 h++;
            break;

            case LSS:
             cout << "Less than found  < " << endl;
						 RW[h] = LSS;
						 h++;
            break;

           case GTR:
            cout << "Greater than found " << endl;
						RW[h] = GTR;
						h++;
           break;

            case 'i': // reconize if's
              if (array[++j] == 'f')
                  cout << "if" <<endl;;
				          strcpy(&RW[h],"if");
						      h++;
            break;

           case 'e': // reconize else's
			       if (array[++j] == 'l')
						 {
				      if(array[++j] == 's')
							{
					     if(array[++j] == 'e')
							 {	
                cout << "else found" << endl;	
					   	  strcpy(&RW[h],"else");
						    h++;
							 }
							}
						 }
           break;

             case 't':
               if (array[++j] == 'h')
                if(array[++j] == 'e')
                 if(array[++j] == 'n')
                   cout << "then found" << endl;
						       strcpy(&RW[h],"then");
						       h++;
             break;

               case 'f':
                 if (array[++j] == 'u')
                  if(array[++j] == 'n')
                   if(array[++j] == 'c')
                    if (array[++j] == 't')
                     if(array[++j] == 'i')
                      if(array[++j] == 'o')
                       if(array[++j] == 'n')
                          cout << "function found " <<endl;
						              strcpy(&RW[h],"function");
						              h++;
               break;


			         case DOLLAR:
				        cout << "its a dollar" << endl;
				   	    RW[h] = DOLLAR;
						    h++;
						   break;

			        default:
								{
				        id[c] = array[j];
					      c++;
								}
				  }

       }
   j++;
}



why is it when theres nothing in func_F thats funcc_t() gets called? I cant work out where its been called from. Really bugging me Can anyone help please?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,222
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 38
Solved Threads: 935
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: code driving me nuts!

  #2  
Feb 9th, 2006
see the last line of main()
Reply With Quote  
Join Date: Nov 2005
Location: Canada
Posts: 236
Reputation: dwks will become famous soon enough dwks will become famous soon enough 
Rep Power: 4
Solved Threads: 21
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: code driving me nuts!

  #3  
Feb 9th, 2006
return 0;?
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 1:03 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC