meta_compile 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -0
- data/meta_compile.gemspec +1 -1
- metadata +1 -7
- data/bootstrap/bootstrapped_c +0 -0
- data/bootstrap/compile_syntax_c_to_ruby.c +0 -214
- data/bootstrap/meta_r +0 -0
- data/bootstrap/meta_ruby_compiler2.rb +0 -230
- data/bootstrap/meta_ruby_compiler3.rb +0 -230
- data/bootstrap/meta_ruby_compiler_from_c.rb +0 -230
data/Rakefile
CHANGED
data/meta_compile.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meta_compile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -23,16 +23,10 @@ files:
|
|
23
23
|
- meta_compile.gemspec
|
24
24
|
- bin/meta_compile
|
25
25
|
- bootstrap/bootstrap.c
|
26
|
-
- bootstrap/bootstrapped_c
|
27
|
-
- bootstrap/compile_syntax_c_to_ruby.c
|
28
26
|
- bootstrap/meta_for_c.txt
|
29
27
|
- bootstrap/meta_for_ruby.txt
|
30
28
|
- bootstrap/meta_for_ruby_single_flag.txt
|
31
|
-
- bootstrap/meta_r
|
32
29
|
- bootstrap/meta_ruby_compiler.rb
|
33
|
-
- bootstrap/meta_ruby_compiler2.rb
|
34
|
-
- bootstrap/meta_ruby_compiler3.rb
|
35
|
-
- bootstrap/meta_ruby_compiler_from_c.rb
|
36
30
|
- bootstrap/original_support.h
|
37
31
|
- bootstrap/support.h
|
38
32
|
homepage: http://rubygems.org/gems/meta_compile
|
data/bootstrap/bootstrapped_c
DELETED
Binary file
|
@@ -1,214 +0,0 @@
|
|
1
|
-
#include "support.h"
|
2
|
-
void meta_outarg(void)
|
3
|
-
{
|
4
|
-
do {
|
5
|
-
read_literal("$");
|
6
|
-
if (test_flag) {
|
7
|
-
emit("@o.print @t");
|
8
|
-
emit_nl();
|
9
|
-
}
|
10
|
-
if (test_flag) { break; }
|
11
|
-
read_string();
|
12
|
-
if (test_flag) {
|
13
|
-
emit("@o.print ");
|
14
|
-
emit_token();
|
15
|
-
emit_nl();
|
16
|
-
}
|
17
|
-
} while (0);
|
18
|
-
}
|
19
|
-
void meta_out(void)
|
20
|
-
{
|
21
|
-
do {
|
22
|
-
read_literal("<");
|
23
|
-
if (test_flag) {
|
24
|
-
do {
|
25
|
-
meta_outarg();
|
26
|
-
} while (test_flag);
|
27
|
-
test_flag = 1;
|
28
|
-
error_if_false();
|
29
|
-
read_literal(">");
|
30
|
-
error_if_false();
|
31
|
-
emit("@o.print \"\\n\"");
|
32
|
-
emit_nl();
|
33
|
-
}
|
34
|
-
} while (0);
|
35
|
-
}
|
36
|
-
void meta_exp3(void)
|
37
|
-
{
|
38
|
-
do {
|
39
|
-
read_id();
|
40
|
-
if (test_flag) {
|
41
|
-
emit("compile_");
|
42
|
-
emit_token();
|
43
|
-
emit_nl();
|
44
|
-
}
|
45
|
-
if (test_flag) { break; }
|
46
|
-
read_string();
|
47
|
-
if (test_flag) {
|
48
|
-
emit("@i.scan /\\s*/; s=");
|
49
|
-
emit_token();
|
50
|
-
emit("; l=s.length;");
|
51
|
-
emit_nl();
|
52
|
-
emit("@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil");
|
53
|
-
emit_nl();
|
54
|
-
}
|
55
|
-
if (test_flag) { break; }
|
56
|
-
read_literal(".id");
|
57
|
-
if (test_flag) {
|
58
|
-
emit("@i.scan /\\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/");
|
59
|
-
emit_nl();
|
60
|
-
}
|
61
|
-
if (test_flag) { break; }
|
62
|
-
read_literal(".string");
|
63
|
-
if (test_flag) {
|
64
|
-
emit("@i.scan /\\s*/; @f = @t = @i.scan /\\047[^\\047]*\\047/");
|
65
|
-
emit_nl();
|
66
|
-
}
|
67
|
-
if (test_flag) { break; }
|
68
|
-
read_literal("(");
|
69
|
-
if (test_flag) {
|
70
|
-
meta_exp1();
|
71
|
-
error_if_false();
|
72
|
-
read_literal(")");
|
73
|
-
error_if_false();
|
74
|
-
}
|
75
|
-
if (test_flag) { break; }
|
76
|
-
read_literal(".e");
|
77
|
-
if (test_flag) {
|
78
|
-
emit("@f = true");
|
79
|
-
emit_nl();
|
80
|
-
}
|
81
|
-
if (test_flag) { break; }
|
82
|
-
read_literal("*");
|
83
|
-
if (test_flag) {
|
84
|
-
emit("begin");
|
85
|
-
emit_nl();
|
86
|
-
meta_exp3();
|
87
|
-
error_if_false();
|
88
|
-
emit("end while @f");
|
89
|
-
emit_nl();
|
90
|
-
emit("@f = true");
|
91
|
-
emit_nl();
|
92
|
-
}
|
93
|
-
} while (0);
|
94
|
-
}
|
95
|
-
void meta_exp2(void)
|
96
|
-
{
|
97
|
-
do {
|
98
|
-
do {
|
99
|
-
meta_exp3();
|
100
|
-
if (test_flag) {
|
101
|
-
emit("if @f");
|
102
|
-
emit_nl();
|
103
|
-
}
|
104
|
-
if (test_flag) { break; }
|
105
|
-
meta_out();
|
106
|
-
if (test_flag) {
|
107
|
-
emit("if true");
|
108
|
-
emit_nl();
|
109
|
-
}
|
110
|
-
} while (0);
|
111
|
-
if (test_flag) {
|
112
|
-
do {
|
113
|
-
do {
|
114
|
-
meta_exp3();
|
115
|
-
if (test_flag) {
|
116
|
-
emit("raise(\"error at: \" + @i.rest.split(\"\\n\")[0]) if !@f");
|
117
|
-
emit_nl();
|
118
|
-
}
|
119
|
-
if (test_flag) { break; }
|
120
|
-
meta_out();
|
121
|
-
if (test_flag) {
|
122
|
-
}
|
123
|
-
} while (0);
|
124
|
-
} while (test_flag);
|
125
|
-
test_flag = 1;
|
126
|
-
error_if_false();
|
127
|
-
emit("end");
|
128
|
-
emit_nl();
|
129
|
-
}
|
130
|
-
} while (0);
|
131
|
-
}
|
132
|
-
void meta_exp1(void)
|
133
|
-
{
|
134
|
-
do {
|
135
|
-
emit("begin");
|
136
|
-
emit_nl();
|
137
|
-
if (1) {
|
138
|
-
meta_exp2();
|
139
|
-
error_if_false();
|
140
|
-
do {
|
141
|
-
do {
|
142
|
-
read_literal("|");
|
143
|
-
if (test_flag) {
|
144
|
-
emit("break if @f");
|
145
|
-
emit_nl();
|
146
|
-
meta_exp2();
|
147
|
-
error_if_false();
|
148
|
-
}
|
149
|
-
} while (0);
|
150
|
-
} while (test_flag);
|
151
|
-
test_flag = 1;
|
152
|
-
error_if_false();
|
153
|
-
emit("end while false");
|
154
|
-
emit_nl();
|
155
|
-
}
|
156
|
-
} while (0);
|
157
|
-
}
|
158
|
-
void meta_rule(void)
|
159
|
-
{
|
160
|
-
do {
|
161
|
-
read_id();
|
162
|
-
if (test_flag) {
|
163
|
-
emit("def compile_");
|
164
|
-
emit_token();
|
165
|
-
emit_nl();
|
166
|
-
read_literal("=");
|
167
|
-
error_if_false();
|
168
|
-
meta_exp1();
|
169
|
-
error_if_false();
|
170
|
-
read_literal(";");
|
171
|
-
error_if_false();
|
172
|
-
emit("end");
|
173
|
-
emit_nl();
|
174
|
-
}
|
175
|
-
} while (0);
|
176
|
-
}
|
177
|
-
void meta_program(void)
|
178
|
-
{
|
179
|
-
do {
|
180
|
-
read_literal(".syntax");
|
181
|
-
if (test_flag) {
|
182
|
-
read_id();
|
183
|
-
error_if_false();
|
184
|
-
emit("#!/usr/bin/env ruby");
|
185
|
-
emit_nl();
|
186
|
-
emit("require \"strscan\"");
|
187
|
-
emit_nl();
|
188
|
-
emit("class ");
|
189
|
-
emit_token();
|
190
|
-
emit_nl();
|
191
|
-
emit("def compile(str, out)");
|
192
|
-
emit_nl();
|
193
|
-
emit("@i, @o = StringScanner.new(str), out");
|
194
|
-
emit_nl();
|
195
|
-
emit("compile_program");
|
196
|
-
emit_nl();
|
197
|
-
emit("end");
|
198
|
-
emit_nl();
|
199
|
-
do {
|
200
|
-
meta_rule();
|
201
|
-
} while (test_flag);
|
202
|
-
test_flag = 1;
|
203
|
-
error_if_false();
|
204
|
-
read_literal(".end");
|
205
|
-
error_if_false();
|
206
|
-
emit("end");
|
207
|
-
emit_nl();
|
208
|
-
emit("begin; puts(\"Use: \" + $0 + \" <in> <out>\"); exit; end if ARGV.length != 2");
|
209
|
-
emit_nl();
|
210
|
-
emit("File.open(ARGV[1], \"w\") {|f| RMetaII.new.compile(File.read(ARGV[0]), f)}");
|
211
|
-
emit_nl();
|
212
|
-
}
|
213
|
-
} while (0);
|
214
|
-
}
|
data/bootstrap/meta_r
DELETED
Binary file
|
@@ -1,230 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require "strscan"
|
3
|
-
class RMetaII
|
4
|
-
def compile(str, out)
|
5
|
-
@i, @o = StringScanner.new(str), out
|
6
|
-
compile_program
|
7
|
-
end
|
8
|
-
def compile_outarg
|
9
|
-
begin
|
10
|
-
@i.scan /\s*/; s='$'; l=s.length;
|
11
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
12
|
-
if @f
|
13
|
-
@o.print '@o.print @t'
|
14
|
-
@o.print "\n"
|
15
|
-
end
|
16
|
-
break if @f
|
17
|
-
@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/
|
18
|
-
if @f
|
19
|
-
@o.print '@o.print '
|
20
|
-
@o.print @t
|
21
|
-
@o.print "\n"
|
22
|
-
end
|
23
|
-
end while false
|
24
|
-
end
|
25
|
-
def compile_out
|
26
|
-
begin
|
27
|
-
@i.scan /\s*/; s='<'; l=s.length;
|
28
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
29
|
-
if @f
|
30
|
-
begin
|
31
|
-
compile_outarg
|
32
|
-
end while @f
|
33
|
-
@f = true
|
34
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
35
|
-
@i.scan /\s*/; s='>'; l=s.length;
|
36
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
37
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
38
|
-
@o.print '@o.print "\n"'
|
39
|
-
@o.print "\n"
|
40
|
-
end
|
41
|
-
end while false
|
42
|
-
end
|
43
|
-
def compile_exp3
|
44
|
-
begin
|
45
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
46
|
-
if @f
|
47
|
-
@o.print 'compile_'
|
48
|
-
@o.print @t
|
49
|
-
@o.print "\n"
|
50
|
-
end
|
51
|
-
break if @f
|
52
|
-
@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/
|
53
|
-
if @f
|
54
|
-
@o.print '@i.scan /\s*/; s='
|
55
|
-
@o.print @t
|
56
|
-
@o.print '; l=s.length;'
|
57
|
-
@o.print "\n"
|
58
|
-
@o.print '@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil'
|
59
|
-
@o.print "\n"
|
60
|
-
end
|
61
|
-
break if @f
|
62
|
-
@i.scan /\s*/; s='.id'; l=s.length;
|
63
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
64
|
-
if @f
|
65
|
-
@o.print '@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/'
|
66
|
-
@o.print "\n"
|
67
|
-
end
|
68
|
-
break if @f
|
69
|
-
@i.scan /\s*/; s='.string'; l=s.length;
|
70
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
71
|
-
if @f
|
72
|
-
@o.print '@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/'
|
73
|
-
@o.print "\n"
|
74
|
-
end
|
75
|
-
break if @f
|
76
|
-
@i.scan /\s*/; s='('; l=s.length;
|
77
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
78
|
-
if @f
|
79
|
-
compile_exp1
|
80
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
81
|
-
@i.scan /\s*/; s=')'; l=s.length;
|
82
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
83
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
84
|
-
end
|
85
|
-
break if @f
|
86
|
-
@i.scan /\s*/; s='.e'; l=s.length;
|
87
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
88
|
-
if @f
|
89
|
-
@o.print '@f = true'
|
90
|
-
@o.print "\n"
|
91
|
-
end
|
92
|
-
break if @f
|
93
|
-
@i.scan /\s*/; s='*'; l=s.length;
|
94
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
95
|
-
if @f
|
96
|
-
@o.print 'begin'
|
97
|
-
@o.print "\n"
|
98
|
-
compile_exp3
|
99
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
100
|
-
@o.print 'end while @f'
|
101
|
-
@o.print "\n"
|
102
|
-
@o.print '@f = true'
|
103
|
-
@o.print "\n"
|
104
|
-
end
|
105
|
-
end while false
|
106
|
-
end
|
107
|
-
def compile_exp2
|
108
|
-
begin
|
109
|
-
begin
|
110
|
-
compile_exp3
|
111
|
-
if @f
|
112
|
-
@o.print 'if @f'
|
113
|
-
@o.print "\n"
|
114
|
-
end
|
115
|
-
break if @f
|
116
|
-
compile_out
|
117
|
-
if @f
|
118
|
-
@o.print 'if true'
|
119
|
-
@o.print "\n"
|
120
|
-
end
|
121
|
-
end while false
|
122
|
-
if @f
|
123
|
-
begin
|
124
|
-
begin
|
125
|
-
compile_exp3
|
126
|
-
if @f
|
127
|
-
@o.print 'raise("error at: " + @i.rest.split("\n")[0]) if !@f'
|
128
|
-
@o.print "\n"
|
129
|
-
end
|
130
|
-
break if @f
|
131
|
-
compile_out
|
132
|
-
if @f
|
133
|
-
end
|
134
|
-
end while false
|
135
|
-
end while @f
|
136
|
-
@f = true
|
137
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
138
|
-
@o.print 'end'
|
139
|
-
@o.print "\n"
|
140
|
-
end
|
141
|
-
end while false
|
142
|
-
end
|
143
|
-
def compile_exp1
|
144
|
-
begin
|
145
|
-
@o.print 'begin'
|
146
|
-
@o.print "\n"
|
147
|
-
if true
|
148
|
-
compile_exp2
|
149
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
150
|
-
begin
|
151
|
-
begin
|
152
|
-
@i.scan /\s*/; s='|'; l=s.length;
|
153
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
154
|
-
if @f
|
155
|
-
@o.print 'break if @f'
|
156
|
-
@o.print "\n"
|
157
|
-
compile_exp2
|
158
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
159
|
-
end
|
160
|
-
end while false
|
161
|
-
end while @f
|
162
|
-
@f = true
|
163
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
164
|
-
@o.print 'end while false'
|
165
|
-
@o.print "\n"
|
166
|
-
end
|
167
|
-
end while false
|
168
|
-
end
|
169
|
-
def compile_rule
|
170
|
-
begin
|
171
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
172
|
-
if @f
|
173
|
-
@o.print 'def compile_'
|
174
|
-
@o.print @t
|
175
|
-
@o.print "\n"
|
176
|
-
@i.scan /\s*/; s='='; l=s.length;
|
177
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
178
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
179
|
-
compile_exp1
|
180
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
181
|
-
@i.scan /\s*/; s=';'; l=s.length;
|
182
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
183
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
184
|
-
@o.print 'end'
|
185
|
-
@o.print "\n"
|
186
|
-
end
|
187
|
-
end while false
|
188
|
-
end
|
189
|
-
def compile_program
|
190
|
-
begin
|
191
|
-
@i.scan /\s*/; s='.syntax'; l=s.length;
|
192
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
193
|
-
if @f
|
194
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
195
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
196
|
-
@o.print '#!/usr/bin/env ruby'
|
197
|
-
@o.print "\n"
|
198
|
-
@o.print 'require "strscan"'
|
199
|
-
@o.print "\n"
|
200
|
-
@o.print 'class '
|
201
|
-
@o.print @t
|
202
|
-
@o.print "\n"
|
203
|
-
@o.print 'def compile(str, out)'
|
204
|
-
@o.print "\n"
|
205
|
-
@o.print '@i, @o = StringScanner.new(str), out'
|
206
|
-
@o.print "\n"
|
207
|
-
@o.print 'compile_program'
|
208
|
-
@o.print "\n"
|
209
|
-
@o.print 'end'
|
210
|
-
@o.print "\n"
|
211
|
-
begin
|
212
|
-
compile_rule
|
213
|
-
end while @f
|
214
|
-
@f = true
|
215
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
216
|
-
@i.scan /\s*/; s='.end'; l=s.length;
|
217
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
218
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
219
|
-
@o.print 'end'
|
220
|
-
@o.print "\n"
|
221
|
-
@o.print 'begin; puts("Use: " + $0 + " <in> <out>"); exit; end if ARGV.length != 2'
|
222
|
-
@o.print "\n"
|
223
|
-
@o.print 'File.open(ARGV[1], "w") {|f| RMetaII.new.compile(File.read(ARGV[0]), f)}'
|
224
|
-
@o.print "\n"
|
225
|
-
end
|
226
|
-
end while false
|
227
|
-
end
|
228
|
-
end
|
229
|
-
begin; puts("Use: " + $0 + " <in> <out>"); exit; end if ARGV.length != 2
|
230
|
-
File.open(ARGV[1], "w") {|f| RMetaII.new.compile(File.read(ARGV[0]), f)}
|
@@ -1,230 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require "strscan"
|
3
|
-
class RMetaII
|
4
|
-
def compile(str, out)
|
5
|
-
@i, @o = StringScanner.new(str), out
|
6
|
-
compile_program
|
7
|
-
end
|
8
|
-
def compile_outarg
|
9
|
-
begin
|
10
|
-
@i.scan /\s*/; s='$'; l=s.length;
|
11
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
12
|
-
if @f
|
13
|
-
@o.print '@o.print @t'
|
14
|
-
@o.print "\n"
|
15
|
-
end
|
16
|
-
break if @f
|
17
|
-
@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/
|
18
|
-
if @f
|
19
|
-
@o.print '@o.print '
|
20
|
-
@o.print @t
|
21
|
-
@o.print "\n"
|
22
|
-
end
|
23
|
-
end while false
|
24
|
-
end
|
25
|
-
def compile_out
|
26
|
-
begin
|
27
|
-
@i.scan /\s*/; s='<'; l=s.length;
|
28
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
29
|
-
if @f
|
30
|
-
begin
|
31
|
-
compile_outarg
|
32
|
-
end while @f
|
33
|
-
@f = true
|
34
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
35
|
-
@i.scan /\s*/; s='>'; l=s.length;
|
36
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
37
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
38
|
-
@o.print '@o.print "\n"'
|
39
|
-
@o.print "\n"
|
40
|
-
end
|
41
|
-
end while false
|
42
|
-
end
|
43
|
-
def compile_exp3
|
44
|
-
begin
|
45
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
46
|
-
if @f
|
47
|
-
@o.print 'compile_'
|
48
|
-
@o.print @t
|
49
|
-
@o.print "\n"
|
50
|
-
end
|
51
|
-
break if @f
|
52
|
-
@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/
|
53
|
-
if @f
|
54
|
-
@o.print '@i.scan /\s*/; s='
|
55
|
-
@o.print @t
|
56
|
-
@o.print '; l=s.length;'
|
57
|
-
@o.print "\n"
|
58
|
-
@o.print '@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil'
|
59
|
-
@o.print "\n"
|
60
|
-
end
|
61
|
-
break if @f
|
62
|
-
@i.scan /\s*/; s='.id'; l=s.length;
|
63
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
64
|
-
if @f
|
65
|
-
@o.print '@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/'
|
66
|
-
@o.print "\n"
|
67
|
-
end
|
68
|
-
break if @f
|
69
|
-
@i.scan /\s*/; s='.string'; l=s.length;
|
70
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
71
|
-
if @f
|
72
|
-
@o.print '@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/'
|
73
|
-
@o.print "\n"
|
74
|
-
end
|
75
|
-
break if @f
|
76
|
-
@i.scan /\s*/; s='('; l=s.length;
|
77
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
78
|
-
if @f
|
79
|
-
compile_exp1
|
80
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
81
|
-
@i.scan /\s*/; s=')'; l=s.length;
|
82
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
83
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
84
|
-
end
|
85
|
-
break if @f
|
86
|
-
@i.scan /\s*/; s='.e'; l=s.length;
|
87
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
88
|
-
if @f
|
89
|
-
@o.print '@f = true'
|
90
|
-
@o.print "\n"
|
91
|
-
end
|
92
|
-
break if @f
|
93
|
-
@i.scan /\s*/; s='*'; l=s.length;
|
94
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
95
|
-
if @f
|
96
|
-
@o.print 'begin'
|
97
|
-
@o.print "\n"
|
98
|
-
compile_exp3
|
99
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
100
|
-
@o.print 'end while @f'
|
101
|
-
@o.print "\n"
|
102
|
-
@o.print '@f = true'
|
103
|
-
@o.print "\n"
|
104
|
-
end
|
105
|
-
end while false
|
106
|
-
end
|
107
|
-
def compile_exp2
|
108
|
-
begin
|
109
|
-
begin
|
110
|
-
compile_exp3
|
111
|
-
if @f
|
112
|
-
@o.print 'if @f'
|
113
|
-
@o.print "\n"
|
114
|
-
end
|
115
|
-
break if @f
|
116
|
-
compile_out
|
117
|
-
if @f
|
118
|
-
@o.print 'if true'
|
119
|
-
@o.print "\n"
|
120
|
-
end
|
121
|
-
end while false
|
122
|
-
if @f
|
123
|
-
begin
|
124
|
-
begin
|
125
|
-
compile_exp3
|
126
|
-
if @f
|
127
|
-
@o.print 'raise("error at: " + @i.rest.split("\n")[0]) if !@f'
|
128
|
-
@o.print "\n"
|
129
|
-
end
|
130
|
-
break if @f
|
131
|
-
compile_out
|
132
|
-
if @f
|
133
|
-
end
|
134
|
-
end while false
|
135
|
-
end while @f
|
136
|
-
@f = true
|
137
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
138
|
-
@o.print 'end'
|
139
|
-
@o.print "\n"
|
140
|
-
end
|
141
|
-
end while false
|
142
|
-
end
|
143
|
-
def compile_exp1
|
144
|
-
begin
|
145
|
-
@o.print 'begin'
|
146
|
-
@o.print "\n"
|
147
|
-
if true
|
148
|
-
compile_exp2
|
149
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
150
|
-
begin
|
151
|
-
begin
|
152
|
-
@i.scan /\s*/; s='|'; l=s.length;
|
153
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
154
|
-
if @f
|
155
|
-
@o.print 'break if @f'
|
156
|
-
@o.print "\n"
|
157
|
-
compile_exp2
|
158
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
159
|
-
end
|
160
|
-
end while false
|
161
|
-
end while @f
|
162
|
-
@f = true
|
163
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
164
|
-
@o.print 'end while false'
|
165
|
-
@o.print "\n"
|
166
|
-
end
|
167
|
-
end while false
|
168
|
-
end
|
169
|
-
def compile_rule
|
170
|
-
begin
|
171
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
172
|
-
if @f
|
173
|
-
@o.print 'def compile_'
|
174
|
-
@o.print @t
|
175
|
-
@o.print "\n"
|
176
|
-
@i.scan /\s*/; s='='; l=s.length;
|
177
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
178
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
179
|
-
compile_exp1
|
180
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
181
|
-
@i.scan /\s*/; s=';'; l=s.length;
|
182
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
183
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
184
|
-
@o.print 'end'
|
185
|
-
@o.print "\n"
|
186
|
-
end
|
187
|
-
end while false
|
188
|
-
end
|
189
|
-
def compile_program
|
190
|
-
begin
|
191
|
-
@i.scan /\s*/; s='.syntax'; l=s.length;
|
192
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
193
|
-
if @f
|
194
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
195
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
196
|
-
@o.print '#!/usr/bin/env ruby'
|
197
|
-
@o.print "\n"
|
198
|
-
@o.print 'require "strscan"'
|
199
|
-
@o.print "\n"
|
200
|
-
@o.print 'class '
|
201
|
-
@o.print @t
|
202
|
-
@o.print "\n"
|
203
|
-
@o.print 'def compile(str, out)'
|
204
|
-
@o.print "\n"
|
205
|
-
@o.print '@i, @o = StringScanner.new(str), out'
|
206
|
-
@o.print "\n"
|
207
|
-
@o.print 'compile_program'
|
208
|
-
@o.print "\n"
|
209
|
-
@o.print 'end'
|
210
|
-
@o.print "\n"
|
211
|
-
begin
|
212
|
-
compile_rule
|
213
|
-
end while @f
|
214
|
-
@f = true
|
215
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
216
|
-
@i.scan /\s*/; s='.end'; l=s.length;
|
217
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
218
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
219
|
-
@o.print 'end'
|
220
|
-
@o.print "\n"
|
221
|
-
@o.print 'begin; puts("Use: " + $0 + " <in> <out>"); exit; end if ARGV.length != 2'
|
222
|
-
@o.print "\n"
|
223
|
-
@o.print 'File.open(ARGV[1], "w") {|f| RMetaII.new.compile(File.read(ARGV[0]), f)}'
|
224
|
-
@o.print "\n"
|
225
|
-
end
|
226
|
-
end while false
|
227
|
-
end
|
228
|
-
end
|
229
|
-
begin; puts("Use: " + $0 + " <in> <out>"); exit; end if ARGV.length != 2
|
230
|
-
File.open(ARGV[1], "w") {|f| RMetaII.new.compile(File.read(ARGV[0]), f)}
|
@@ -1,230 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require "strscan"
|
3
|
-
class RMetaII
|
4
|
-
def compile(str, out)
|
5
|
-
@i, @o = StringScanner.new(str), out
|
6
|
-
compile_program
|
7
|
-
end
|
8
|
-
def compile_outarg
|
9
|
-
begin
|
10
|
-
@i.scan /\s*/; s="$"; l=s.length;
|
11
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
12
|
-
if @f
|
13
|
-
@o.print "@o.print @t"
|
14
|
-
@o.print "\n"
|
15
|
-
end
|
16
|
-
break if @f
|
17
|
-
@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/
|
18
|
-
if @f
|
19
|
-
@o.print "@o.print "
|
20
|
-
@o.print @t
|
21
|
-
@o.print "\n"
|
22
|
-
end
|
23
|
-
end while false
|
24
|
-
end
|
25
|
-
def compile_out
|
26
|
-
begin
|
27
|
-
@i.scan /\s*/; s="<"; l=s.length;
|
28
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
29
|
-
if @f
|
30
|
-
begin
|
31
|
-
compile_outarg
|
32
|
-
end while @f
|
33
|
-
@f = true
|
34
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
35
|
-
@i.scan /\s*/; s=">"; l=s.length;
|
36
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
37
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
38
|
-
@o.print "@o.print \"\\n\""
|
39
|
-
@o.print "\n"
|
40
|
-
end
|
41
|
-
end while false
|
42
|
-
end
|
43
|
-
def compile_exp3
|
44
|
-
begin
|
45
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
46
|
-
if @f
|
47
|
-
@o.print "compile_"
|
48
|
-
@o.print @t
|
49
|
-
@o.print "\n"
|
50
|
-
end
|
51
|
-
break if @f
|
52
|
-
@i.scan /\s*/; @f = @t = @i.scan /\047[^\047]*\047/
|
53
|
-
if @f
|
54
|
-
@o.print "@i.scan /\\s*/; s="
|
55
|
-
@o.print @t
|
56
|
-
@o.print "; l=s.length;"
|
57
|
-
@o.print "\n"
|
58
|
-
@o.print "@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil"
|
59
|
-
@o.print "\n"
|
60
|
-
end
|
61
|
-
break if @f
|
62
|
-
@i.scan /\s*/; s=".id"; l=s.length;
|
63
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
64
|
-
if @f
|
65
|
-
@o.print "@i.scan /\\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/"
|
66
|
-
@o.print "\n"
|
67
|
-
end
|
68
|
-
break if @f
|
69
|
-
@i.scan /\s*/; s=".string"; l=s.length;
|
70
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
71
|
-
if @f
|
72
|
-
@o.print "@i.scan /\\s*/; @f = @t = @i.scan /\\047[^\\047]*\\047/"
|
73
|
-
@o.print "\n"
|
74
|
-
end
|
75
|
-
break if @f
|
76
|
-
@i.scan /\s*/; s="("; l=s.length;
|
77
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
78
|
-
if @f
|
79
|
-
compile_exp1
|
80
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
81
|
-
@i.scan /\s*/; s=")"; l=s.length;
|
82
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
83
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
84
|
-
end
|
85
|
-
break if @f
|
86
|
-
@i.scan /\s*/; s=".e"; l=s.length;
|
87
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
88
|
-
if @f
|
89
|
-
@o.print "@f = true"
|
90
|
-
@o.print "\n"
|
91
|
-
end
|
92
|
-
break if @f
|
93
|
-
@i.scan /\s*/; s="*"; l=s.length;
|
94
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
95
|
-
if @f
|
96
|
-
@o.print "begin"
|
97
|
-
@o.print "\n"
|
98
|
-
compile_exp3
|
99
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
100
|
-
@o.print "end while @f"
|
101
|
-
@o.print "\n"
|
102
|
-
@o.print "@f = true"
|
103
|
-
@o.print "\n"
|
104
|
-
end
|
105
|
-
end while false
|
106
|
-
end
|
107
|
-
def compile_exp2
|
108
|
-
begin
|
109
|
-
begin
|
110
|
-
compile_exp3
|
111
|
-
if @f
|
112
|
-
@o.print "if @f"
|
113
|
-
@o.print "\n"
|
114
|
-
end
|
115
|
-
break if @f
|
116
|
-
compile_out
|
117
|
-
if @f
|
118
|
-
@o.print "if true"
|
119
|
-
@o.print "\n"
|
120
|
-
end
|
121
|
-
end while false
|
122
|
-
if @f
|
123
|
-
begin
|
124
|
-
begin
|
125
|
-
compile_exp3
|
126
|
-
if @f
|
127
|
-
@o.print "raise(\"error at: \" + @i.rest.split(\"\\n\")[0]) if !@f"
|
128
|
-
@o.print "\n"
|
129
|
-
end
|
130
|
-
break if @f
|
131
|
-
compile_out
|
132
|
-
if @f
|
133
|
-
end
|
134
|
-
end while false
|
135
|
-
end while @f
|
136
|
-
@f = true
|
137
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
138
|
-
@o.print "end"
|
139
|
-
@o.print "\n"
|
140
|
-
end
|
141
|
-
end while false
|
142
|
-
end
|
143
|
-
def compile_exp1
|
144
|
-
begin
|
145
|
-
@o.print "begin"
|
146
|
-
@o.print "\n"
|
147
|
-
if true
|
148
|
-
compile_exp2
|
149
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
150
|
-
begin
|
151
|
-
begin
|
152
|
-
@i.scan /\s*/; s="|"; l=s.length;
|
153
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
154
|
-
if @f
|
155
|
-
@o.print "break if @f"
|
156
|
-
@o.print "\n"
|
157
|
-
compile_exp2
|
158
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
159
|
-
end
|
160
|
-
end while false
|
161
|
-
end while @f
|
162
|
-
@f = true
|
163
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
164
|
-
@o.print "end while false"
|
165
|
-
@o.print "\n"
|
166
|
-
end
|
167
|
-
end while false
|
168
|
-
end
|
169
|
-
def compile_rule
|
170
|
-
begin
|
171
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
172
|
-
if @f
|
173
|
-
@o.print "def compile_"
|
174
|
-
@o.print @t
|
175
|
-
@o.print "\n"
|
176
|
-
@i.scan /\s*/; s="="; l=s.length;
|
177
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
178
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
179
|
-
compile_exp1
|
180
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
181
|
-
@i.scan /\s*/; s=";"; l=s.length;
|
182
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
183
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
184
|
-
@o.print "end"
|
185
|
-
@o.print "\n"
|
186
|
-
end
|
187
|
-
end while false
|
188
|
-
end
|
189
|
-
def compile_program
|
190
|
-
begin
|
191
|
-
@i.scan /\s*/; s=".syntax"; l=s.length;
|
192
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
193
|
-
if @f
|
194
|
-
@i.scan /\s*/; @f = @t = @i.scan /[A-Za-z]+[A-Za-z0-9_]+/
|
195
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
196
|
-
@o.print "#!/usr/bin/env ruby"
|
197
|
-
@o.print "\n"
|
198
|
-
@o.print "require \"strscan\""
|
199
|
-
@o.print "\n"
|
200
|
-
@o.print "class "
|
201
|
-
@o.print @t
|
202
|
-
@o.print "\n"
|
203
|
-
@o.print "def compile(str, out)"
|
204
|
-
@o.print "\n"
|
205
|
-
@o.print "@i, @o = StringScanner.new(str), out"
|
206
|
-
@o.print "\n"
|
207
|
-
@o.print "compile_program"
|
208
|
-
@o.print "\n"
|
209
|
-
@o.print "end"
|
210
|
-
@o.print "\n"
|
211
|
-
begin
|
212
|
-
compile_rule
|
213
|
-
end while @f
|
214
|
-
@f = true
|
215
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
216
|
-
@i.scan /\s*/; s=".end"; l=s.length;
|
217
|
-
@f = (@i.peek(l) == s) ? (@t=s; @i.pos += l) : nil
|
218
|
-
raise("error at: " + @i.rest.split("\n")[0]) if !@f
|
219
|
-
@o.print "end"
|
220
|
-
@o.print "\n"
|
221
|
-
@o.print "begin; puts(\"Use: \" + $0 + \" <in> <out>\"); exit; end if ARGV.length != 2"
|
222
|
-
@o.print "\n"
|
223
|
-
@o.print "File.open(ARGV[1], \"w\") {|f| RMetaII.new.compile(File.read(ARGV[0]), f)}"
|
224
|
-
@o.print "\n"
|
225
|
-
end
|
226
|
-
end while false
|
227
|
-
end
|
228
|
-
end
|
229
|
-
begin; puts("Use: " + $0 + " <in> <out>"); exit; end if ARGV.length != 2
|
230
|
-
File.open(ARGV[1], "w") {|f| RMetaII.new.compile(File.read(ARGV[0]), f)}
|