6
6
#------------------------------------------------------------------------------
8
combi_rule dash_to_ones ($start, $next, $surface):
8
combi_rule dash_to_ones( $state, $link, $surface ):
9
9
# Read a "-" in front of "one", ..., "nine".
11
result $start, rules ones;
10
require $surface = "-";
11
result $state, rules ones;
14
14
#------------------------------------------------------------------------------
16
combi_rule blank_to_ones_or_tens ($start, $next, $surface):
16
combi_rule blank_to_ones_or_tens( $state, $link, $surface ):
17
17
# Read a blank in front of "one", ..., "ninety".
19
result $start, rules ones, tens;
18
require $surface = " ";
19
result $state, rules ones, tens;
20
20
end blank_to_ones_or_tens;
22
22
#------------------------------------------------------------------------------
24
combi_rule ones ($start, $next):
24
combi_rule ones( $state, $link ):
25
25
# Read "one", "two", ..., "nineteen"
29
$start.tens := $next.tens;
26
require ones in $link;
28
require $state.tens = 0;
29
$state.tens := $link.tens;
31
$start.ones := $next.ones;
32
result $start, rules blank_to_thousand, blank_to_hundred, finish;
31
$state.ones := $link.ones;
32
result $state, rules blank_to_thousand, blank_to_hundred, finish;
35
35
#------------------------------------------------------------------------------
37
combi_rule tens ($start, $next):
37
combi_rule tens( $state, $link ):
38
38
# Read "twenty", ..., "ninety".
40
? tens in $next and not ones in $next;
41
$start.tens := $next.tens;
42
result $start, rules dash_to_ones, blank_to_thousand, finish;
39
require $state.tens = 0;
40
require tens in $link and not ones in $link;
41
$state.tens := $link.tens;
42
result $state, rules dash_to_ones, blank_to_thousand, finish;
45
45
#------------------------------------------------------------------------------
47
combi_rule blank_to_hundred ($start, $next, $surface):
47
combi_rule blank_to_hundred( $state, $link, $surface ):
48
48
# Read a blank in front of "hundred".
50
result $start, rules hundred;
49
require $surface = " ";
50
result $state, rules hundred;
51
51
end blank_to_hundred;
53
53
#------------------------------------------------------------------------------
55
combi_rule hundred ($start, $next, $surface):
55
combi_rule hundred( $state, $link, $surface ):
57
? $surface = "hundred";
58
? $start.hundreds = 0 and $start.tens = 0;
59
if $start.ones = 0 then
57
require $surface = "hundred";
58
require $state.hundreds = 0 and $state.tens = 0;
59
if $state.ones = 0 then
62
$start :=+ [hundreds: $start.ones, ones: 0];
63
result $start, rules blank_to_ones_or_tens, blank_to_thousand, finish;
62
$state :=+ [hundreds: $state.ones, ones: 0];
63
result $state, rules blank_to_ones_or_tens, blank_to_thousand, finish;
66
66
#------------------------------------------------------------------------------
68
combi_rule blank_to_thousand ($start, $next, $surface):
68
combi_rule blank_to_thousand( $state, $link, $surface ):
69
69
# Read a blank in front of "thousand".
71
result $start, rules thousand;
70
require $surface = " ";
71
result $state, rules thousand;
72
72
end blank_to_thousand;
74
74
#------------------------------------------------------------------------------
76
combi_rule thousand ($start, $next, $surface):
76
combi_rule thousand( $state, $link, $surface ):
78
? $surface = "thousand";
79
? $start.thousands = 0;
80
if $start.ones = 0 and $start.tens = 0 and $start.hundreds = 0 then
78
require $surface = "thousand";
79
require $state.thousands = 0;
80
if $state.ones = 0 and $state.tens = 0 and $state.hundreds = 0 then
83
83
define $result := [ones: 0, tens: 0, hundreds: 0,
84
thousands: ($start.hundreds * 100 + $start.tens * 10
84
thousands: ($state.hundreds * 100 + $state.tens * 10
86
86
result $result, rules blank_to_ones_or_tens, finish;
89
89
#------------------------------------------------------------------------------
91
end_rule finish ($start):
92
result ($start.thousands * 1000
93
+ $start.hundreds * 100
95
+ $start.ones), accept;
91
end_rule finish( $state ):
92
result ($state.thousands * 1000
93
+ $state.hundreds * 100
95
+ $state.ones), accept;
98
98
# end of file =================================================================