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.
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,326 @@
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
+ Parser.h Specification
31
+ -----------------------------------------------------------------------*/
32
+
33
+ -->begin
34
+
35
+ #if !defined(-->prefixCOCO_PARSER_H__)
36
+ #define -->prefixCOCO_PARSER_H__
37
+
38
+ -->headerdef
39
+
40
+ #include "Scanner.h"
41
+
42
+ -->namespace_open
43
+
44
+ class Errors {
45
+ public:
46
+ int count; // number of errors detected
47
+
48
+ Errors();
49
+ void SynErr(int line, int col, int n);
50
+ void Error(int line, int col, const wchar_t *s);
51
+ void Warning(int line, int col, const wchar_t *s);
52
+ void Warning(const wchar_t *s);
53
+ void Exception(const wchar_t *s);
54
+
55
+ }; // Errors
56
+
57
+ class Parser {
58
+ private:
59
+ -->constantsheader
60
+ Token *dummyToken;
61
+ int errDist;
62
+ int minErrDist;
63
+
64
+ void SynErr(int n);
65
+ void Get();
66
+ void Expect(int n);
67
+ bool StartOf(int s);
68
+ void ExpectWeak(int n, int follow);
69
+ bool WeakSeparator(int n, int syFol, int repFol);
70
+
71
+ public:
72
+ Scanner *scanner;
73
+ Errors *errors;
74
+
75
+ Token *t; // last recognized token
76
+ Token *la; // lookahead token
77
+
78
+ -->declarations
79
+
80
+ Parser(Scanner *scanner);
81
+ ~Parser();
82
+ void SemErr(const wchar_t* msg);
83
+
84
+ -->productionsheader
85
+ void Parse();
86
+
87
+ }; // end Parser
88
+
89
+ -->namespace_close
90
+
91
+ #endif
92
+
93
+ -->implementation
94
+
95
+ /*----------------------------------------------------------------------
96
+ Parser.cpp Specification
97
+ -----------------------------------------------------------------------*/
98
+
99
+ -->begin
100
+
101
+ #include <wchar.h>
102
+ #include "Parser.h"
103
+ #include "Scanner.h"
104
+
105
+
106
+ -->namespace_open
107
+
108
+ void Parser::SynErr(int n) {
109
+ if (errDist >= minErrDist) errors->SynErr(la->line, la->col, n);
110
+ errDist = 0;
111
+ }
112
+
113
+ void Parser::SemErr(const wchar_t* msg) {
114
+ if (errDist >= minErrDist) errors->Error(t->line, t->col, msg);
115
+ errDist = 0;
116
+ }
117
+
118
+ void Parser::Get() {
119
+ for (;;) {
120
+ t = la;
121
+ la = scanner->Scan();
122
+ if (la->kind <= maxT) { ++errDist; break; }
123
+ -->pragmas
124
+ if (dummyToken != t) {
125
+ dummyToken->kind = t->kind;
126
+ dummyToken->pos = t->pos;
127
+ dummyToken->col = t->col;
128
+ dummyToken->line = t->line;
129
+ dummyToken->next = NULL;
130
+ coco_string_delete(dummyToken->val);
131
+ dummyToken->val = coco_string_create(t->val);
132
+ t = dummyToken;
133
+ }
134
+ la = t;
135
+ }
136
+ }
137
+
138
+ void Parser::Expect(int n) {
139
+ if (la->kind==n) Get(); else { SynErr(n); }
140
+ }
141
+
142
+ void Parser::ExpectWeak(int n, int follow) {
143
+ if (la->kind == n) Get();
144
+ else {
145
+ SynErr(n);
146
+ while (!StartOf(follow)) Get();
147
+ }
148
+ }
149
+
150
+ bool Parser::WeakSeparator(int n, int syFol, int repFol) {
151
+ if (la->kind == n) {Get(); return true;}
152
+ else if (StartOf(repFol)) {return false;}
153
+ else {
154
+ SynErr(n);
155
+ while (!(StartOf(syFol) || StartOf(repFol) || StartOf(0))) {
156
+ Get();
157
+ }
158
+ return StartOf(syFol);
159
+ }
160
+ }
161
+
162
+ -->productions
163
+
164
+
165
+ // If the user declared a method Init and a mehtod Destroy they should
166
+ // be called in the contructur and the destructor respctively.
167
+ //
168
+ // The following templates are used to recognize if the user declared
169
+ // the methods Init and Destroy.
170
+
171
+ template<typename T>
172
+ struct ParserInitExistsRecognizer {
173
+ template<typename U, void (U::*)() = &U::Init>
174
+ struct ExistsIfInitIsDefinedMarker{};
175
+
176
+ struct InitIsMissingType {
177
+ char dummy1;
178
+ };
179
+
180
+ struct InitExistsType {
181
+ char dummy1; char dummy2;
182
+ };
183
+
184
+ // exists always
185
+ template<typename U>
186
+ static InitIsMissingType is_here(...);
187
+
188
+ // exist only if ExistsIfInitIsDefinedMarker is defined
189
+ template<typename U>
190
+ static InitExistsType is_here(ExistsIfInitIsDefinedMarker<U>*);
191
+
192
+ enum { InitExists = (sizeof(is_here<T>(NULL)) == sizeof(InitExistsType)) };
193
+ };
194
+
195
+ template<typename T>
196
+ struct ParserDestroyExistsRecognizer {
197
+ template<typename U, void (U::*)() = &U::Destroy>
198
+ struct ExistsIfDestroyIsDefinedMarker{};
199
+
200
+ struct DestroyIsMissingType {
201
+ char dummy1;
202
+ };
203
+
204
+ struct DestroyExistsType {
205
+ char dummy1; char dummy2;
206
+ };
207
+
208
+ // exists always
209
+ template<typename U>
210
+ static DestroyIsMissingType is_here(...);
211
+
212
+ // exist only if ExistsIfDestroyIsDefinedMarker is defined
213
+ template<typename U>
214
+ static DestroyExistsType is_here(ExistsIfDestroyIsDefinedMarker<U>*);
215
+
216
+ enum { DestroyExists = (sizeof(is_here<T>(NULL)) == sizeof(DestroyExistsType)) };
217
+ };
218
+
219
+ // The folloing templates are used to call the Init and Destroy methods if they exist.
220
+
221
+ // Generic case of the ParserInitCaller, gets used if the Init method is missing
222
+ template<typename T, bool = ParserInitExistsRecognizer<T>::InitExists>
223
+ struct ParserInitCaller {
224
+ static void CallInit(T *t) {
225
+ // nothing to do
226
+ }
227
+ };
228
+
229
+ // True case of the ParserInitCaller, gets used if the Init method exists
230
+ template<typename T>
231
+ struct ParserInitCaller<T, true> {
232
+ static void CallInit(T *t) {
233
+ t->Init();
234
+ }
235
+ };
236
+
237
+ // Generic case of the ParserDestroyCaller, gets used if the Destroy method is missing
238
+ template<typename T, bool = ParserDestroyExistsRecognizer<T>::DestroyExists>
239
+ struct ParserDestroyCaller {
240
+ static void CallDestroy(T *t) {
241
+ // nothing to do
242
+ }
243
+ };
244
+
245
+ // True case of the ParserDestroyCaller, gets used if the Destroy method exists
246
+ template<typename T>
247
+ struct ParserDestroyCaller<T, true> {
248
+ static void CallDestroy(T *t) {
249
+ t->Destroy();
250
+ }
251
+ };
252
+
253
+ void Parser::Parse() {
254
+ t = NULL;
255
+ la = dummyToken = new Token();
256
+ la->val = coco_string_create(L"Dummy Token");
257
+ Get();
258
+ -->parseRoot
259
+ }
260
+
261
+ Parser::Parser(Scanner *scanner) {
262
+ -->constants
263
+ ParserInitCaller<Parser>::CallInit(this);
264
+ dummyToken = NULL;
265
+ t = la = NULL;
266
+ minErrDist = 2;
267
+ errDist = minErrDist;
268
+ this->scanner = scanner;
269
+ errors = new Errors();
270
+ }
271
+
272
+ bool Parser::StartOf(int s) {
273
+ const bool T = true;
274
+ const bool x = false;
275
+
276
+ -->initialization
277
+
278
+ return set[s][la->kind];
279
+ }
280
+
281
+ Parser::~Parser() {
282
+ ParserDestroyCaller<Parser>::CallDestroy(this);
283
+ delete errors;
284
+ delete dummyToken;
285
+ }
286
+
287
+ Errors::Errors() {
288
+ count = 0;
289
+ }
290
+
291
+ void Errors::SynErr(int line, int col, int n) {
292
+ wchar_t* s;
293
+ switch (n) {
294
+ -->errors
295
+ default:
296
+ {
297
+ wchar_t format[20];
298
+ coco_swprintf(format, 20, L"error %d", n);
299
+ s = coco_string_create(format);
300
+ }
301
+ break;
302
+ }
303
+ wprintf(L"-- line %d col %d: %ls\n", line, col, s);
304
+ coco_string_delete(s);
305
+ count++;
306
+ }
307
+
308
+ void Errors::Error(int line, int col, const wchar_t *s) {
309
+ wprintf(L"-- line %d col %d: %ls\n", line, col, s);
310
+ count++;
311
+ }
312
+
313
+ void Errors::Warning(int line, int col, const wchar_t *s) {
314
+ wprintf(L"-- line %d col %d: %ls\n", line, col, s);
315
+ }
316
+
317
+ void Errors::Warning(const wchar_t *s) {
318
+ wprintf(L"%ls\n", s);
319
+ }
320
+
321
+ void Errors::Exception(const wchar_t* s) {
322
+ wprintf(L"%ls", s);
323
+ exit(1);
324
+ }
325
+
326
+ -->namespace_close
@@ -0,0 +1,153 @@
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_PARSER_H__)
31
+ #define Coco_COCO_PARSER_H__
32
+
33
+ #include "Tab.h"
34
+ #include "DFA.h"
35
+ #include "ParserGen.h"
36
+
37
+
38
+ #include "Scanner.h"
39
+
40
+ namespace Coco {
41
+
42
+
43
+ class Errors {
44
+ public:
45
+ int count; // number of errors detected
46
+
47
+ Errors();
48
+ void SynErr(int line, int col, int n);
49
+ void Error(int line, int col, const wchar_t *s);
50
+ void Warning(int line, int col, const wchar_t *s);
51
+ void Warning(const wchar_t *s);
52
+ void Exception(const wchar_t *s);
53
+
54
+ }; // Errors
55
+
56
+ class Parser {
57
+ private:
58
+ enum {
59
+ _EOF=0,
60
+ _ident=1,
61
+ _number=2,
62
+ _string=3,
63
+ _badString=4,
64
+ _char=5,
65
+ _ddtSym=42,
66
+ _optionSym=43
67
+ };
68
+ int maxT;
69
+
70
+ Token *dummyToken;
71
+ int errDist;
72
+ int minErrDist;
73
+
74
+ void SynErr(int n);
75
+ void Get();
76
+ void Expect(int n);
77
+ bool StartOf(int s);
78
+ void ExpectWeak(int n, int follow);
79
+ bool WeakSeparator(int n, int syFol, int repFol);
80
+
81
+ public:
82
+ Scanner *scanner;
83
+ Errors *errors;
84
+
85
+ Token *t; // last recognized token
86
+ Token *la; // lookahead token
87
+
88
+ int id;
89
+ int str;
90
+
91
+ FILE* trace; // other Coco objects referenced in this ATG
92
+ Tab *tab;
93
+ DFA *dfa;
94
+ ParserGen *pgen;
95
+
96
+ bool genScanner;
97
+ wchar_t* tokenString; // used in declarations of literal tokens
98
+ wchar_t* noString; // used in declarations of literal tokens
99
+
100
+ // This method will be called by the contructor if it exits.
101
+ // This support is specific to the C++ version of Coco/R.
102
+ void Init() {
103
+ tab = NULL;
104
+ dfa = NULL;
105
+ pgen = NULL;
106
+ id = 0;
107
+ str = 1;
108
+ tokenString = NULL;
109
+ noString = coco_string_create(L"-none-");
110
+ }
111
+
112
+ // Uncomment this method if cleanup is necessary,
113
+ // this method will be called by the destructor if it exists.
114
+ // This support is specific to the C++ version of Coco/R.
115
+ // void Destroy() {
116
+ // nothing to do
117
+ // }
118
+ /*-------------------------------------------------------------------------*/
119
+
120
+
121
+
122
+ Parser(Scanner *scanner);
123
+ ~Parser();
124
+ void SemErr(const wchar_t* msg);
125
+
126
+ void Coco();
127
+ void SetDecl();
128
+ void TokenDecl(int typ);
129
+ void TokenExpr(Graph* &g);
130
+ void Set(CharSet* &s);
131
+ void AttrDecl(Symbol *sym);
132
+ void SemText(Position* &pos);
133
+ void Expression(Graph* &g);
134
+ void SimSet(CharSet* &s);
135
+ void Char(int &n);
136
+ void Sym(wchar_t* &name, int &kind);
137
+ void Term(Graph* &g);
138
+ void Resolver(Position* &pos);
139
+ void Factor(Graph* &g);
140
+ void Attribs(Node *p);
141
+ void Condition();
142
+ void TokenTerm(Graph* &g);
143
+ void TokenFactor(Graph* &g);
144
+
145
+ void Parse();
146
+
147
+ }; // end Parser
148
+
149
+ } // namespace
150
+
151
+
152
+ #endif
153
+