blob: b43e25938263b252bef78ecc5091a0a788b6ac7e (
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
|
//
// @LANG: julia
// @GENERATED: true
//
%%{
machine state_chart;
action begin {neg = 0;
value = 0;
}
action see_neg {neg = 1;
}
action add_digit {value = value * 10 + convert( Int, ( fc - 48 ) )
;
}
action finish {if ( neg != 0 )
value = -1 * value;
end
}
atoi = (
start: (
'-' @see_neg ->om_num |
'+' ->om_num |
[0-9] @add_digit ->more_nums
),
# One or more nums.
om_num: (
[0-9] @add_digit ->more_nums
),
# Zero ore more nums.
more_nums: (
[0-9] @add_digit ->more_nums |
'' -> final
)
) >begin %finish;
action oneof {print( value );
print( "\n" );
}
main := ( atoi '\n' @oneof )*;
}%%
%% write data;
function m( data::AbstractString )
p = 0
pe = length(data)
eof = length(data)
cs = 0
buffer = ""
neg = 0;
value = 0;
value = 0;
neg = 0;
%% write init;
%% write exec;
if ( cs >= state_chart_first_final )
println( "ACCEPT" );
else
println( "FAIL" );
end
end
m( "1\n" );
m( "12\n" );
m( "222222\n" );
m( "+2123\n" );
m( "213 3213\n" );
m( "-12321\n" );
m( "--123\n" );
m( "-99\n" );
m( " -3000\n" );
|