File: Parserbase.h

package info (click to toggle)
bisonc%2B%2B 6.09.02-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,984 kB
  • sloc: cpp: 9,375; ansic: 1,505; fortran: 1,134; makefile: 1,062; sh: 526; yacc: 84; lex: 60
file content (130 lines) | stat: -rw-r--r-- 2,738 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#ifndef ParserBase_h_included
#define ParserBase_h_included

#include <vector>
#include <iostream>

// $insert debugincludes
#include <iostream>
#include <sstream>
#include <string>
#include <map>
#include <iomanip>

namespace // anonymous
{
    struct PI_;
}


class ParserBase
{
    public:
// $insert tokens

    // Symbolic tokens:
    enum Tokens_
    {
        ID = 257,
        UNARY,
    };

// $insert STYPE
using STYPE_ = int;

    private:
        int d_stackIdx_;
        std::vector<size_t>   d_stateStack_;
        std::vector<STYPE_>  d_valueStack_;

    protected:
        enum Return_
        {
            PARSE_ACCEPT_ = 0,   // values used as parse()'s return values
            PARSE_ABORT_  = 1
        };
        enum ErrorRecovery_
        {
            DEFAULT_RECOVERY_MODE_,
            UNEXPECTED_TOKEN_,
        };
        bool        d_debug_;
        size_t      d_nErrors_;
        size_t      d_requiredTokens_;
        size_t      d_acceptedTokens_;
        int         d_token_;
        int         d_nextToken_;
        size_t      d_state_;
        STYPE_    *d_vsp_;
        STYPE_     d_val_;
        STYPE_     d_nextVal_;

        ParserBase();

// $insert debugdecl
        static std::ostringstream s_out_;

        std::string symbol_(int value) const;
        std::string stype_(char const *pre, STYPE_ const &semVal,
                            char const *post = "") const;
        static std::ostream &dflush_(std::ostream &out);
        void ABORT() const;
        void ACCEPT() const;
        void ERROR() const;
        void clearin();
        bool debug() const;
        void pop_(size_t count = 1);
        void push_(size_t nextState);
        void popToken_();
        void pushToken_(int token);
        void reduce_(PI_ const &productionInfo);
        void errorVerbose_();
        size_t top_() const;

    public:
        void setDebug(bool mode);
}; 

inline bool ParserBase::debug() const
{
    return d_debug_;
}

inline void ParserBase::setDebug(bool mode)
{
    d_debug_ = mode;
}

inline void ParserBase::ABORT() const
{
    // $insert debug
    if (d_debug_)
        s_out_ <<  "ABORT(): Parsing unsuccessful" << "\n" << dflush_;
    throw PARSE_ABORT_;
}

inline void ParserBase::ACCEPT() const
{
    // $insert debug
    if (d_debug_)
        s_out_ <<  "ACCEPT(): Parsing successful" << "\n" << dflush_;
    throw PARSE_ACCEPT_;
}

inline void ParserBase::ERROR() const
{
    // $insert debug
    if (d_debug_)
        s_out_ <<  "ERROR(): Forced error condition" << "\n" << dflush_;
    throw UNEXPECTED_TOKEN_;
}


// As a convenience, when including ParserBase.h its symbols are available as
// symbols in the class Parser, too.
#define Parser ParserBase


#endif