const int NOMORETOKENS = 0;
const int IDENTIFIER = 1;
const int DIGITSTRING = 2;
const int LPAR = 3;
const int RPAR = 4;
const int ADDOP = 5;
const int MULOP = 6;
//------------------------------------------------------------------------------
// determine if c is a letter (upper/lower case)
bool isLetter(char c)
{
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
}
//------------------------------------------------------------------------------
// determine if c is a digit character
bool isDigit(char c)
{
return '0' <= c && c <= '9';
}
//------------------------------------------------------------------------------
// determine if c is a multiplication operator
bool isMulop(char c)
{
return (c=='*' || c=='/');
}
//------------------------------------------------------------------------------
// determine if c is an addition operator
bool isAddop(char c)
{
return c=='+' || c=='-';
}
//==============================================================================
// return the name of the lexical unit whose code is p
string lexName(int p)
{
string names[] = {"NoTokens", "Identifer", "DigitString", "LeftParent", "RightParent",
"AddOp", "MulOp"};
return names[p];
}
int main(int argc, char *argv[])
{
string file;
cout<<"Name the file to be processed : ";
cin>>file;
string filename = file;
ifstream infile;
infile.open(filename.c_str()); // open file
if(infile)
{
string s="";
while(infile)
{
getline(infile,s);
cout<<s<<endl;
}
while(s.length()>0)
{
string t= "";
int ln= getNextLex(s,t);
cout<<"\t"<<t<<"\t "<<lexName(ln)<<"("<<ln<<")"<<endl;
}
system("PAUSE");
return EXIT_SUCCESS;
}
else
{
cout << "The file name you gave does not exist"<<endl;
}
infile.close(); // file close