line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mylisp; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
44907
|
use 5.012; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
4
|
no warnings 'experimental'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Exporter; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
60
|
|
7
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
8
|
|
|
|
|
|
|
our @EXPORT = qw(my_repl get_my_parser my_to_ast); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '2.03'; |
11
|
1
|
|
|
1
|
|
242
|
use Spp::Builtin; |
|
1
|
|
|
|
|
157721
|
|
|
1
|
|
|
|
|
192
|
|
12
|
1
|
|
|
1
|
|
258
|
use Spp::Tools; |
|
1
|
|
|
|
|
2052
|
|
|
1
|
|
|
|
|
93
|
|
13
|
1
|
|
|
1
|
|
240
|
use Spp; |
|
1
|
|
|
|
|
10373
|
|
|
1
|
|
|
|
|
50
|
|
14
|
1
|
|
|
1
|
|
248
|
use Mylisp::Grammar; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
15
|
1
|
|
|
1
|
|
235
|
use Mylisp::OptAst; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
158
|
|
16
|
1
|
|
|
1
|
|
308
|
use Mylisp::ToPerl; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
135
|
|
17
|
1
|
|
|
1
|
|
257
|
use Mylisp::ToGo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
289
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub my_repl { |
20
|
0
|
|
|
0
|
0
|
|
my $parser = get_my_parser(); |
21
|
0
|
|
|
|
|
|
say 'This is Mylisp REPL, type enter to exit.'; |
22
|
0
|
|
|
|
|
|
while (1) { |
23
|
0
|
|
|
|
|
|
print '>> '; |
24
|
0
|
|
|
|
|
|
my $line = <STDIN>; |
25
|
0
|
0
|
|
|
|
|
exit() if ord($line) == 10; |
26
|
0
|
|
|
|
|
|
my ($match, $ok) = match_text($parser, $line); |
27
|
0
|
0
|
|
|
|
|
if ($ok) { |
28
|
0
|
|
|
|
|
|
say '.. ', see_ast($match); |
29
|
0
|
|
|
|
|
|
my $ast = opt_my_ast($match); |
30
|
0
|
|
|
|
|
|
say 'opt => ', see_ast($ast); |
31
|
0
|
|
|
|
|
|
say 'go => ', ast_to_go($ast); |
32
|
0
|
|
|
|
|
|
say 'perl => ', ast_to_perl_repl($ast); |
33
|
|
|
|
|
|
|
} |
34
|
0
|
|
|
|
|
|
else { say $match } |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub get_my_parser { |
39
|
0
|
|
|
0
|
0
|
|
my $grammar = get_my_grammar(); |
40
|
0
|
|
|
|
|
|
my $ast = grammar_to_ast($grammar); |
41
|
0
|
|
|
|
|
|
return ast_to_table($ast); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub my_to_ast { |
45
|
0
|
|
|
0
|
0
|
|
my $code = shift; |
46
|
0
|
|
|
|
|
|
my $parser = get_my_parser(); |
47
|
0
|
|
|
|
|
|
my ($match, $ok) = match_text($parser, $code); |
48
|
0
|
0
|
|
|
|
|
if ($ok) { return opt_my_ast($match) } |
|
0
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
else { error($match) } |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
1; |