forked from davidsiaw/coco-r-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DFA.h
executable file
·132 lines (111 loc) · 4.57 KB
/
DFA.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
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
131
132
/*-------------------------------------------------------------------------
DFA -- Generation of the Scanner Automaton
Compiler Generator Coco/R,
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
extended by M. Loeberbauer & A. Woess, Univ. of Linz
ported to C++ by Csaba Balazs, University of Szeged
with improvements by Pat Terry, Rhodes University
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 2, 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.
As an exception, it is allowed to write an extension of Coco/R that is
used as a plugin in non-free software.
If not otherwise stated, any source code generated by Coco/R (other than
Coco/R itself) does not fall under the GNU General Public License.
-------------------------------------------------------------------------*/
#if !defined(COCO_DFA_H__)
#define COCO_DFA_H__
#include <stddef.h>
#include "Action.h"
#include "Comment.h"
#include "State.h"
#include "Symbol.h"
#include "Melted.h"
#include "Node.h"
#include "Target.h"
namespace Coco {
class Parser;
class Tab;
class BitArray;
class DFA
{
public:
int maxStates;
int lastStateNr; // highest state number
State *firstState;
State *lastState; // last allocated state
int lastSimState; // last non melted state
FILE* fram; // scanner frame input
FILE* gen; // generated scanner file
Symbol *curSy; // current token to be recognized (in FindTrans)
Node *curGraph; // start of graph for current token (in FindTrans)
bool ignoreCase; // true if input should be treated case-insensitively
bool dirtyDFA; // DFA may become nondeterministic in MatchLiteral
bool hasCtxMoves; // DFA has context transitions
bool *existLabel; // checking the Labels (in order to avoid the warning messages)
Parser *parser; // other Coco objects
Tab *tab;
Errors *errors;
FILE* trace;
Melted *firstMelted; // head of melted state list
Comment *firstComment; // list of comments
//---------- Output primitives
wchar_t* Ch(wchar_t ch);
wchar_t* ChCond(wchar_t ch);
void PutRange(CharSet *s);
//---------- State handling
State* NewState();
void NewTransition(State *from, State *to, int typ, int sym, int tc);
void CombineShifts();
void FindUsedStates(State *state, BitArray *used);
void DeleteRedundantStates();
State* TheState(Node *p);
void Step(State *from, Node *p, BitArray *stepped);
void NumberNodes(Node *p, State *state, bool renumIter);
void FindTrans (Node *p, bool start, BitArray *marked);
void ConvertToStates(Node *p, Symbol *sym);
// match string against current automaton; store it either as a fixedToken or as a litToken
void MatchLiteral(wchar_t* s, Symbol *sym);
void SplitActions(State *state, Action *a, Action *b);
bool Overlap(Action *a, Action *b);
bool MakeUnique(State *state); // return true if actions were split
void MeltStates(State *state);
void FindCtxStates();
void MakeDeterministic();
void PrintStates();
void CheckLabels();
//---------------------------- actions --------------------------------
Action* FindAction(State *state, wchar_t ch);
void GetTargetStates(Action *a, BitArray* &targets, Symbol* &endOf, bool &ctx);
//------------------------- melted states ------------------------------
Melted* NewMelted(BitArray *set, State *state);
BitArray* MeltedSet(int nr);
Melted* StateWithSet(BitArray *s);
//------------------------ comments --------------------------------
wchar_t* CommentStr(Node *p);
void NewComment(Node *from, Node *to, bool nested);
//------------------------ scanner generation ----------------------
void GenComBody(Comment *com);
void GenCommentHeader(Comment *com, int i);
void GenComment(Comment *com, int i);
void CopyFramePart(const wchar_t* stop);
wchar_t* SymName(Symbol *sym); // real name value is stored in Tab.literals
void GenLiterals ();
int GenNamespaceOpen(const wchar_t* nsName);
void GenNamespaceClose(int nrOfNs);
void WriteState(State *state);
void WriteStartTab();
void OpenGen(const wchar_t* genName, bool backUp); /* pdt */
void WriteScanner();
DFA(Parser *parser);
};
}; // namespace
#endif // !defined(COCO_DFA_H__)