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,173 @@
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
+ Trace output options
30
+ 0 | A: prints the states of the scanner automaton
31
+ 1 | F: prints the First and Follow sets of all nonterminals
32
+ 2 | G: prints the syntax graph of the productions
33
+ 3 | I: traces the computation of the First sets
34
+ 4 | J: prints the sets associated with ANYs and synchronisation sets
35
+ 6 | S: prints the symbol table (terminals, nonterminals, pragmas)
36
+ 7 | X: prints a cross reference list of all syntax symbols
37
+ 8 | P: prints statistics about the Coco run
38
+
39
+ Trace output can be switched on by the pragma
40
+ $ { digit | letter }
41
+ in the attributed grammar or as a command-line option
42
+ -------------------------------------------------------------------------*/
43
+
44
+
45
+ #include <stdio.h>
46
+ #include "Scanner.h"
47
+ #include "Parser.h"
48
+ #include "Tab.h"
49
+
50
+ using namespace Coco;
51
+
52
+ #ifdef _WIN32
53
+ int wmain(int argc, wchar_t *argv[]) {
54
+ #elif defined __GNUC__
55
+ int main(int argc, char *argv_[]) {
56
+ wchar_t ** argv = new wchar_t*[argc];
57
+ for (int i = 0; i < argc; ++i) {
58
+ argv[i] = coco_string_create(argv_[i]);
59
+ }
60
+ #else
61
+ #error unknown compiler!
62
+ #endif
63
+
64
+ wprintf(L"Coco/R (Jan 02, 2012)\n");
65
+
66
+ wchar_t *srcName = NULL, *nsName = NULL, *frameDir = NULL, *ddtString = NULL, *traceFileName = NULL;
67
+ wchar_t *outDir = NULL;
68
+ char *chTrFileName = NULL;
69
+ bool emitLines = false;
70
+
71
+ for (int i = 1; i < argc; i++) {
72
+ if (coco_string_equal(argv[i], L"-namespace") && i < argc - 1) nsName = coco_string_create(argv[++i]);
73
+ else if (coco_string_equal(argv[i], L"-frames") && i < argc - 1) frameDir = coco_string_create(argv[++i]);
74
+ else if (coco_string_equal(argv[i], L"-trace") && i < argc - 1) ddtString = coco_string_create(argv[++i]);
75
+ else if (coco_string_equal(argv[i], L"-o") && i < argc - 1) outDir = coco_string_create_append(argv[++i], L"/");
76
+ else if (coco_string_equal(argv[i], L"-lines")) emitLines = true;
77
+ else srcName = coco_string_create(argv[i]);
78
+ }
79
+
80
+ #if defined __GNUC__
81
+ for (int i = 0; i < argc; ++i) {
82
+ coco_string_delete(argv[i]);
83
+ }
84
+ delete [] argv; argv = NULL;
85
+ #endif
86
+
87
+ if (argc > 0 && srcName != NULL) {
88
+ int pos = coco_string_lastindexof(srcName, '/');
89
+ if (pos < 0) pos = coco_string_lastindexof(srcName, '\\');
90
+ wchar_t* file = coco_string_create(srcName);
91
+ wchar_t* srcDir = coco_string_create(srcName, 0, pos+1);
92
+
93
+ Coco::Scanner *scanner = new Coco::Scanner(file);
94
+ Coco::Parser *parser = new Coco::Parser(scanner);
95
+
96
+ traceFileName = coco_string_create_append(srcDir, L"trace.txt");
97
+ chTrFileName = coco_string_create_char(traceFileName);
98
+
99
+ if ((parser->trace = fopen(chTrFileName, "w")) == NULL) {
100
+ wprintf(L"-- could not open %hs\n", chTrFileName);
101
+ exit(1);
102
+ }
103
+
104
+ parser->tab = new Coco::Tab(parser);
105
+ parser->dfa = new Coco::DFA(parser);
106
+ parser->pgen = new Coco::ParserGen(parser);
107
+
108
+ parser->tab->srcName = coco_string_create(srcName);
109
+ parser->tab->srcDir = coco_string_create(srcDir);
110
+ parser->tab->nsName = nsName ? coco_string_create(nsName) : NULL;
111
+ parser->tab->frameDir = coco_string_create(frameDir);
112
+ parser->tab->outDir = coco_string_create(outDir != NULL ? outDir : srcDir);
113
+ parser->tab->emitLines = emitLines;
114
+
115
+ if (ddtString != NULL) parser->tab->SetDDT(ddtString);
116
+
117
+ parser->Parse();
118
+
119
+ fclose(parser->trace);
120
+
121
+ // obtain the FileSize
122
+ parser->trace = fopen(chTrFileName, "r");
123
+ fseek(parser->trace, 0, SEEK_END);
124
+ long fileSize = ftell(parser->trace);
125
+ fclose(parser->trace);
126
+ if (fileSize == 0) {
127
+ remove(chTrFileName);
128
+ } else {
129
+ wprintf(L"trace output is in %hs\n", chTrFileName);
130
+ }
131
+
132
+ wprintf(L"%d errors detected\n", parser->errors->count);
133
+ if (parser->errors->count != 0) {
134
+ exit(1);
135
+ }
136
+
137
+ delete parser->pgen;
138
+ delete parser->dfa;
139
+ delete parser->tab;
140
+ delete parser;
141
+ delete scanner;
142
+ coco_string_delete(file);
143
+ coco_string_delete(srcDir);
144
+ } else {
145
+ wprintf(L"Usage: Coco Grammar.ATG {Option}\n");
146
+ wprintf(L"Options:\n");
147
+ wprintf(L" -namespace <namespaceName>\n");
148
+ wprintf(L" -frames <frameFilesDirectory>\n");
149
+ wprintf(L" -trace <traceString>\n");
150
+ wprintf(L" -o <outputDirectory>\n");
151
+ wprintf(L" -lines\n");
152
+ wprintf(L"Valid characters in the trace string:\n");
153
+ wprintf(L" A trace automaton\n");
154
+ wprintf(L" F list first/follow sets\n");
155
+ wprintf(L" G print syntax graph\n");
156
+ wprintf(L" I trace computation of first sets\n");
157
+ wprintf(L" J list ANY and SYNC sets\n");
158
+ wprintf(L" P print statistics\n");
159
+ wprintf(L" S list symbol table\n");
160
+ wprintf(L" X list cross reference table\n");
161
+ wprintf(L"Scanner.frame and Parser.frame files needed in ATG directory\n");
162
+ wprintf(L"or in a directory specified in the -frames option.\n");
163
+ }
164
+
165
+ coco_string_delete(srcName);
166
+ coco_string_delete(nsName);
167
+ coco_string_delete(frameDir);
168
+ coco_string_delete(ddtString);
169
+ coco_string_delete(chTrFileName);
170
+ coco_string_delete(traceFileName);
171
+
172
+ return 0;
173
+ }
@@ -0,0 +1,45 @@
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 "Comment.h"
30
+ #include "Scanner.h"
31
+
32
+ namespace Coco {
33
+
34
+ Comment::Comment(wchar_t* start, wchar_t* stop, bool nested) {
35
+ this->start = coco_string_create(start);
36
+ this->stop = coco_string_create(stop);
37
+ this->nested = nested;
38
+ }
39
+
40
+ Comment::~Comment() {
41
+ coco_string_delete(start);
42
+ coco_string_delete(stop);
43
+ }
44
+
45
+ }; // namespace
@@ -0,0 +1,51 @@
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_COMMENT_H__)
30
+ #define COCO_COMMENT_H__
31
+
32
+ #include <wchar.h>
33
+
34
+ namespace Coco {
35
+
36
+ class Comment // info about comment syntax
37
+ {
38
+ public:
39
+ wchar_t* start;
40
+ wchar_t* stop;
41
+ bool nested;
42
+ Comment *next;
43
+
44
+ Comment(wchar_t* start, wchar_t* stop, bool nested);
45
+ virtual ~Comment();
46
+
47
+ };
48
+
49
+ }; // namespace
50
+
51
+ #endif // !defined(COCO_COMMENT_H__)
@@ -0,0 +1,27 @@
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
+ -----------------------------------------------------------------------*/