Removed arg passing from frontend to backend functions.
[ragel.git] / test / atoi3.rl
blobfcd4a4169e53f3ecf93116da57d9d822fa006b23
2 # @LANG: ruby
5 %%{
6     machine atoi3;
7     action begin {
8         neg = false;
9         val = 0;
10     }
11     action see_neg {
12         neg = true;
13     }
14     action add_digit {
15                 val = val * 10 + (fc - "0"[0]);
16     }
17     action finish {
18                 val = -1 * val if neg
19     }
20     action print {
21         puts val;
22     }
23     atoi = (('-' @ see_neg | '+') ? (digit @ add_digit) +) > begin % finish;
24     main := atoi '\n' @ print;
25 }%%
27 %% write data;
29 def run_machine( data )
30         p = 0;
31         pe = data.length
32         cs = 0
33         val = 0;
34         neg = false;
36         %% write init;
37         %% write exec;
38         if  cs >= atoi3_first_final
39                 puts "ACCEPT"
40         else
41                 puts "FAIL"
42         end
43 end
45 inp = [
46                 "1\n",
47                 "12\n",
48                 "222222\n",
49                 "+2123\n",
50                 "213 3213\n",
51                 "-12321\n",
52                 "--123\n",
53                 "-99\n",
54                 " -3000\n",
57 inp.each { |str| run_machine(str) }
59 =begin _____OUTPUT_____
61 ACCEPT
63 ACCEPT
64 222222
65 ACCEPT
66 2123
67 ACCEPT
68 FAIL
69 -12321
70 ACCEPT
71 FAIL
72 -99
73 ACCEPT
74 FAIL
75 =end _____OUTPUT_____