#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?

This article has been dead for over six months. Start a new discussion instead.