Debian Codegraph @

yo/concrete/bisonc++/parser/parser.h

raw
1 #ifndef Parser_h_included
2 #define Parser_h_included
3
4 #include <iostream>
5 #include <sstream>
6 #include <bobcat/a2x>
7
8 #include "parserbase.h"
9 #include "../scanner/scanner.h"
10
11 #undef Parser
12 class Parser: public ParserBase
13 {
14 std::ostringstream d_rpn;
15 // $insert scannerobject
16 Scanner d_scanner;
17
18 public:
19 int parse();
20
21 private:
22 template <typename Type>
23 Type exec(char c, Type left, Type right);
24
25 template <typename Type>
26 Type neg(Type op);
27
28 template <typename Type>
29 Type convert();
30
31 void display(int x);
32 void display(double x);
33 void done() const;
34 void reset();
35 void error(char const *msg);
36 int lex();
37 void print();
38
39 static double d(int i);
40
41 // support functions for parse():
42
43 void executeAction(int d_ruleNr);
44 void errorRecovery();
45 int lookup(bool recovery);
46 void nextToken();
47 void print__();
48 };
49
50 inline double Parser::d(int i)
51 {
52 return i;
53 }
54
55 template <typename Type>
56 Type Parser::exec(char c, Type left, Type right)
57 {
58 d_rpn << " " << c << " ";
59 return c == '*' ? left * right : left + right;
60 }
61
62 template <typename Type>
63 Type Parser::neg(Type op)
64 {
65 d_rpn << " n ";
66 return -op;
67 }
68
69 template <typename Type>
70 Type Parser::convert()
71 {
72 Type ret = FBB::A2x(d_scanner.matched());
73 d_rpn << " " << ret << " ";
74 return ret;
75 }
76
77 inline void Parser::error(char const *msg)
78 {
79 std::cerr << msg << '\n';
80 }
81
82 inline int Parser::lex()
83 {
84 return d_scanner.lex();
85 }
86
87 inline void Parser::print()
88 {}
89
90 #endif