I need to write a scanner for ASCII files. The scanner should recognize (find) three kinds of tokens in the input file. strings of spaces, single new lines, and words (a word is defined to be any sequence of characters not including any spaces or new lines.
The driver should repeatedly call a function called getToken(). getToken reads the next token in the input file, and return to main the token type, the actual string (lexeme) of the token.
For each call to getToken() (for each token returned), main outputs the token type (a unique integer is OK to represent the type), the string (except for new lines – this causes visual problems on the screen) main also outputs the position in the input file for each token: the line number and the char position on the line of the beginning of the token.
The ifstream.get() function within getToken() should read characters one at a time from the input. getToken() will collect them until it has what it needs to return the next token.
??
2006-09-28
13:15:07
·
1 answers
·
asked by
Anonymous