Debian Codegraph @

documentation/manual/algorithm/example/Parser.h

raw
1 #ifndef Parser_h_included
2 #define Parser_h_included
3
4 // $insert baseclass
5 #include "Parserbase.h"
6
7 #include <cctype>
8 #include <string>
9
10
11 #undef Parser
12 class Parser: public ParserBase
13 {
14
15 public:
16 int parse();
17
18 private:
19 void error(char const *msg); // called on (syntax) errors
20 int lex(); // returns the next token from the
21 // lexical scanner.
22 void print(); // use, e.g., d_token, d_loc
23
24 // support functions for parse():
25 void executeAction(int ruleNr);
26 void errorRecovery();
27 int lookup(bool recovery);
28 void nextToken();
29 };
30
31 inline void Parser::error(char const *msg)
32 {
33 std::cerr << msg << '\n';
34 }
35
36 // $insert lex
37
38 inline void Parser::print() // use d_token, d_loc
39 {}
40
41 inline int Parser::lex()
42 {
43 std::string word;
44
45 std::cin >> word;
46 if (std::cin.eof())
47 return 0;
48 if (isdigit(word[0]))
49 return NR;
50
51 return word[0];
52 }
53
54
55 #endif