blob: 43a535e607f8846f7ef2abf9811d823869fc4c3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
#
# @LANG: ruby
# @GENERATED: true
#
%%{
machine patact;
other := |*
[a-z]+ => {print( "word\n" );
};
[0-9]+ => {print( "num\n" );
};
[\n ] => {print( "space\n" );
};
*|;
exec_test := |*
[a-z]+ => {print( "word (w/lbh)\n" );
fexec te-1;fgoto other;};
[a-z]+ ' foil' => {print( "word (c/lbh)\n" );
};
[\n ] => {print( "space\n" );
};
'22' => {print( "num (w/switch)\n" );
};
[0-9]+ => {print( "num (w/switch)\n" );
fexec te-1;fgoto other;};
[0-9]+ ' foil' => {print( "num (c/switch)\n" );
};
'!';# => { print_str "immdiate\n"; fgoto exec_test; };
*|;
semi := |*
';' => {print( "in semi\n" );
fgoto main;};
*|;
main := |*
[a-z]+ => {print( "word (w/lbh)\n" );
fhold;fgoto other;};
[a-z]+ ' foil' => {print( "word (c/lbh)\n" );
};
[\n ] => {print( "space\n" );
};
'22' => {print( "num (w/switch)\n" );
};
[0-9]+ => {print( "num (w/switch)\n" );
fhold;fgoto other;};
[0-9]+ ' foil' => {print( "num (c/switch)\n" );
};
';' => {print( "going to semi\n" );
fhold;fgoto semi;};
'!' => {print( "immdiate\n" );
fgoto exec_test;};
*|;
}%%
%% write data;
def run_machine( data )
p = 0
pe = data.length
eof = data.length
cs = 0;
_m =
_a =
buffer = Array.new
blen = 0
comm = 1
top = 1
stack = Array.new
ts = 1
te = 1
act = 1
value = 1
%% write init;
%% write exec;
if cs >= patact_first_final
puts "ACCEPT"
else
puts "FAIL"
end
end
inp = [
"abcd foix\n",
"abcd\nanother\n",
"123 foix\n",
"!abcd foix\n",
"!abcd\nanother\n",
"!123 foix\n",
";",
]
inplen = 7
inp.each { |str| run_machine(str) }
|