ruco-cpp 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +17 -0
- data/bin/console +14 -0
- data/bin/ruco +30 -0
- data/bin/setup +7 -0
- data/data/ruco/Parser.frame +359 -0
- data/data/ruco/Scanner.frame +896 -0
- data/data/ruco/picojson/Changes +14 -0
- data/data/ruco/picojson/LICENSE +25 -0
- data/data/ruco/picojson/Makefile +8 -0
- data/data/ruco/picojson/README.mkdn +183 -0
- data/data/ruco/picojson/examples/github-issues.cc +110 -0
- data/data/ruco/picojson/examples/iostream.cc +70 -0
- data/data/ruco/picojson/examples/streaming.cc +76 -0
- data/data/ruco/picojson/picojson.h +1299 -0
- data/ext/cocor/Action.cpp +81 -0
- data/ext/cocor/Action.h +59 -0
- data/ext/cocor/ArrayList.cpp +79 -0
- data/ext/cocor/ArrayList.h +52 -0
- data/ext/cocor/BitArray.cpp +156 -0
- data/ext/cocor/BitArray.h +68 -0
- data/ext/cocor/CharClass.cpp +42 -0
- data/ext/cocor/CharClass.h +48 -0
- data/ext/cocor/CharSet.cpp +166 -0
- data/ext/cocor/CharSet.h +68 -0
- data/ext/cocor/Coco.atg +528 -0
- data/ext/cocor/Coco.cpp +173 -0
- data/ext/cocor/Comment.cpp +45 -0
- data/ext/cocor/Comment.h +51 -0
- data/ext/cocor/Copyright.frame +27 -0
- data/ext/cocor/DFA.cpp +865 -0
- data/ext/cocor/DFA.h +132 -0
- data/ext/cocor/Generator.cpp +182 -0
- data/ext/cocor/Generator.h +61 -0
- data/ext/cocor/Graph.h +59 -0
- data/ext/cocor/HashTable.cpp +115 -0
- data/ext/cocor/HashTable.h +84 -0
- data/ext/cocor/Makefile +11 -0
- data/ext/cocor/Melted.cpp +39 -0
- data/ext/cocor/Melted.h +51 -0
- data/ext/cocor/Node.cpp +69 -0
- data/ext/cocor/Node.h +86 -0
- data/ext/cocor/Parser.cpp +925 -0
- data/ext/cocor/Parser.frame +326 -0
- data/ext/cocor/Parser.h +153 -0
- data/ext/cocor/ParserGen.cpp +486 -0
- data/ext/cocor/ParserGen.h +99 -0
- data/ext/cocor/Position.cpp +37 -0
- data/ext/cocor/Position.h +46 -0
- data/ext/cocor/README.md +12 -0
- data/ext/cocor/Scanner.cpp +833 -0
- data/ext/cocor/Scanner.frame +897 -0
- data/ext/cocor/Scanner.h +291 -0
- data/ext/cocor/Sets.h +84 -0
- data/ext/cocor/SortedList.cpp +141 -0
- data/ext/cocor/SortedList.h +68 -0
- data/ext/cocor/State.cpp +77 -0
- data/ext/cocor/State.h +55 -0
- data/ext/cocor/StringBuilder.cpp +88 -0
- data/ext/cocor/StringBuilder.h +29 -0
- data/ext/cocor/Symbol.cpp +61 -0
- data/ext/cocor/Symbol.h +70 -0
- data/ext/cocor/Tab.cpp +1248 -0
- data/ext/cocor/Tab.h +245 -0
- data/ext/cocor/Target.cpp +41 -0
- data/ext/cocor/Target.h +48 -0
- data/ext/cocor/build.bat +3 -0
- data/ext/cocor/build.sh +4 -0
- data/ext/cocor/coc.bat +1 -0
- data/ext/cocor/coc.sh +2 -0
- data/ext/cocor/cocor_ruby_ext.cpp +124 -0
- data/ext/cocor/cygBuild.bat +1 -0
- data/ext/cocor/extconf.rb +5 -0
- data/ext/cocor/mingwbuild.bat +2 -0
- data/ext/cocor/mkmf.log +57 -0
- data/ext/cocor/zipsources.bat +1 -0
- data/lib/cocor.rb +14 -0
- data/lib/ruco/version.rb +3 -0
- data/lib/ruco.rb +728 -0
- metadata +195 -0
data/ext/cocor/DFA.h
ADDED
@@ -0,0 +1,132 @@
|
|
1
|
+
/*-------------------------------------------------------------------------
|
2
|
+
DFA -- Generation of the Scanner Automaton
|
3
|
+
Compiler Generator Coco/R,
|
4
|
+
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
|
5
|
+
extended by M. Loeberbauer & A. Woess, Univ. of Linz
|
6
|
+
ported to C++ by Csaba Balazs, University of Szeged
|
7
|
+
with improvements by Pat Terry, Rhodes University
|
8
|
+
|
9
|
+
This program is free software; you can redistribute it and/or modify it
|
10
|
+
under the terms of the GNU General Public License as published by the
|
11
|
+
Free Software Foundation; either version 2, or (at your option) any
|
12
|
+
later version.
|
13
|
+
|
14
|
+
This program is distributed in the hope that it will be useful, but
|
15
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
16
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
17
|
+
for more details.
|
18
|
+
|
19
|
+
You should have received a copy of the GNU General Public License along
|
20
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
21
|
+
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
22
|
+
|
23
|
+
As an exception, it is allowed to write an extension of Coco/R that is
|
24
|
+
used as a plugin in non-free software.
|
25
|
+
|
26
|
+
If not otherwise stated, any source code generated by Coco/R (other than
|
27
|
+
Coco/R itself) does not fall under the GNU General Public License.
|
28
|
+
-------------------------------------------------------------------------*/
|
29
|
+
|
30
|
+
#if !defined(COCO_DFA_H__)
|
31
|
+
#define COCO_DFA_H__
|
32
|
+
|
33
|
+
#include <stddef.h>
|
34
|
+
#include "Action.h"
|
35
|
+
#include "Comment.h"
|
36
|
+
#include "State.h"
|
37
|
+
#include "Symbol.h"
|
38
|
+
#include "Melted.h"
|
39
|
+
#include "Node.h"
|
40
|
+
#include "Target.h"
|
41
|
+
|
42
|
+
namespace Coco {
|
43
|
+
|
44
|
+
|
45
|
+
class Parser;
|
46
|
+
class Tab;
|
47
|
+
class BitArray;
|
48
|
+
|
49
|
+
class DFA
|
50
|
+
{
|
51
|
+
public:
|
52
|
+
int maxStates;
|
53
|
+
int lastStateNr; // highest state number
|
54
|
+
State *firstState;
|
55
|
+
State *lastState; // last allocated state
|
56
|
+
int lastSimState; // last non melted state
|
57
|
+
FILE* fram; // scanner frame input
|
58
|
+
FILE* gen; // generated scanner file
|
59
|
+
Symbol *curSy; // current token to be recognized (in FindTrans)
|
60
|
+
Node *curGraph; // start of graph for current token (in FindTrans)
|
61
|
+
bool ignoreCase; // true if input should be treated case-insensitively
|
62
|
+
bool dirtyDFA; // DFA may become nondeterministic in MatchLiteral
|
63
|
+
bool hasCtxMoves; // DFA has context transitions
|
64
|
+
bool *existLabel; // checking the Labels (in order to avoid the warning messages)
|
65
|
+
|
66
|
+
Parser *parser; // other Coco objects
|
67
|
+
Tab *tab;
|
68
|
+
Errors *errors;
|
69
|
+
FILE* trace;
|
70
|
+
|
71
|
+
Melted *firstMelted; // head of melted state list
|
72
|
+
Comment *firstComment; // list of comments
|
73
|
+
|
74
|
+
//---------- Output primitives
|
75
|
+
wchar_t* Ch(wchar_t ch);
|
76
|
+
wchar_t* ChCond(wchar_t ch);
|
77
|
+
void PutRange(CharSet *s);
|
78
|
+
|
79
|
+
//---------- State handling
|
80
|
+
State* NewState();
|
81
|
+
void NewTransition(State *from, State *to, int typ, int sym, int tc);
|
82
|
+
void CombineShifts();
|
83
|
+
void FindUsedStates(State *state, BitArray *used);
|
84
|
+
void DeleteRedundantStates();
|
85
|
+
State* TheState(Node *p);
|
86
|
+
void Step(State *from, Node *p, BitArray *stepped);
|
87
|
+
void NumberNodes(Node *p, State *state, bool renumIter);
|
88
|
+
void FindTrans (Node *p, bool start, BitArray *marked);
|
89
|
+
void ConvertToStates(Node *p, Symbol *sym);
|
90
|
+
// match string against current automaton; store it either as a fixedToken or as a litToken
|
91
|
+
void MatchLiteral(wchar_t* s, Symbol *sym);
|
92
|
+
void SplitActions(State *state, Action *a, Action *b);
|
93
|
+
bool Overlap(Action *a, Action *b);
|
94
|
+
bool MakeUnique(State *state); // return true if actions were split
|
95
|
+
void MeltStates(State *state);
|
96
|
+
void FindCtxStates();
|
97
|
+
void MakeDeterministic();
|
98
|
+
void PrintStates();
|
99
|
+
void CheckLabels();
|
100
|
+
|
101
|
+
//---------------------------- actions --------------------------------
|
102
|
+
Action* FindAction(State *state, wchar_t ch);
|
103
|
+
void GetTargetStates(Action *a, BitArray* &targets, Symbol* &endOf, bool &ctx);
|
104
|
+
|
105
|
+
//------------------------- melted states ------------------------------
|
106
|
+
Melted* NewMelted(BitArray *set, State *state);
|
107
|
+
BitArray* MeltedSet(int nr);
|
108
|
+
Melted* StateWithSet(BitArray *s);
|
109
|
+
|
110
|
+
//------------------------ comments --------------------------------
|
111
|
+
wchar_t* CommentStr(Node *p);
|
112
|
+
void NewComment(Node *from, Node *to, bool nested);
|
113
|
+
|
114
|
+
//------------------------ scanner generation ----------------------
|
115
|
+
void GenComBody(Comment *com);
|
116
|
+
void GenCommentHeader(Comment *com, int i);
|
117
|
+
void GenComment(Comment *com, int i);
|
118
|
+
void CopyFramePart(const wchar_t* stop);
|
119
|
+
wchar_t* SymName(Symbol *sym); // real name value is stored in Tab.literals
|
120
|
+
void GenLiterals ();
|
121
|
+
int GenNamespaceOpen(const wchar_t* nsName);
|
122
|
+
void GenNamespaceClose(int nrOfNs);
|
123
|
+
void WriteState(State *state);
|
124
|
+
void WriteStartTab();
|
125
|
+
void OpenGen(const wchar_t* genName, bool backUp); /* pdt */
|
126
|
+
void WriteScanner();
|
127
|
+
DFA(Parser *parser);
|
128
|
+
};
|
129
|
+
|
130
|
+
}; // namespace
|
131
|
+
|
132
|
+
#endif // !defined(COCO_DFA_H__)
|
@@ -0,0 +1,182 @@
|
|
1
|
+
/*----------------------------------------------------------------------
|
2
|
+
Compiler Generator Coco/R,
|
3
|
+
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
|
4
|
+
extended by M. Loeberbauer & A. Woess, Univ. of Linz
|
5
|
+
ported to C++ by Csaba Balazs, University of Szeged
|
6
|
+
with improvements by Pat Terry, Rhodes University
|
7
|
+
|
8
|
+
This program is free software; you can redistribute it and/or modify it
|
9
|
+
under the terms of the GNU General Public License as published by the
|
10
|
+
Free Software Foundation; either version 2, or (at your option) any
|
11
|
+
later version.
|
12
|
+
|
13
|
+
This program is distributed in the hope that it will be useful, but
|
14
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
15
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
16
|
+
for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU General Public License along
|
19
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21
|
+
|
22
|
+
As an exception, it is allowed to write an extension of Coco/R that is
|
23
|
+
used as a plugin in non-free software.
|
24
|
+
|
25
|
+
If not otherwise stated, any source code generated by Coco/R (other than
|
26
|
+
Coco/R itself) does not fall under the GNU General Public License.
|
27
|
+
-----------------------------------------------------------------------*/
|
28
|
+
|
29
|
+
#include "Generator.h"
|
30
|
+
#include "Scanner.h"
|
31
|
+
|
32
|
+
namespace Coco {
|
33
|
+
|
34
|
+
Generator::Generator(Tab *tab, Errors *errors) {
|
35
|
+
this->errors = errors;
|
36
|
+
this->tab = tab;
|
37
|
+
fram = NULL;
|
38
|
+
gen = NULL;
|
39
|
+
frameFile = NULL;
|
40
|
+
}
|
41
|
+
|
42
|
+
FILE* Generator::OpenFrame(const wchar_t* frame) {
|
43
|
+
if (coco_string_length(tab->frameDir) != 0) {
|
44
|
+
frameFile = coco_string_create_append(tab->frameDir, L"/");
|
45
|
+
coco_string_merge(frameFile, frame);
|
46
|
+
char *chFrameFile = coco_string_create_char(frameFile);
|
47
|
+
fram = fopen(chFrameFile, "r");
|
48
|
+
delete [] chFrameFile;
|
49
|
+
}
|
50
|
+
if (fram == NULL) {
|
51
|
+
delete [] frameFile;
|
52
|
+
frameFile = coco_string_create_append(tab->srcDir, frame); /* pdt */
|
53
|
+
char *chFrameFile = coco_string_create_char(frameFile);
|
54
|
+
fram = fopen(chFrameFile, "r");
|
55
|
+
delete [] chFrameFile;
|
56
|
+
}
|
57
|
+
if (fram == NULL) {
|
58
|
+
wchar_t *message = coco_string_create_append(L"-- Cannot find : ", frame);
|
59
|
+
errors->Exception(message);
|
60
|
+
delete [] message;
|
61
|
+
}
|
62
|
+
|
63
|
+
return fram;
|
64
|
+
}
|
65
|
+
|
66
|
+
|
67
|
+
FILE* Generator::OpenGen(const wchar_t *genName) { /* pdt */
|
68
|
+
wchar_t *fn = coco_string_create_append(tab->outDir, genName); /* pdt */
|
69
|
+
char *chFn = coco_string_create_char(fn);
|
70
|
+
|
71
|
+
if ((gen = fopen(chFn, "r")) != NULL) {
|
72
|
+
fclose(gen);
|
73
|
+
wchar_t *oldName = coco_string_create_append(fn, L".old");
|
74
|
+
char *chOldName = coco_string_create_char(oldName);
|
75
|
+
remove(chOldName); rename(chFn, chOldName); // copy with overwrite
|
76
|
+
coco_string_delete(chOldName);
|
77
|
+
coco_string_delete(oldName);
|
78
|
+
}
|
79
|
+
if ((gen = fopen(chFn, "w")) == NULL) {
|
80
|
+
wchar_t *message = coco_string_create_append(L"-- Cannot generate : ", genName);
|
81
|
+
errors->Exception(message);
|
82
|
+
delete [] message;
|
83
|
+
}
|
84
|
+
coco_string_delete(chFn);
|
85
|
+
coco_string_delete(fn);
|
86
|
+
|
87
|
+
return gen;
|
88
|
+
}
|
89
|
+
|
90
|
+
|
91
|
+
void Generator::GenCopyright() {
|
92
|
+
FILE *file = NULL;
|
93
|
+
|
94
|
+
if (coco_string_length(tab->frameDir) != 0) {
|
95
|
+
wchar_t *copyFr = coco_string_create_append(tab->frameDir, L"/Copyright.frame");
|
96
|
+
char *chCopyFr = coco_string_create_char(copyFr);
|
97
|
+
file = fopen(chCopyFr, "r");
|
98
|
+
delete [] copyFr;
|
99
|
+
delete [] chCopyFr;
|
100
|
+
}
|
101
|
+
if (file == NULL) {
|
102
|
+
wchar_t *copyFr = coco_string_create_append(tab->srcDir, L"Copyright.frame");
|
103
|
+
char *chCopyFr = coco_string_create_char(copyFr);
|
104
|
+
file = fopen(chCopyFr, "r");
|
105
|
+
delete [] copyFr;
|
106
|
+
delete [] chCopyFr;
|
107
|
+
}
|
108
|
+
if (file == NULL) {
|
109
|
+
return;
|
110
|
+
}
|
111
|
+
|
112
|
+
FILE *scannerFram = fram;
|
113
|
+
fram = file;
|
114
|
+
|
115
|
+
CopyFramePart(NULL);
|
116
|
+
fram = scannerFram;
|
117
|
+
|
118
|
+
fclose(file);
|
119
|
+
}
|
120
|
+
|
121
|
+
void Generator::GenPrefixFromNamespace() {
|
122
|
+
const wchar_t *nsName = tab->nsName;
|
123
|
+
if (nsName == NULL || coco_string_length(nsName) == 0) {
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
const int len = coco_string_length(nsName);
|
127
|
+
int startPos = 0;
|
128
|
+
do {
|
129
|
+
int curLen = coco_string_indexof(nsName + startPos, COCO_CPP_NAMESPACE_SEPARATOR);
|
130
|
+
if (curLen == -1) { curLen = len - startPos; }
|
131
|
+
wchar_t *curNs = coco_string_create(nsName, startPos, curLen);
|
132
|
+
fwprintf(gen, L"%ls_", curNs);
|
133
|
+
coco_string_delete(curNs);
|
134
|
+
startPos = startPos + curLen + 1;
|
135
|
+
} while (startPos < len);
|
136
|
+
}
|
137
|
+
|
138
|
+
void Generator::SkipFramePart(const wchar_t *stop) {
|
139
|
+
CopyFramePart(stop, false);
|
140
|
+
}
|
141
|
+
|
142
|
+
void Generator::CopyFramePart(const wchar_t *stop) {
|
143
|
+
CopyFramePart(stop, true);
|
144
|
+
}
|
145
|
+
|
146
|
+
void Generator::CopyFramePart(const wchar_t* stop, bool generateOutput) {
|
147
|
+
wchar_t startCh = 0;
|
148
|
+
int endOfStopString = 0;
|
149
|
+
wchar_t ch = 0;
|
150
|
+
|
151
|
+
if (stop != NULL) {
|
152
|
+
startCh = stop[0];
|
153
|
+
endOfStopString = coco_string_length(stop)-1;
|
154
|
+
}
|
155
|
+
|
156
|
+
fwscanf(fram, L"%lc", &ch); // fram.ReadByte();
|
157
|
+
while (!feof(fram)) { // ch != EOF
|
158
|
+
if (stop != NULL && ch == startCh) {
|
159
|
+
int i = 0;
|
160
|
+
do {
|
161
|
+
if (i == endOfStopString) return; // stop[0..i] found
|
162
|
+
fwscanf(fram, L"%lc", &ch); i++;
|
163
|
+
} while (ch == stop[i]);
|
164
|
+
// stop[0..i-1] found; continue with last read character
|
165
|
+
if (generateOutput) {
|
166
|
+
wchar_t *subStop = coco_string_create(stop, 0, i);
|
167
|
+
fwprintf(gen, L"%ls", subStop);
|
168
|
+
coco_string_delete(subStop);
|
169
|
+
}
|
170
|
+
} else {
|
171
|
+
if (generateOutput) { fwprintf(gen, L"%lc", ch); }
|
172
|
+
fwscanf(fram, L"%lc", &ch);
|
173
|
+
}
|
174
|
+
}
|
175
|
+
if (stop != NULL) {
|
176
|
+
wchar_t *message = coco_string_create_append(L" -- Incomplete or corrupt frame file: ", frameFile);
|
177
|
+
errors->Exception(message);
|
178
|
+
delete [] message;
|
179
|
+
}
|
180
|
+
}
|
181
|
+
|
182
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
/*----------------------------------------------------------------------
|
2
|
+
Compiler Generator Coco/R,
|
3
|
+
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
|
4
|
+
extended by M. Loeberbauer & A. Woess, Univ. of Linz
|
5
|
+
ported to C++ by Csaba Balazs, University of Szeged
|
6
|
+
with improvements by Pat Terry, Rhodes University
|
7
|
+
|
8
|
+
This program is free software; you can redistribute it and/or modify it
|
9
|
+
under the terms of the GNU General Public License as published by the
|
10
|
+
Free Software Foundation; either version 2, or (at your option) any
|
11
|
+
later version.
|
12
|
+
|
13
|
+
This program is distributed in the hope that it will be useful, but
|
14
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
15
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
16
|
+
for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU General Public License along
|
19
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21
|
+
|
22
|
+
As an exception, it is allowed to write an extension of Coco/R that is
|
23
|
+
used as a plugin in non-free software.
|
24
|
+
|
25
|
+
If not otherwise stated, any source code generated by Coco/R (other than
|
26
|
+
Coco/R itself) does not fall under the GNU General Public License.
|
27
|
+
-----------------------------------------------------------------------*/
|
28
|
+
|
29
|
+
#if !defined(COCO_GENERATOR_H__)
|
30
|
+
#define COCO_GENERATOR_H__
|
31
|
+
|
32
|
+
#include <stdio.h>
|
33
|
+
#include "Tab.h"
|
34
|
+
#include "Parser.h"
|
35
|
+
|
36
|
+
namespace Coco {
|
37
|
+
|
38
|
+
class Generator {
|
39
|
+
public:
|
40
|
+
Generator(Tab *tab, Errors *errors);
|
41
|
+
FILE* OpenFrame(const wchar_t* frame);
|
42
|
+
FILE* OpenGen(const wchar_t *genName);
|
43
|
+
void GenCopyright();
|
44
|
+
void GenPrefixFromNamespace();
|
45
|
+
void SkipFramePart(const wchar_t *stop);
|
46
|
+
void CopyFramePart(const wchar_t *stop);
|
47
|
+
|
48
|
+
private:
|
49
|
+
FILE* fram;
|
50
|
+
FILE* gen;
|
51
|
+
Tab *tab;
|
52
|
+
wchar_t* frameFile;
|
53
|
+
Errors *errors;
|
54
|
+
|
55
|
+
void CopyFramePart(const wchar_t* stop, bool generateOutput);
|
56
|
+
|
57
|
+
};
|
58
|
+
|
59
|
+
} // namespace
|
60
|
+
|
61
|
+
#endif // !defined(COCO_GENERATOR_H__)
|
data/ext/cocor/Graph.h
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
/*-------------------------------------------------------------------------
|
2
|
+
Compiler Generator Coco/R,
|
3
|
+
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
|
4
|
+
extended by M. Loeberbauer & A. Woess, Univ. of Linz
|
5
|
+
ported to C++ by Csaba Balazs, University of Szeged
|
6
|
+
with improvements by Pat Terry, Rhodes University
|
7
|
+
|
8
|
+
This program is free software; you can redistribute it and/or modify it
|
9
|
+
under the terms of the GNU General Public License as published by the
|
10
|
+
Free Software Foundation; either version 2, or (at your option) any
|
11
|
+
later version.
|
12
|
+
|
13
|
+
This program is distributed in the hope that it will be useful, but
|
14
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
15
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
16
|
+
for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU General Public License along
|
19
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21
|
+
|
22
|
+
As an exception, it is allowed to write an extension of Coco/R that is
|
23
|
+
used as a plugin in non-free software.
|
24
|
+
|
25
|
+
If not otherwise stated, any source code generated by Coco/R (other than
|
26
|
+
Coco/R itself) does not fall under the GNU General Public License.
|
27
|
+
-------------------------------------------------------------------------*/
|
28
|
+
|
29
|
+
#if !defined(COCO_GRAPH_H__)
|
30
|
+
#define COCO_GRAPH_H__
|
31
|
+
|
32
|
+
#include "Node.h"
|
33
|
+
|
34
|
+
namespace Coco {
|
35
|
+
|
36
|
+
class Graph {
|
37
|
+
public:
|
38
|
+
Node *l; // left end of graph = head
|
39
|
+
Node *r; // right end of graph = list of nodes to be linked to successor graph
|
40
|
+
|
41
|
+
Graph() {
|
42
|
+
l = NULL; r = NULL;
|
43
|
+
}
|
44
|
+
|
45
|
+
Graph(Node *left, Node *right) {
|
46
|
+
l = left; r = right;
|
47
|
+
}
|
48
|
+
|
49
|
+
Graph(Node *p) {
|
50
|
+
l = p; r = p;
|
51
|
+
}
|
52
|
+
|
53
|
+
virtual ~Graph() {
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
}; // namespace
|
58
|
+
|
59
|
+
#endif // !defined(COCO_GRAPH_H__)
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/*-------------------------------------------------------------------------
|
2
|
+
Compiler Generator Coco/R,
|
3
|
+
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
|
4
|
+
extended by M. Loeberbauer & A. Woess, Univ. of Linz
|
5
|
+
ported to C++ by Csaba Balazs, University of Szeged
|
6
|
+
with improvements by Pat Terry, Rhodes University
|
7
|
+
|
8
|
+
This program is free software; you can redistribute it and/or modify it
|
9
|
+
under the terms of the GNU General Public License as published by the
|
10
|
+
Free Software Foundation; either version 2, or (at your option) any
|
11
|
+
later version.
|
12
|
+
|
13
|
+
This program is distributed in the hope that it will be useful, but
|
14
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
15
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
16
|
+
for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU General Public License along
|
19
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21
|
+
|
22
|
+
As an exception, it is allowed to write an extension of Coco/R that is
|
23
|
+
used as a plugin in non-free software.
|
24
|
+
|
25
|
+
If not otherwise stated, any source code generated by Coco/R (other than
|
26
|
+
Coco/R itself) does not fall under the GNU General Public License.
|
27
|
+
-------------------------------------------------------------------------*/
|
28
|
+
|
29
|
+
#include <memory.h>
|
30
|
+
#include <stdio.h>
|
31
|
+
#include "HashTable.h"
|
32
|
+
#include "Scanner.h"
|
33
|
+
|
34
|
+
namespace Coco {
|
35
|
+
|
36
|
+
HashTable::HashTable(int size) {
|
37
|
+
this->size = size;
|
38
|
+
data = new Obj*[size];
|
39
|
+
memset(data, 0, size * sizeof(Obj*));
|
40
|
+
}
|
41
|
+
|
42
|
+
HashTable::~HashTable() {
|
43
|
+
for (int i = 0; i < size; ++i) {
|
44
|
+
Obj *o = data[i];
|
45
|
+
while (o != NULL) {
|
46
|
+
Obj *del = o;
|
47
|
+
o = o->next;
|
48
|
+
delete del;
|
49
|
+
}
|
50
|
+
}
|
51
|
+
delete[] data;
|
52
|
+
data = NULL;
|
53
|
+
};
|
54
|
+
|
55
|
+
HashTable::Obj* HashTable::Get0(wchar_t *key) const {
|
56
|
+
int k = coco_string_hash(key) % size;
|
57
|
+
HashTable::Obj *o = data[k];
|
58
|
+
while (o != NULL && !coco_string_equal(key, o->key)) {
|
59
|
+
o = o->next;
|
60
|
+
}
|
61
|
+
return o;
|
62
|
+
}
|
63
|
+
|
64
|
+
void HashTable::Set(wchar_t *key, void *val) {
|
65
|
+
HashTable::Obj *o = Get0(key);
|
66
|
+
if (o == NULL) {
|
67
|
+
// new entry
|
68
|
+
int k = coco_string_hash(key) % size;
|
69
|
+
o = new Obj();
|
70
|
+
o->key = key;
|
71
|
+
o->val = val;
|
72
|
+
o->next = data[k];
|
73
|
+
data[k] = o;
|
74
|
+
} else {
|
75
|
+
// exist entry - overwrite
|
76
|
+
o->val = val;
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
void* HashTable::Get(wchar_t *key) const {
|
81
|
+
HashTable::Obj *o = Get0(key);
|
82
|
+
if (o != NULL) {
|
83
|
+
return o->val;
|
84
|
+
}
|
85
|
+
return NULL;
|
86
|
+
}
|
87
|
+
|
88
|
+
Iterator* HashTable::GetIterator() {
|
89
|
+
return new HashTable::Iter(this);
|
90
|
+
}
|
91
|
+
|
92
|
+
HashTable::Iter::Iter(HashTable *ht) {
|
93
|
+
this->ht = ht;
|
94
|
+
this->pos = 0;
|
95
|
+
this->cur = NULL;
|
96
|
+
}
|
97
|
+
|
98
|
+
bool HashTable::Iter::HasNext() {
|
99
|
+
while (cur == NULL && pos < ht->size) {
|
100
|
+
cur = ht->data[pos];
|
101
|
+
++pos;
|
102
|
+
}
|
103
|
+
return cur != NULL;
|
104
|
+
}
|
105
|
+
|
106
|
+
DictionaryEntry* HashTable::Iter::Next() {
|
107
|
+
if (!HasNext()) {
|
108
|
+
return NULL;
|
109
|
+
}
|
110
|
+
Obj *next = cur;
|
111
|
+
cur = cur->next;
|
112
|
+
return next;
|
113
|
+
}
|
114
|
+
|
115
|
+
}; // namespace
|
@@ -0,0 +1,84 @@
|
|
1
|
+
/*-------------------------------------------------------------------------
|
2
|
+
Compiler Generator Coco/R,
|
3
|
+
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
|
4
|
+
extended by M. Loeberbauer & A. Woess, Univ. of Linz
|
5
|
+
ported to C++ by Csaba Balazs, University of Szeged
|
6
|
+
with improvements by Pat Terry, Rhodes University
|
7
|
+
|
8
|
+
This program is free software; you can redistribute it and/or modify it
|
9
|
+
under the terms of the GNU General Public License as published by the
|
10
|
+
Free Software Foundation; either version 2, or (at your option) any
|
11
|
+
later version.
|
12
|
+
|
13
|
+
This program is distributed in the hope that it will be useful, but
|
14
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
15
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
16
|
+
for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU General Public License along
|
19
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21
|
+
|
22
|
+
As an exception, it is allowed to write an extension of Coco/R that is
|
23
|
+
used as a plugin in non-free software.
|
24
|
+
|
25
|
+
If not otherwise stated, any source code generated by Coco/R (other than
|
26
|
+
Coco/R itself) does not fall under the GNU General Public License.
|
27
|
+
-------------------------------------------------------------------------*/
|
28
|
+
|
29
|
+
#if !defined(COCO_HASHTABLE_H__)
|
30
|
+
#define COCO_HASHTABLE_H__
|
31
|
+
|
32
|
+
#include <wchar.h>
|
33
|
+
|
34
|
+
namespace Coco {
|
35
|
+
|
36
|
+
class DictionaryEntry {
|
37
|
+
public:
|
38
|
+
wchar_t *key;
|
39
|
+
void *val;
|
40
|
+
};
|
41
|
+
|
42
|
+
class Iterator {
|
43
|
+
public:
|
44
|
+
virtual bool HasNext() = 0;
|
45
|
+
virtual DictionaryEntry* Next() = 0;
|
46
|
+
};
|
47
|
+
|
48
|
+
class HashTable
|
49
|
+
{
|
50
|
+
public:
|
51
|
+
HashTable(int size = 128);
|
52
|
+
virtual ~HashTable();
|
53
|
+
|
54
|
+
virtual void Set(wchar_t *key, void *value);
|
55
|
+
virtual void* Get(wchar_t *key) const;
|
56
|
+
inline void* operator[](wchar_t *key) const { return Get(key); };
|
57
|
+
virtual Iterator* GetIterator();
|
58
|
+
|
59
|
+
private:
|
60
|
+
class Obj : public DictionaryEntry {
|
61
|
+
public:
|
62
|
+
Obj *next;
|
63
|
+
};
|
64
|
+
|
65
|
+
class Iter : public Iterator {
|
66
|
+
private:
|
67
|
+
HashTable *ht;
|
68
|
+
int pos;
|
69
|
+
Obj* cur;
|
70
|
+
|
71
|
+
public:
|
72
|
+
Iter(HashTable *ht);
|
73
|
+
virtual bool HasNext();
|
74
|
+
virtual DictionaryEntry* Next();
|
75
|
+
};
|
76
|
+
|
77
|
+
Obj* Get0(wchar_t *key) const;
|
78
|
+
Obj **data;
|
79
|
+
int size;
|
80
|
+
};
|
81
|
+
|
82
|
+
}; // namespace
|
83
|
+
|
84
|
+
#endif // !defined(COCO_HASHTABLE_H__)
|
data/ext/cocor/Makefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
/*-------------------------------------------------------------------------
|
2
|
+
Compiler Generator Coco/R,
|
3
|
+
Copyright (c) 1990, 2004 Hanspeter Moessenboeck, University of Linz
|
4
|
+
extended by M. Loeberbauer & A. Woess, Univ. of Linz
|
5
|
+
ported to C++ by Csaba Balazs, University of Szeged
|
6
|
+
with improvements by Pat Terry, Rhodes University
|
7
|
+
|
8
|
+
This program is free software; you can redistribute it and/or modify it
|
9
|
+
under the terms of the GNU General Public License as published by the
|
10
|
+
Free Software Foundation; either version 2, or (at your option) any
|
11
|
+
later version.
|
12
|
+
|
13
|
+
This program is distributed in the hope that it will be useful, but
|
14
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
15
|
+
or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
16
|
+
for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU General Public License along
|
19
|
+
with this program; if not, write to the Free Software Foundation, Inc.,
|
20
|
+
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
21
|
+
|
22
|
+
As an exception, it is allowed to write an extension of Coco/R that is
|
23
|
+
used as a plugin in non-free software.
|
24
|
+
|
25
|
+
If not otherwise stated, any source code generated by Coco/R (other than
|
26
|
+
Coco/R itself) does not fall under the GNU General Public License.
|
27
|
+
-------------------------------------------------------------------------*/
|
28
|
+
|
29
|
+
#include "Melted.h"
|
30
|
+
|
31
|
+
namespace Coco {
|
32
|
+
|
33
|
+
class BitArray;
|
34
|
+
|
35
|
+
Melted::Melted(BitArray *set, State *state) {
|
36
|
+
this->set = set; this->state = state;
|
37
|
+
}
|
38
|
+
|
39
|
+
}; // namespace
|