Debian Codegraph @

documentation/demos/manual/rpn/parser/lex.cc

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