1 /* $Id: dfa.h 850 2008-03-24 01:05:08Z helly $ */
12 extern void prtCh(std::ostream
&, uint
, bool useTalx
= true);
13 extern void prtHex(std::ostream
&, uint
, bool useTalx
= true);
14 extern void prtChOrHex(std::ostream
&, uint
, bool useTalx
= true);
15 extern void printSpan(std::ostream
&, uint
, uint
);
31 virtual void emit(std::ostream
&, uint
, bool&, const std::string
&) const = 0;
32 virtual bool isRule() const;
33 virtual bool isMatch() const;
34 virtual bool isInitial() const;
35 virtual bool readAhead() const;
39 Action(const Action
& oth
)
43 Action
& operator = (const Action
& oth
)
51 class Match
: public Action
55 void emit(std::ostream
&, uint
, bool&, const std::string
&) const;
59 class Enter
: public Action
66 void emit(std::ostream
&, uint
, bool&, const std::string
&) const;
69 class Initial
: public Enter
75 Initial(State
*, uint
, bool);
76 void emit(std::ostream
&, uint
, bool&, const std::string
&) const;
77 bool isInitial() const;
80 class Save
: public Match
88 void emit(std::ostream
&, uint
, bool&, const std::string
&) const;
92 class Move
: public Action
97 void emit(std::ostream
&, uint
, bool&, const std::string
&) const;
100 class Accept
: public Action
104 typedef std::map
<uint
, State
*> RuleMap
;
112 Accept(State
*, uint
, uint
*, State
**);
113 void emit(std::ostream
&, uint
, bool&, const std::string
&) const;
114 void emitBinary(std::ostream
&o
, uint ind
, uint l
, uint r
, bool &readCh
) const;
119 Accept(const Accept
& oth
)
126 Accept
& operator=(const Accept
& oth
)
128 new(this) Accept(oth
);
134 class Rule
: public Action
141 Rule(State
*, RuleOp
*);
142 void emit(std::ostream
&, uint
, bool&, const std::string
&) const;
147 Rule (const Rule
& oth
)
152 Rule
& operator=(const Rule
& oth
)
168 uint
show(std::ostream
&, uint
) const;
185 uint nSpans
; // number of spans
186 uint wSpans
; // number of spans in wide mode
187 uint lSpans
; // number of low (non wide) spans
188 uint dSpans
; // number of decision spans (decide between g and b mode)
193 void genGoto( std::ostream
&, uint ind
, const State
*from
, const State
*next
, bool &readCh
);
194 void genBase( std::ostream
&, uint ind
, const State
*from
, const State
*next
, bool &readCh
, uint mask
) const;
195 void genLinear(std::ostream
&, uint ind
, const State
*from
, const State
*next
, bool &readCh
, uint mask
) const;
196 void genBinary(std::ostream
&, uint ind
, const State
*from
, const State
*next
, bool &readCh
, uint mask
) const;
197 void genSwitch(std::ostream
&, uint ind
, const State
*from
, const State
*next
, bool &readCh
, uint mask
) const;
198 void genCpGoto(std::ostream
&, uint ind
, const State
*from
, const State
*next
, bool &readCh
) const;
200 void unmap(Go
*, const State
*);
211 uint depth
; // for finding SCCs
223 void emit(std::ostream
&, uint
, bool&, const std::string
&) const;
224 friend std::ostream
& operator<<(std::ostream
&, const State
&);
225 friend std::ostream
& operator<<(std::ostream
&, const State
*);
229 State(const State
& oth
)
242 State
& operator = (const State
& oth
)
244 new(this) State(oth
);
260 const Char
*free_rep
;
268 DFA(Ins
*, uint
, uint
, uint
, const Char
*);
270 void addState(State
**, State
*);
271 State
*findState(Ins
**, uint
);
275 void findBaseState();
277 void emit(std::ostream
&, uint
&, const RegExpMap
*, const std::string
&, bool, bool&);
279 friend std::ostream
& operator<<(std::ostream
&, const DFA
&);
280 friend std::ostream
& operator<<(std::ostream
&, const DFA
*);
286 , nStates(oth
.nStates
)
292 DFA
& operator = (const DFA
& oth
)
300 inline Action::Action(State
*s
) : state(s
)
306 inline Action::~Action()
310 inline bool Action::isRule() const
315 inline bool Action::isMatch() const
320 inline bool Action::isInitial() const
325 inline bool Action::readAhead() const
327 return !isMatch() || (state
&& state
->next
&& state
->next
->action
&& !state
->next
->action
->isRule());
330 inline Match::Match(State
*s
) : Action(s
)
333 inline bool Match::isMatch() const
338 inline Enter::Enter(State
*s
, uint l
) : Action(s
), label(l
)
341 inline Initial::Initial(State
*s
, uint l
, bool b
) : Enter(s
, l
), setMarker(b
)
344 inline bool Initial::isInitial() const
349 inline Save::Save(State
*s
, uint i
) : Match(s
), selector(i
)
352 inline bool Save::isMatch() const
357 inline bool Rule::isRule() const
362 inline std::ostream
& operator<<(std::ostream
&o
, const State
*s
)
367 inline std::ostream
& operator<<(std::ostream
&o
, const DFA
*dfa
)
372 } // end namespace re2c