| 1 |
#include "Parser.ih" |
| 2 |
|
| 3 |
/* |
| 4 |
Lexical scanner returns a double floating point |
| 5 |
number on the stack and the token NUM, or the ASCII |
| 6 |
character read if not a number. Skips all blanks |
| 7 |
and tabs, returns 0 for EOF. |
| 8 |
*/ |
| 9 |
|
| 10 |
int Parser::lex() |
| 11 |
{ |
| 12 |
char c; |
| 13 |
// get the next non-ws character |
| 14 |
while ((std::cin.get(c) && c == ' ') || c == '\t') |
| 15 |
; |
| 16 |
|
| 17 |
if (!std::cin) // no characters were obtained |
| 18 |
return 0; // indicate End Of Input |
| 19 |
|
| 20 |
if (c == '.' || isdigit (c)) // if a digit char was found |
| 21 |
{ |
| 22 |
std::cin.putback(c); // return the character |
| 23 |
std::cin >> d_val_; // extract a number |
| 24 |
return NUM; // return the NUM token |
| 25 |
} |
| 26 |
|
| 27 |
return c; // otherwise return the extracted char. |
| 28 |
} |