•
•
•
•
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
![]() |
•
•
Join Date: Dec 2004
Posts: 465
Reputation:
Rep Power: 4
Solved Threads: 5
#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?
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,222
Reputation:
Rep Power: 38
Solved Threads: 935
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
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
access activation api blogger blogging blogs code combo dani daniweb data debugging development dreamweaver driving dropdownlist effects games gdata google gpl html innovation key linux microsoft module net news openbsd product programming racing reuse rss serial source tags video vista web wysiwyg xml
- hello to all in DaniLand!!!! (Geeks' Lounge)
- Program keeps crashing... (C++)
- Concept to fruition - the chronicle of a new site (Growing an Online Community)
- LOP driving me nuts! How to be rid of it? (Viruses, Spyware and other Nasties)
- ads234 is driving me NUTS (Viruses, Spyware and other Nasties)
- Can't remove "about:blank" homepage. Please help. (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Counting the amount of numbers in one integer?
- Next Thread: error help



Linear Mode