ruco-cpp 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +17 -0
  3. data/bin/console +14 -0
  4. data/bin/ruco +30 -0
  5. data/bin/setup +7 -0
  6. data/data/ruco/Parser.frame +359 -0
  7. data/data/ruco/Scanner.frame +896 -0
  8. data/data/ruco/picojson/Changes +14 -0
  9. data/data/ruco/picojson/LICENSE +25 -0
  10. data/data/ruco/picojson/Makefile +8 -0
  11. data/data/ruco/picojson/README.mkdn +183 -0
  12. data/data/ruco/picojson/examples/github-issues.cc +110 -0
  13. data/data/ruco/picojson/examples/iostream.cc +70 -0
  14. data/data/ruco/picojson/examples/streaming.cc +76 -0
  15. data/data/ruco/picojson/picojson.h +1299 -0
  16. data/ext/cocor/Action.cpp +81 -0
  17. data/ext/cocor/Action.h +59 -0
  18. data/ext/cocor/ArrayList.cpp +79 -0
  19. data/ext/cocor/ArrayList.h +52 -0
  20. data/ext/cocor/BitArray.cpp +156 -0
  21. data/ext/cocor/BitArray.h +68 -0
  22. data/ext/cocor/CharClass.cpp +42 -0
  23. data/ext/cocor/CharClass.h +48 -0
  24. data/ext/cocor/CharSet.cpp +166 -0
  25. data/ext/cocor/CharSet.h +68 -0
  26. data/ext/cocor/Coco.atg +528 -0
  27. data/ext/cocor/Coco.cpp +173 -0
  28. data/ext/cocor/Comment.cpp +45 -0
  29. data/ext/cocor/Comment.h +51 -0
  30. data/ext/cocor/Copyright.frame +27 -0
  31. data/ext/cocor/DFA.cpp +865 -0
  32. data/ext/cocor/DFA.h +132 -0
  33. data/ext/cocor/Generator.cpp +182 -0
  34. data/ext/cocor/Generator.h +61 -0
  35. data/ext/cocor/Graph.h +59 -0
  36. data/ext/cocor/HashTable.cpp +115 -0
  37. data/ext/cocor/HashTable.h +84 -0
  38. data/ext/cocor/Makefile +11 -0
  39. data/ext/cocor/Melted.cpp +39 -0
  40. data/ext/cocor/Melted.h +51 -0
  41. data/ext/cocor/Node.cpp +69 -0
  42. data/ext/cocor/Node.h +86 -0
  43. data/ext/cocor/Parser.cpp +925 -0
  44. data/ext/cocor/Parser.frame +326 -0
  45. data/ext/cocor/Parser.h +153 -0
  46. data/ext/cocor/ParserGen.cpp +486 -0
  47. data/ext/cocor/ParserGen.h +99 -0
  48. data/ext/cocor/Position.cpp +37 -0
  49. data/ext/cocor/Position.h +46 -0
  50. data/ext/cocor/README.md +12 -0
  51. data/ext/cocor/Scanner.cpp +833 -0
  52. data/ext/cocor/Scanner.frame +897 -0
  53. data/ext/cocor/Scanner.h +291 -0
  54. data/ext/cocor/Sets.h +84 -0
  55. data/ext/cocor/SortedList.cpp +141 -0
  56. data/ext/cocor/SortedList.h +68 -0
  57. data/ext/cocor/State.cpp +77 -0
  58. data/ext/cocor/State.h +55 -0
  59. data/ext/cocor/StringBuilder.cpp +88 -0
  60. data/ext/cocor/StringBuilder.h +29 -0
  61. data/ext/cocor/Symbol.cpp +61 -0
  62. data/ext/cocor/Symbol.h +70 -0
  63. data/ext/cocor/Tab.cpp +1248 -0
  64. data/ext/cocor/Tab.h +245 -0
  65. data/ext/cocor/Target.cpp +41 -0
  66. data/ext/cocor/Target.h +48 -0
  67. data/ext/cocor/build.bat +3 -0
  68. data/ext/cocor/build.sh +4 -0
  69. data/ext/cocor/coc.bat +1 -0
  70. data/ext/cocor/coc.sh +2 -0
  71. data/ext/cocor/cocor_ruby_ext.cpp +124 -0
  72. data/ext/cocor/cygBuild.bat +1 -0
  73. data/ext/cocor/extconf.rb +5 -0
  74. data/ext/cocor/mingwbuild.bat +2 -0
  75. data/ext/cocor/mkmf.log +57 -0
  76. data/ext/cocor/zipsources.bat +1 -0
  77. data/lib/cocor.rb +14 -0
  78. data/lib/ruco/version.rb +3 -0
  79. data/lib/ruco.rb +728 -0
  80. metadata +195 -0
@@ -0,0 +1,291 @@
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
+
30
+ #if !defined(Coco_COCO_SCANNER_H__)
31
+ #define Coco_COCO_SCANNER_H__
32
+
33
+ #include <limits.h>
34
+ #include <stdio.h>
35
+ #include <stdlib.h>
36
+ #include <string.h>
37
+ #include <wchar.h>
38
+
39
+ // io.h and fcntl are used to ensure binary read from streams on windows
40
+ #if _MSC_VER >= 1300
41
+ #include <io.h>
42
+ #include <fcntl.h>
43
+ #endif
44
+
45
+ #if _MSC_VER >= 1400
46
+ #define coco_swprintf swprintf_s
47
+ #elif _MSC_VER >= 1300
48
+ #define coco_swprintf _snwprintf
49
+ #elif defined __MINGW32__
50
+ #define coco_swprintf _snwprintf
51
+ #else
52
+ // assume every other compiler knows swprintf
53
+ #define coco_swprintf swprintf
54
+ #endif
55
+
56
+ #define COCO_WCHAR_MAX 65535
57
+ #define COCO_MIN_BUFFER_LENGTH 1024
58
+ #define COCO_MAX_BUFFER_LENGTH (64*COCO_MIN_BUFFER_LENGTH)
59
+ #define COCO_HEAP_BLOCK_SIZE (64*1024)
60
+ #define COCO_CPP_NAMESPACE_SEPARATOR L':'
61
+
62
+ namespace Coco {
63
+
64
+
65
+ // string handling, wide character
66
+ wchar_t* coco_string_create(const wchar_t *value);
67
+ wchar_t* coco_string_create(const wchar_t *value, int startIndex);
68
+ wchar_t* coco_string_create(const wchar_t *value, int startIndex, int length);
69
+ wchar_t* coco_string_create_upper(const wchar_t* data);
70
+ wchar_t* coco_string_create_lower(const wchar_t* data);
71
+ wchar_t* coco_string_create_lower(const wchar_t* data, int startIndex, int dataLen);
72
+ wchar_t* coco_string_create_append(const wchar_t* data1, const wchar_t* data2);
73
+ wchar_t* coco_string_create_append(const wchar_t* data, const wchar_t value);
74
+ void coco_string_delete(wchar_t* &data);
75
+ int coco_string_length(const wchar_t* data);
76
+ bool coco_string_endswith(const wchar_t* data, const wchar_t *value);
77
+ int coco_string_indexof(const wchar_t* data, const wchar_t value);
78
+ int coco_string_lastindexof(const wchar_t* data, const wchar_t value);
79
+ void coco_string_merge(wchar_t* &data, const wchar_t* value);
80
+ bool coco_string_equal(const wchar_t* data1, const wchar_t* data2);
81
+ int coco_string_compareto(const wchar_t* data1, const wchar_t* data2);
82
+ int coco_string_hash(const wchar_t* data);
83
+
84
+ // string handling, ascii character
85
+ wchar_t* coco_string_create(const char *value);
86
+ char* coco_string_create_char(const wchar_t *value);
87
+ void coco_string_delete(char* &data);
88
+
89
+
90
+ class Token
91
+ {
92
+ public:
93
+ int kind; // token kind
94
+ int pos; // token position in bytes in the source text (starting at 0)
95
+ int charPos; // token position in characters in the source text (starting at 0)
96
+ int col; // token column (starting at 1)
97
+ int line; // token line (starting at 1)
98
+ wchar_t* val; // token value
99
+ Token *next; // ML 2005-03-11 Peek tokens are kept in linked list
100
+
101
+ Token();
102
+ ~Token();
103
+ };
104
+
105
+ class Buffer {
106
+ // This Buffer supports the following cases:
107
+ // 1) seekable stream (file)
108
+ // a) whole stream in buffer
109
+ // b) part of stream in buffer
110
+ // 2) non seekable stream (network, console)
111
+ private:
112
+ unsigned char *buf; // input buffer
113
+ int bufCapacity; // capacity of buf
114
+ int bufStart; // position of first byte in buffer relative to input stream
115
+ int bufLen; // length of buffer
116
+ int fileLen; // length of input stream (may change if the stream is no file)
117
+ int bufPos; // current position in buffer
118
+ FILE* stream; // input stream (seekable)
119
+ bool isUserStream; // was the stream opened by the user?
120
+
121
+ int ReadNextStreamChunk();
122
+ bool CanSeek(); // true if stream can be seeked otherwise false
123
+
124
+ public:
125
+ static const int EoF = COCO_WCHAR_MAX + 1;
126
+
127
+ Buffer(FILE* s, bool isUserStream);
128
+ Buffer(const unsigned char* buf, int len);
129
+ Buffer(Buffer *b);
130
+ virtual ~Buffer();
131
+
132
+ virtual void Close();
133
+ virtual int Read();
134
+ virtual int Peek();
135
+ virtual wchar_t* GetString(int beg, int end);
136
+ virtual int GetPos();
137
+ virtual void SetPos(int value);
138
+ };
139
+
140
+ class UTF8Buffer : public Buffer {
141
+ public:
142
+ UTF8Buffer(Buffer *b) : Buffer(b) {};
143
+ virtual int Read();
144
+ };
145
+
146
+ //-----------------------------------------------------------------------------------
147
+ // StartStates -- maps characters to start states of tokens
148
+ //-----------------------------------------------------------------------------------
149
+ class StartStates {
150
+ private:
151
+ class Elem {
152
+ public:
153
+ int key, val;
154
+ Elem *next;
155
+ Elem(int key, int val) { this->key = key; this->val = val; next = NULL; }
156
+ };
157
+
158
+ Elem **tab;
159
+
160
+ public:
161
+ StartStates() { tab = new Elem*[128]; memset(tab, 0, 128 * sizeof(Elem*)); }
162
+ virtual ~StartStates() {
163
+ for (int i = 0; i < 128; ++i) {
164
+ Elem *e = tab[i];
165
+ while (e != NULL) {
166
+ Elem *next = e->next;
167
+ delete e;
168
+ e = next;
169
+ }
170
+ }
171
+ delete [] tab;
172
+ }
173
+
174
+ void set(int key, int val) {
175
+ Elem *e = new Elem(key, val);
176
+ int k = ((unsigned int) key) % 128;
177
+ e->next = tab[k]; tab[k] = e;
178
+ }
179
+
180
+ int state(int key) {
181
+ Elem *e = tab[((unsigned int) key) % 128];
182
+ while (e != NULL && e->key != key) e = e->next;
183
+ return e == NULL ? 0 : e->val;
184
+ }
185
+ };
186
+
187
+ //-------------------------------------------------------------------------------------------
188
+ // KeywordMap -- maps strings to integers (identifiers to keyword kinds)
189
+ //-------------------------------------------------------------------------------------------
190
+ class KeywordMap {
191
+ private:
192
+ class Elem {
193
+ public:
194
+ wchar_t *key;
195
+ int val;
196
+ Elem *next;
197
+ Elem(const wchar_t *key, int val) { this->key = coco_string_create(key); this->val = val; next = NULL; }
198
+ virtual ~Elem() { coco_string_delete(key); }
199
+ };
200
+
201
+ Elem **tab;
202
+
203
+ public:
204
+ KeywordMap() { tab = new Elem*[128]; memset(tab, 0, 128 * sizeof(Elem*)); }
205
+ virtual ~KeywordMap() {
206
+ for (int i = 0; i < 128; ++i) {
207
+ Elem *e = tab[i];
208
+ while (e != NULL) {
209
+ Elem *next = e->next;
210
+ delete e;
211
+ e = next;
212
+ }
213
+ }
214
+ delete [] tab;
215
+ }
216
+
217
+ void set(const wchar_t *key, int val) {
218
+ Elem *e = new Elem(key, val);
219
+ int k = coco_string_hash(key) % 128;
220
+ e->next = tab[k]; tab[k] = e;
221
+ }
222
+
223
+ int get(const wchar_t *key, int defaultVal) {
224
+ Elem *e = tab[coco_string_hash(key) % 128];
225
+ while (e != NULL && !coco_string_equal(e->key, key)) e = e->next;
226
+ return e == NULL ? defaultVal : e->val;
227
+ }
228
+ };
229
+
230
+ class Scanner {
231
+ private:
232
+ void *firstHeap;
233
+ void *heap;
234
+ void *heapTop;
235
+ void **heapEnd;
236
+
237
+ unsigned char EOL;
238
+ int eofSym;
239
+ int noSym;
240
+ int maxT;
241
+ int charSetSize;
242
+ StartStates start;
243
+ KeywordMap keywords;
244
+
245
+ Token *t; // current token
246
+ wchar_t *tval; // text of current token
247
+ int tvalLength; // length of text of current token
248
+ int tlen; // length of current token
249
+
250
+ Token *tokens; // list of tokens already peeked (first token is a dummy)
251
+ Token *pt; // current peek token
252
+
253
+ int ch; // current input character
254
+
255
+ int pos; // byte position of current character
256
+ int charPos; // position by unicode characters starting with 0
257
+ int line; // line number of current character
258
+ int col; // column number of current character
259
+ int oldEols; // EOLs that appeared in a comment;
260
+
261
+ void CreateHeapBlock();
262
+ Token* CreateToken();
263
+ void AppendVal(Token *t);
264
+ void SetScannerBehindT();
265
+
266
+ void Init();
267
+ void NextCh();
268
+ void AddCh();
269
+ bool Comment0();
270
+ bool Comment1();
271
+
272
+ Token* NextToken();
273
+
274
+ public:
275
+ Buffer *buffer; // scanner buffer
276
+
277
+ Scanner(const unsigned char* buf, int len);
278
+ Scanner(const wchar_t* fileName);
279
+ Scanner(FILE* s);
280
+ ~Scanner();
281
+ Token* Scan();
282
+ Token* Peek();
283
+ void ResetPeek();
284
+
285
+ }; // end Scanner
286
+
287
+ } // namespace
288
+
289
+
290
+ #endif
291
+
data/ext/cocor/Sets.h ADDED
@@ -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_SETS_H__)
30
+ #define COCO_SETS_H__
31
+
32
+ #include "BitArray.h"
33
+
34
+ namespace Coco {
35
+
36
+ class Sets {
37
+ public:
38
+ static int First(BitArray *s) {
39
+ int max = s->getCount();
40
+ for (int i=0; i<max; i++)
41
+ if ((*s)[i]) return i;
42
+ return -1;
43
+ }
44
+
45
+ static int Elements(BitArray *s) {
46
+ int max = s->getCount();
47
+ int n = 0;
48
+ for (int i=0; i<max; i++)
49
+ if ((*s)[i]) n++;
50
+ return n;
51
+ }
52
+
53
+ static bool Equals(BitArray *a, BitArray *b) {
54
+ int max = a->getCount();
55
+ for (int i=0; i<max; i++)
56
+ if ((*a)[i] != (*b)[i]) return false;
57
+ return true;
58
+ }
59
+
60
+ static bool Includes(BitArray *a, BitArray *b) { // a > b ?
61
+ int max = a->getCount();
62
+ for (int i=0; i<max; i++)
63
+ if ((*b)[i] && ! (*a)[i]) return false;
64
+ return true;
65
+ }
66
+
67
+ static bool Intersect(BitArray *a, BitArray *b) { // a * b != {}
68
+ int max = a->getCount();
69
+ for (int i=0; i<max; i++)
70
+ if ((*a)[i] && (*b)[i]) return true;
71
+ return false;
72
+ }
73
+
74
+ static void Subtract(BitArray *a, BitArray *b) { // a = a - b
75
+ BitArray *c = b->Clone();
76
+ c->Not();
77
+ a->And(c);
78
+ delete c;
79
+ }
80
+ };
81
+
82
+ }; // namespace
83
+
84
+ #endif // !defined(COCO_SETS_H__)
@@ -0,0 +1,141 @@
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 <stdio.h>
30
+ #include "SortedList.h"
31
+ #include "Tab.h"
32
+
33
+ namespace Coco {
34
+
35
+ int Compare(Symbol *x, Symbol *y) {
36
+ return coco_string_compareto(x->name, y->name);
37
+ }
38
+
39
+ SortedEntry::SortedEntry(Symbol* Key, void* Value) {
40
+ this->Key = Key;
41
+ this->Value = Value;
42
+ this->next = NULL;
43
+ }
44
+
45
+ SortedEntry::~SortedEntry() {
46
+ };
47
+
48
+ SortedList::SortedList() {
49
+ Count = 0;
50
+ Data = NULL;
51
+ }
52
+
53
+ SortedList::~SortedList() {
54
+ }
55
+
56
+ bool SortedList::Find(Symbol* key) {
57
+ SortedEntry* pSortedEntry = Data;
58
+ while (pSortedEntry) {
59
+ if (!Compare(pSortedEntry->Key, key))
60
+ return true;
61
+ pSortedEntry = pSortedEntry->next;
62
+ }
63
+ return false;
64
+ }
65
+
66
+ void SortedList::Set(Symbol *key, void *value) {
67
+ if (!Find(key)) {
68
+ // new entry
69
+ SortedEntry* pSortedEntry = Data;
70
+ SortedEntry* pSortedEntryPrev = NULL;
71
+ SortedEntry* newSortedEntry = new SortedEntry(key, value);
72
+ if (pSortedEntry) {
73
+ // insert
74
+
75
+ if (Compare(pSortedEntry->Key, key) > 0) { // before the first
76
+ newSortedEntry->next = Data;
77
+ Data = newSortedEntry;
78
+ } else {
79
+ while (pSortedEntry) {
80
+ if (Compare(pSortedEntry->Key, key) < 0) {
81
+ pSortedEntryPrev = pSortedEntry;
82
+ pSortedEntry = pSortedEntry->next;
83
+ } else {
84
+ break;
85
+ }
86
+ }
87
+ pSortedEntryPrev->next = newSortedEntry;
88
+ newSortedEntry->next = pSortedEntry;
89
+ }
90
+ } else {
91
+ Data = newSortedEntry; // first entry
92
+ }
93
+ Count++;
94
+ } else {
95
+ // exist entry - overwrite
96
+ SortedEntry* pSortedEntry = Data;
97
+ while (Compare(pSortedEntry->Key, key)) {
98
+ pSortedEntry = pSortedEntry->next;
99
+ }
100
+ pSortedEntry->Value = value;
101
+ }
102
+ }
103
+
104
+ void* SortedList::Get( Symbol* key ) const // Value
105
+ {
106
+ SortedEntry* pSortedEntry = Data;
107
+ while (pSortedEntry) {
108
+ if (!Compare(pSortedEntry->Key, key))
109
+ return pSortedEntry->Value;
110
+ pSortedEntry = pSortedEntry->next;
111
+ }
112
+ return NULL;
113
+ }
114
+
115
+
116
+ void* SortedList::GetKey( int index ) const // Key
117
+ {
118
+ if (0 <= index && index < Count) {
119
+ SortedEntry* pSortedEntry = Data;
120
+ for (int i=0; i<index; i++) {
121
+ pSortedEntry = pSortedEntry->next;
122
+ }
123
+ return pSortedEntry->Key;
124
+ } else {
125
+ return NULL;
126
+ }
127
+ }
128
+
129
+ SortedEntry* SortedList::operator[]( int index ) const {
130
+ if (0 <= index && index < Count) {
131
+ SortedEntry* pSortedEntry = Data;
132
+ for (int i=0; i<index; i++) {
133
+ pSortedEntry = pSortedEntry->next;
134
+ }
135
+ return pSortedEntry;
136
+ } else {
137
+ return NULL;
138
+ }
139
+ }
140
+
141
+ }; // namespace
@@ -0,0 +1,68 @@
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_SORTEDLIST_H__)
30
+ #define COCO_SORTEDLIST_H__
31
+
32
+ namespace Coco {
33
+
34
+ class Symbol;
35
+
36
+ class SortedEntry
37
+ {
38
+ public:
39
+ Symbol* Key;
40
+ void* Value;
41
+ SortedEntry* next;
42
+
43
+ SortedEntry(Symbol* Key, void* Value);
44
+ virtual ~SortedEntry();
45
+ };
46
+
47
+ class SortedList
48
+ {
49
+ public:
50
+ SortedList();
51
+ virtual ~SortedList();
52
+
53
+ void Set(Symbol *key, void *value);
54
+ void* Get( Symbol* key ) const; // Value
55
+ void* GetKey( int index ) const ;// Key
56
+ SortedEntry* operator[]( int index ) const;
57
+
58
+ int Count;
59
+ private:
60
+ bool Find(Symbol* key);
61
+
62
+ SortedEntry *Data;
63
+
64
+ };
65
+
66
+ }; // namespace
67
+
68
+ #endif // !defined(COCO_SORTEDLIST_H__)
@@ -0,0 +1,77 @@
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 "Action.h"
30
+ #include "State.h"
31
+
32
+ namespace Coco {
33
+
34
+ State::State() {
35
+ this->firstAction = NULL;
36
+ this->endOf = NULL;
37
+ this->ctx = false;
38
+ this->next = NULL;
39
+ }
40
+
41
+ void State::AddAction(Action *act) {
42
+ Action *lasta = NULL, *a = firstAction;
43
+ while (a != NULL && act->typ >= a->typ) {lasta = a; a = a->next;}
44
+ // collecting classes at the beginning gives better performance
45
+ act->next = a;
46
+ if (a==firstAction) {
47
+ firstAction = act;
48
+ }
49
+ else {
50
+ lasta->next = act;
51
+ }
52
+ }
53
+
54
+ void State::DetachAction(Action *act) {
55
+ Action *lasta = NULL, *a = firstAction;
56
+ while (a != NULL && a != act) {lasta = a; a = a->next;}
57
+ if (a != NULL) {
58
+ if (a == firstAction) {
59
+ firstAction = a->next;
60
+ }
61
+ else {
62
+ lasta->next = a->next;
63
+ }
64
+ }
65
+ }
66
+
67
+
68
+ void State::MeltWith(State *s) { // copy actions of s to state
69
+ Action *a;
70
+ for (Action *action = s->firstAction; action != NULL; action = action->next) {
71
+ a = new Action(action->typ, action->sym, action->tc);
72
+ a->AddTargets(action);
73
+ AddAction(a);
74
+ }
75
+ }
76
+
77
+ }; // namespace