ruco-cpp 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- 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/Tab.h
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
/*-------------------------------------------------------------------------
|
2
|
+
Tab -- Symbol Table Management
|
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_TAB_H__)
|
31
|
+
#define COCO_TAB_H__
|
32
|
+
|
33
|
+
#include "ArrayList.h"
|
34
|
+
#include "HashTable.h"
|
35
|
+
#include "StringBuilder.h"
|
36
|
+
#include "SortedList.h"
|
37
|
+
#include "Scanner.h"
|
38
|
+
#include "Position.h"
|
39
|
+
#include "Symbol.h"
|
40
|
+
#include "Node.h"
|
41
|
+
#include "Graph.h"
|
42
|
+
#include "Sets.h"
|
43
|
+
#include "CharClass.h"
|
44
|
+
|
45
|
+
namespace Coco {
|
46
|
+
|
47
|
+
class Errors;
|
48
|
+
class Parser;
|
49
|
+
class BitArray;
|
50
|
+
|
51
|
+
class Tab {
|
52
|
+
public:
|
53
|
+
Position *semDeclPos; // position of global semantic declarations
|
54
|
+
CharSet *ignored; // characters ignored by the scanner
|
55
|
+
bool ddt[10]; // debug and test switches
|
56
|
+
Symbol *gramSy; // root nonterminal; filled by ATG
|
57
|
+
Symbol *eofSy; // end of file symbol
|
58
|
+
Symbol *noSym; // used in case of an error
|
59
|
+
BitArray *allSyncSets; // union of all synchronisation sets
|
60
|
+
HashTable *literals; // symbols that are used as literals
|
61
|
+
|
62
|
+
wchar_t* srcName; // name of the atg file (including path)
|
63
|
+
wchar_t* srcDir; // directory path of the atg file
|
64
|
+
wchar_t* nsName; // namespace for generated files
|
65
|
+
wchar_t* frameDir; // directory containing the frame files
|
66
|
+
wchar_t* outDir; // directory for generated files
|
67
|
+
bool checkEOF; // should coco generate a check for EOF at
|
68
|
+
// the end of Parser.Parse():
|
69
|
+
bool emitLines; // emit line directives in generated parser
|
70
|
+
|
71
|
+
BitArray *visited; // mark list for graph traversals
|
72
|
+
Symbol *curSy; // current symbol in computation of sets
|
73
|
+
|
74
|
+
Parser *parser; // other Coco objects
|
75
|
+
FILE* trace;
|
76
|
+
|
77
|
+
Errors *errors;
|
78
|
+
|
79
|
+
ArrayList *terminals;
|
80
|
+
ArrayList *pragmas;
|
81
|
+
ArrayList *nonterminals;
|
82
|
+
|
83
|
+
|
84
|
+
ArrayList *nodes;
|
85
|
+
static const char* nTyp[];
|
86
|
+
Node *dummyNode;
|
87
|
+
|
88
|
+
ArrayList *classes;
|
89
|
+
int dummyName;
|
90
|
+
|
91
|
+
|
92
|
+
Tab(Parser *parser);
|
93
|
+
|
94
|
+
//---------------------------------------------------------------------
|
95
|
+
// Symbol list management
|
96
|
+
//---------------------------------------------------------------------
|
97
|
+
|
98
|
+
|
99
|
+
static const char* tKind[];
|
100
|
+
|
101
|
+
Symbol* NewSym(int typ, const wchar_t* name, int line);
|
102
|
+
Symbol* FindSym(const wchar_t* name);
|
103
|
+
int Num(Node *p);
|
104
|
+
void PrintSym(Symbol *sym);
|
105
|
+
void PrintSymbolTable();
|
106
|
+
void PrintSet(BitArray *s, int indent);
|
107
|
+
|
108
|
+
//---------------------------------------------------------------------
|
109
|
+
// Syntax graph management
|
110
|
+
//---------------------------------------------------------------------
|
111
|
+
|
112
|
+
Node* NewNode(int typ, Symbol *sym, int line);
|
113
|
+
Node* NewNode(int typ, Node* sub);
|
114
|
+
Node* NewNode(int typ, int val, int line);
|
115
|
+
void MakeFirstAlt(Graph *g);
|
116
|
+
void MakeAlternative(Graph *g1, Graph *g2);
|
117
|
+
void MakeSequence(Graph *g1, Graph *g2);
|
118
|
+
void MakeIteration(Graph *g);
|
119
|
+
void MakeOption(Graph *g);
|
120
|
+
void Finish(Graph *g);
|
121
|
+
void DeleteNodes();
|
122
|
+
Graph* StrToGraph(const wchar_t* str);
|
123
|
+
void SetContextTrans(Node *p); // set transition code in the graph rooted at p
|
124
|
+
|
125
|
+
//------------ graph deletability check -----------------
|
126
|
+
|
127
|
+
bool DelGraph(Node* p);
|
128
|
+
bool DelSubGraph(Node* p);
|
129
|
+
bool DelNode(Node* p);
|
130
|
+
|
131
|
+
//----------------- graph printing ----------------------
|
132
|
+
|
133
|
+
int Ptr(Node *p, bool up);
|
134
|
+
wchar_t* Pos(Position *pos);
|
135
|
+
wchar_t* Name(const wchar_t* name);
|
136
|
+
void PrintNodes();
|
137
|
+
|
138
|
+
//---------------------------------------------------------------------
|
139
|
+
// Character class management
|
140
|
+
//---------------------------------------------------------------------
|
141
|
+
|
142
|
+
CharClass* NewCharClass(const wchar_t* name, CharSet *s);
|
143
|
+
CharClass* FindCharClass(const wchar_t* name);
|
144
|
+
CharClass* FindCharClass(CharSet *s);
|
145
|
+
CharSet* CharClassSet(int i);
|
146
|
+
|
147
|
+
//----------- character class printing
|
148
|
+
|
149
|
+
wchar_t* Ch(const wchar_t ch);
|
150
|
+
void WriteCharSet(CharSet *s);
|
151
|
+
void WriteCharClasses ();
|
152
|
+
|
153
|
+
//---------------------------------------------------------------------
|
154
|
+
// Symbol set computations
|
155
|
+
//---------------------------------------------------------------------
|
156
|
+
|
157
|
+
/* Computes the first set for the given Node. */
|
158
|
+
BitArray* First0(Node *p, BitArray *mark);
|
159
|
+
BitArray* First(Node *p);
|
160
|
+
void CompFirstSets();
|
161
|
+
void CompFollow(Node *p);
|
162
|
+
void Complete(Symbol *sym);
|
163
|
+
void CompFollowSets();
|
164
|
+
Node* LeadingAny(Node *p);
|
165
|
+
void FindAS(Node *p); // find ANY sets
|
166
|
+
void CompAnySets();
|
167
|
+
BitArray* Expected(Node *p, Symbol *curSy);
|
168
|
+
// does not look behind resolvers; only called during LL(1) test and in CheckRes
|
169
|
+
BitArray* Expected0(Node *p, Symbol *curSy);
|
170
|
+
void CompSync(Node *p);
|
171
|
+
void CompSyncSets();
|
172
|
+
void SetupAnys();
|
173
|
+
void CompDeletableSymbols();
|
174
|
+
void RenumberPragmas();
|
175
|
+
void CompSymbolSets();
|
176
|
+
|
177
|
+
//---------------------------------------------------------------------
|
178
|
+
// String handling
|
179
|
+
//---------------------------------------------------------------------
|
180
|
+
|
181
|
+
wchar_t Hex2Char(const wchar_t* s);
|
182
|
+
wchar_t* Char2Hex(const wchar_t ch);
|
183
|
+
wchar_t* Unescape(const wchar_t* s);
|
184
|
+
wchar_t* Escape(const wchar_t* s);
|
185
|
+
|
186
|
+
//---------------------------------------------------------------------
|
187
|
+
// Grammar checks
|
188
|
+
//---------------------------------------------------------------------
|
189
|
+
|
190
|
+
bool GrammarOk();
|
191
|
+
|
192
|
+
//--------------- check for circular productions ----------------------
|
193
|
+
|
194
|
+
class CNode { // node of list for finding circular productions
|
195
|
+
public:
|
196
|
+
Symbol *left, *right;
|
197
|
+
|
198
|
+
CNode (Symbol *l, Symbol *r) {
|
199
|
+
left = l; right = r;
|
200
|
+
}
|
201
|
+
};
|
202
|
+
|
203
|
+
void GetSingles(Node *p, ArrayList *singles);
|
204
|
+
bool NoCircularProductions();
|
205
|
+
|
206
|
+
//--------------- check for LL(1) errors ----------------------
|
207
|
+
|
208
|
+
void LL1Error(int cond, Symbol *sym);
|
209
|
+
void CheckOverlap(BitArray *s1, BitArray *s2, int cond);
|
210
|
+
void CheckAlts(Node *p);
|
211
|
+
void CheckLL1();
|
212
|
+
|
213
|
+
//------------- check if resolvers are legal --------------------
|
214
|
+
|
215
|
+
void ResErr(Node *p, const wchar_t* msg);
|
216
|
+
void CheckRes(Node *p, bool rslvAllowed);
|
217
|
+
void CheckResolvers();
|
218
|
+
|
219
|
+
//------------- check if every nts has a production --------------------
|
220
|
+
|
221
|
+
bool NtsComplete();
|
222
|
+
|
223
|
+
//-------------- check if every nts can be reached -----------------
|
224
|
+
|
225
|
+
void MarkReachedNts(Node *p);
|
226
|
+
bool AllNtReached();
|
227
|
+
|
228
|
+
//--------- check if every nts can be derived to terminals ------------
|
229
|
+
|
230
|
+
bool IsTerm(Node *p, BitArray *mark); // true if graph can be derived to terminals
|
231
|
+
bool AllNtToTerm();
|
232
|
+
|
233
|
+
//---------------------------------------------------------------------
|
234
|
+
// Cross reference list
|
235
|
+
//---------------------------------------------------------------------
|
236
|
+
|
237
|
+
void XRef();
|
238
|
+
void SetDDT(const wchar_t* s);
|
239
|
+
void SetOption(const wchar_t* s);
|
240
|
+
|
241
|
+
};
|
242
|
+
|
243
|
+
}; // namespace
|
244
|
+
|
245
|
+
#endif // !defined(COCO_TAB_H__)
|
@@ -0,0 +1,41 @@
|
|
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 "Target.h"
|
31
|
+
#include "State.h"
|
32
|
+
|
33
|
+
namespace Coco {
|
34
|
+
|
35
|
+
Target::Target(State *s) {
|
36
|
+
next = NULL;
|
37
|
+
|
38
|
+
state = s;
|
39
|
+
}
|
40
|
+
|
41
|
+
}; // namespace
|
data/ext/cocor/Target.h
ADDED
@@ -0,0 +1,48 @@
|
|
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_TARGET_H__)
|
30
|
+
#define COCO_TARGET_H__
|
31
|
+
|
32
|
+
namespace Coco {
|
33
|
+
|
34
|
+
class State;
|
35
|
+
|
36
|
+
class Target // set of states that are reached by an action
|
37
|
+
{
|
38
|
+
public:
|
39
|
+
Target (State *s);
|
40
|
+
|
41
|
+
State *state; // target state
|
42
|
+
Target *next;
|
43
|
+
|
44
|
+
};
|
45
|
+
|
46
|
+
}; // namespace
|
47
|
+
|
48
|
+
#endif // !defined(COCO_TARGET_H__)
|
data/ext/cocor/build.bat
ADDED
data/ext/cocor/build.sh
ADDED
data/ext/cocor/coc.bat
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
coco Coco.ATG -namespace Coco
|
data/ext/cocor/coc.sh
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
#include <iostream>
|
3
|
+
#include <stdio.h>
|
4
|
+
|
5
|
+
#include "Scanner.h"
|
6
|
+
#include "Parser.h"
|
7
|
+
#include "Tab.h"
|
8
|
+
|
9
|
+
using namespace Coco;
|
10
|
+
|
11
|
+
// --------------
|
12
|
+
// UTILITIES
|
13
|
+
// --------------
|
14
|
+
|
15
|
+
std::wstring RSTRING_PTR_WIDE(VALUE rubyString)
|
16
|
+
{
|
17
|
+
std::wstring wc( RSTRING_LEN(rubyString), L'#' );
|
18
|
+
mbstowcs( &wc[0], RSTRING_PTR(rubyString), RSTRING_LEN(rubyString) );
|
19
|
+
return wc;
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE rb_str_new_wide(std::wstring str)
|
23
|
+
{
|
24
|
+
std::string s( str.begin(), str.end() );
|
25
|
+
return rb_str_new(s.c_str(), s.length());
|
26
|
+
}
|
27
|
+
|
28
|
+
// --------------
|
29
|
+
// METHODS
|
30
|
+
// --------------
|
31
|
+
|
32
|
+
VALUE method_test(VALUE rubySelf, VALUE rubyString)
|
33
|
+
{
|
34
|
+
std::wstring s(RSTRING_PTR_WIDE(rubyString));
|
35
|
+
s = L"test-" + s;
|
36
|
+
|
37
|
+
return rb_str_new_wide(s);
|
38
|
+
}
|
39
|
+
|
40
|
+
VALUE method_compile(VALUE rubySelf, VALUE rubySrcName, VALUE rubyFramedir, VALUE rubyNsName, VALUE rubyOutDir)
|
41
|
+
{
|
42
|
+
std::wstring srcNameW = RSTRING_PTR_WIDE(rubySrcName);
|
43
|
+
std::wstring nsNameW = RSTRING_PTR_WIDE(rubyNsName);
|
44
|
+
std::wstring frameDirW = RSTRING_PTR_WIDE(rubyFramedir);
|
45
|
+
std::wstring outDirW = RSTRING_PTR_WIDE(rubyOutDir);
|
46
|
+
|
47
|
+
const wchar_t *srcName = srcNameW.c_str(),
|
48
|
+
*nsName = nsNameW.c_str(),
|
49
|
+
*frameDir = frameDirW.c_str(),
|
50
|
+
*outDir = outDirW.c_str(),
|
51
|
+
*ddtString = NULL,
|
52
|
+
*traceFileName = NULL;
|
53
|
+
|
54
|
+
char *chTrFileName = NULL;
|
55
|
+
bool emitLines = false;
|
56
|
+
|
57
|
+
// basically copy pasta from Coco.cpp
|
58
|
+
|
59
|
+
int pos = coco_string_lastindexof(srcName, '/');
|
60
|
+
if (pos < 0) pos = coco_string_lastindexof(srcName, '\\');
|
61
|
+
wchar_t* file = coco_string_create(srcName);
|
62
|
+
wchar_t* srcDir = coco_string_create(srcName, 0, pos+1);
|
63
|
+
|
64
|
+
Coco::Scanner *scanner = new Coco::Scanner(file);
|
65
|
+
Coco::Parser *parser = new Coco::Parser(scanner);
|
66
|
+
|
67
|
+
traceFileName = coco_string_create_append(srcDir, L"trace.txt");
|
68
|
+
chTrFileName = coco_string_create_char(traceFileName);
|
69
|
+
|
70
|
+
if ((parser->trace = fopen(chTrFileName, "w")) == NULL) {
|
71
|
+
wprintf(L"-- could not open %hs\n", chTrFileName);
|
72
|
+
exit(1);
|
73
|
+
}
|
74
|
+
|
75
|
+
parser->tab = new Coco::Tab(parser);
|
76
|
+
parser->dfa = new Coco::DFA(parser);
|
77
|
+
parser->pgen = new Coco::ParserGen(parser);
|
78
|
+
|
79
|
+
parser->tab->srcName = coco_string_create(srcName);
|
80
|
+
parser->tab->srcDir = coco_string_create(srcDir);
|
81
|
+
parser->tab->nsName = nsName ? coco_string_create(nsName) : NULL;
|
82
|
+
parser->tab->frameDir = coco_string_create(frameDir);
|
83
|
+
parser->tab->outDir = coco_string_create(outDir != NULL ? outDir : srcDir);
|
84
|
+
parser->tab->emitLines = emitLines;
|
85
|
+
|
86
|
+
if (ddtString != NULL) parser->tab->SetDDT(ddtString);
|
87
|
+
|
88
|
+
parser->Parse();
|
89
|
+
|
90
|
+
fclose(parser->trace);
|
91
|
+
|
92
|
+
// obtain the FileSize
|
93
|
+
parser->trace = fopen(chTrFileName, "r");
|
94
|
+
fseek(parser->trace, 0, SEEK_END);
|
95
|
+
long fileSize = ftell(parser->trace);
|
96
|
+
fclose(parser->trace);
|
97
|
+
if (fileSize == 0) {
|
98
|
+
remove(chTrFileName);
|
99
|
+
} else {
|
100
|
+
wprintf(L"trace output is in %hs\n", chTrFileName);
|
101
|
+
}
|
102
|
+
|
103
|
+
wprintf(L"%d errors detected\n", parser->errors->count);
|
104
|
+
if (parser->errors->count != 0) {
|
105
|
+
exit(1);
|
106
|
+
}
|
107
|
+
|
108
|
+
delete parser->pgen;
|
109
|
+
delete parser->dfa;
|
110
|
+
delete parser->tab;
|
111
|
+
delete parser;
|
112
|
+
delete scanner;
|
113
|
+
coco_string_delete(file);
|
114
|
+
coco_string_delete(srcDir);
|
115
|
+
|
116
|
+
return Qnil;
|
117
|
+
}
|
118
|
+
|
119
|
+
extern "C" void Init_cocor()
|
120
|
+
{
|
121
|
+
VALUE cocor = rb_define_module("Cocor");
|
122
|
+
rb_define_method(cocor, "cocor_test", (VALUE(*)(ANYARGS))method_test,1);
|
123
|
+
rb_define_method(cocor, "cocor_compile", (VALUE(*)(ANYARGS))method_compile,4);
|
124
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
g++ *.cpp -o Coco.exe
|
data/ext/cocor/mkmf.log
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
have_library: checking for main() in -lstdc++... -------------------- yes
|
2
|
+
|
3
|
+
"gcc -o conftest -I/opt/chef/embedded/include/ruby-1.9.1/x86_64-darwin11.2.0 -I/opt/chef/embedded/include/ruby-1.9.1/ruby/backward -I/opt/chef/embedded/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/opt/chef/embedded/include -I/opt/chef/embedded/include -I/opt/chef/embedded/include/ncurses -arch x86_64 -O3 -g -pipe -Qunused-arguments -fno-common conftest.c -L. -L/opt/chef/embedded/lib -L/opt/chef/embedded/lib -L. -L/opt/chef/embedded/lib -arch x86_64 -L/opt/chef/embedded/lib -m64 -lruby.1.9.1 -lpthread -ldl -lobjc "
|
4
|
+
checked program was:
|
5
|
+
/* begin */
|
6
|
+
1: #include "ruby.h"
|
7
|
+
2:
|
8
|
+
3: int main(int argc, char **argv)
|
9
|
+
4: {
|
10
|
+
5: return 0;
|
11
|
+
6: }
|
12
|
+
/* end */
|
13
|
+
|
14
|
+
"gcc -o conftest -I/opt/chef/embedded/include/ruby-1.9.1/x86_64-darwin11.2.0 -I/opt/chef/embedded/include/ruby-1.9.1/ruby/backward -I/opt/chef/embedded/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/opt/chef/embedded/include -I/opt/chef/embedded/include -I/opt/chef/embedded/include/ncurses -arch x86_64 -O3 -g -pipe -Qunused-arguments -fno-common conftest.c -L. -L/opt/chef/embedded/lib -L/opt/chef/embedded/lib -L. -L/opt/chef/embedded/lib -arch x86_64 -L/opt/chef/embedded/lib -m64 -lruby.1.9.1 -lstdc++ -lpthread -ldl -lobjc "
|
15
|
+
conftest.c:4:53: error: use of undeclared identifier 'main'
|
16
|
+
int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
|
17
|
+
^
|
18
|
+
1 error generated.
|
19
|
+
checked program was:
|
20
|
+
/* begin */
|
21
|
+
1: #include "ruby.h"
|
22
|
+
2:
|
23
|
+
3: /*top*/
|
24
|
+
4: int t() { void ((*volatile p)()); p = (void ((*)()))main; return 0; }
|
25
|
+
5: int main(int argc, char **argv)
|
26
|
+
6: {
|
27
|
+
7: if (argc > 1000000) {
|
28
|
+
8: printf("%p", &t);
|
29
|
+
9: }
|
30
|
+
10:
|
31
|
+
11: return 0;
|
32
|
+
12: }
|
33
|
+
/* end */
|
34
|
+
|
35
|
+
"gcc -o conftest -I/opt/chef/embedded/include/ruby-1.9.1/x86_64-darwin11.2.0 -I/opt/chef/embedded/include/ruby-1.9.1/ruby/backward -I/opt/chef/embedded/include/ruby-1.9.1 -I. -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -I/opt/chef/embedded/include -I/opt/chef/embedded/include -I/opt/chef/embedded/include/ncurses -arch x86_64 -O3 -g -pipe -Qunused-arguments -fno-common conftest.c -L. -L/opt/chef/embedded/lib -L/opt/chef/embedded/lib -L. -L/opt/chef/embedded/lib -arch x86_64 -L/opt/chef/embedded/lib -m64 -lruby.1.9.1 -lstdc++ -lpthread -ldl -lobjc "
|
36
|
+
conftest.c:4:11: warning: implicit declaration of function 'main' is invalid in C99 [-Wimplicit-function-declaration]
|
37
|
+
int t() { main(); return 0; }
|
38
|
+
^
|
39
|
+
1 warning generated.
|
40
|
+
checked program was:
|
41
|
+
/* begin */
|
42
|
+
1: #include "ruby.h"
|
43
|
+
2:
|
44
|
+
3: /*top*/
|
45
|
+
4: int t() { main(); return 0; }
|
46
|
+
5: int main(int argc, char **argv)
|
47
|
+
6: {
|
48
|
+
7: if (argc > 1000000) {
|
49
|
+
8: printf("%p", &t);
|
50
|
+
9: }
|
51
|
+
10:
|
52
|
+
11: return 0;
|
53
|
+
12: }
|
54
|
+
/* end */
|
55
|
+
|
56
|
+
--------------------
|
57
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
jar -cfM CocoSourcesCPP.zip *.atg *.frame *.bat *.h *.cpp *.sh Makefile
|
data/lib/cocor.rb
ADDED
data/lib/ruco/version.rb
ADDED