forked from kdt3rd/lime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rule.h
103 lines (78 loc) · 2.8 KB
/
Rule.h
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
/// @file Rule.h
/// @brief File that declares a production rule.
///
///
//
//
// Copyright © 2003-2013 Kimball Thurston
//
// This program is free software; you can redisribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
//
#ifndef _Rule_h_
#define _Rule_h_
#include <iosfwd>
#include <vector>
#include <string>
////////////////////////////////////////
class Symbol;
class Rule
{
public:
typedef std::pair< std::string, std::string > RHSEntry;
typedef std::vector< RHSEntry > RHSList;
typedef RHSList::iterator RHSListIter;
typedef RHSList::const_iterator RHSListConstIter;
Rule( const std::string &lhs, size_t ruleIndex );
~Rule( void );
/// The left hand side for the rule
inline const std::string &getLHS( void ) const { return myLHS; }
Symbol *getLHSSymbol( void ) const;
/// Rule index for use during rule production analysis.
inline size_t getRuleIndex( void ) const { return myRuleIndex; }
/// Alias for left hand side.
void setLHSAlias( const std::string &lhsalias );
inline const std::string &getLHSAlias( void ) const { return myLHSAlias; }
/// Line number for the rule.
void setRuleLine( int line );
inline int getRuleLine( void ) const { return myRuleLine; }
/// The RHS symbols.
void setRHS( const RHSList &rhs );
inline const RHSList &getRHS( void ) const { return myRHSList; }
/// The code to run when the rule is reduced.
void setCode( int codeline, const std::string &code );
inline int getCodeLine( void ) const { return myCodeLine; }
inline const std::string &getCode( void ) const { return myCode; }
// The precedence symbol for this rule
void setPrecedence( const std::string &precSym );
inline const std::string &getPrecedence( void ) const { return myPrecedence;}
Symbol *getPrecedenceSymbol( void ) const;
void setCanReduce( bool on_off );
inline bool canReduce( void ) const { return myCanReduce; }
void print( std::ostream &out ) const;
private:
Rule( const Rule &other );
Rule &operator=( const Rule &other );
size_t myRuleIndex;
std::string myLHS;
std::string myLHSAlias;
int myRuleLine;
RHSList myRHSList;
int myCodeLine;
std::string myCode;
std::string myPrecedence;
bool myCanReduce;
};
#endif /* _Rule_h_ */