repo.or.cz
/
ragel.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Added missing operators.
[ragel.git]
/
test
/
atoi1.rl
blob
ea706c8cb0479ac2b6dc97b1d77476a1ce920165
1
/*
2
* @LANG: indep
3
*/
4
bool neg;
5
int val;
6
%%
7
val = 0;
8
neg = false;
9
%%{
10
machine AtoI;
11
12
action begin {
13
neg = false;
14
val = 0;
15
}
16
17
action see_neg {
18
neg = true;
19
}
20
21
action add_digit {
22
val = val * 10 + (fc - 48);
23
}
24
25
action finish {
26
if ( neg ) {
27
val = -1 * val;
28
}
29
}
30
action print {
31
printi val;
32
prints "\n";
33
}
34
35
atoi = (
36
('-'@see_neg | '+')? (digit @add_digit)+
37
) >begin %finish;
38
39
main := atoi '\n' @print;
40
}%%
41
/* _____INPUT_____
42
"1\n"
43
"12\n"
44
"222222\n"
45
"+2123\n"
46
"213 3213\n"
47
"-12321\n"
48
"--123\n"
49
"-99\n"
50
" -3000\n"
51
_____INPUT_____ */
52
53
/* _____OUTPUT_____
54
1
55
ACCEPT
56
12
57
ACCEPT
58
222222
59
ACCEPT
60
2123
61
ACCEPT
62
FAIL
63
-12321
64
ACCEPT
65
FAIL
66
-99
67
ACCEPT
68
FAIL
69
_____OUTPUT_____ */