I have assignment to write a simple lex anayzer. I can't get the output to print the tokens correctly.
All that should print is the characters from a file, and their assigned token. Mine just ends in DIGIT DIGIT DIGIT every time (because i have "int token = 0". If i change the value it just changes the constant token name. Due tonight, and feeling desperate. Please show my what I am doing wrong. Thank you so much.
CO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int main()
{
string characters;
ifstream foo("file name here");
while (foo >> characters)
{
int t = 0;
string convertToken(int t);
cout << characters << convertToken(t);
}
foo.close();
return 0;
}
This prints
A DIGIT
+ DIGIT
1 DIGIT
= DIGIT
word DIGIT
etc etc
it should print
A LETTER/WORD
+ PLUS
1 DIGIT
= EQUAL
word LETTER/WORD
I think that's part of the point of your assignment; based on the list you've given, however, if the string contains characters, it is a "LETTER/WORD", if it is the plus sign, it is "PLUS", and so on.
It is part of the point of the assignment. Setting up all the code you cannot see is another part. And, after many many days I cannot figure out how to do it, so in desperation I am coming for help.
If i code it so that it takes information from user input, it works correctly. When I switch it to take the information from a file, something breaks. I cannot figure out what is wrong, and I am asking for straight up help at this point. Please.