-
Notifications
You must be signed in to change notification settings - Fork 3
/
mk_enctab.pl
137 lines (123 loc) · 3 KB
/
mk_enctab.pl
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/env perl
# Create encoding table to turn bit vector output by DFA into the recognized
# word type (given that multiple bits may be set in the vector and it's down to
# a priority scheme to decide which one dominates.)
# $Header$
# COPYRIGHT
# Build first state table, 256 entries for dealing with cmavo, gismu, lujvo.
# Each class should be mutually disjoint.
$W_UNKNOWN = 0;
$W_CMAVOS = 1;
$W_CMAVOS_END_CY = 2;
$W_GISMU = 3;
$W_LUJVO = 4;
$W_FUIVLA = 5;
$W_CMENE = 6;
$W_BAD_TOSMABRU = 8;
$W_BAD_SLINKUI = 9;
$W_BIZARRE = 10;
@table = ();
for $c (0..1) {
for $cy (0..1) {
for $g0 (0..1) {
for $g1 (0..1) {
for $l0 (0..1) {
for $l1 (0..1) {
for $l1t (0..1) {
for $tos (0..1) {
$addr = $c | ($cy<<1) | ($g0<<2) | ($g1<<3) | ($l0<<4) | ($l1<<5) | ($l1t<<6) | ($tos<<7);
$result = $W_UNKNOWN;
$decrement = 0;
if (($c && $cy) ||
(($c || $cy) && ($g0 || $g1)) ||
(($c || $cy) && ($l0 || $l1 || $l1t)) ||
(($g0 || $g1) && ($l0 || $l1 || $l1t)) ||
(($l1t || $tos) && ($l0 || $l1))) {
$result = $W_BIZARRE;
} elsif ($g0) {
$result = $W_GISMU;
} elsif ($g1) {
$result = $W_GISMU;
$decrement = 1;
} elsif ($l0) {
$result = $W_LUJVO;
} elsif ($l1) {
$result = $W_LUJVO;
$decrement = 1;
} elsif ($l1t) {
$decrement = 1;
$result = ($tos) ? $W_LUJVO : $W_BAD_TOSMABRU;
} elsif ($c) {
$result = $W_CMAVOS;
} elsif ($cy) {
$result = $W_CMAVOS_END_CY;
} else {
# unknown
}
$table[$addr] = $result + ($decrement ? 0x80 : 0x0);
}
}
}
}
}
}
}
}
print "static unsigned char morf_enctab1[256] = {\n ";
for $i (0 .. 255) {
printf "0x%02x", $table[$i];
if ($i < 255) {
print ", ";
}
if ($i%8 == 7) {
print "\n ";
}
}
print "};\n\n";
# 2nd table to decode fuivla/slinkui and cmene
@table = ();
for $fv0 (0..1) {
for $fv1 (0..1) {
for $sl0 (0..1) {
for $cmn (0..1) {
$addr = ($fv0) | ($fv1<<1) | ($sl0<<2) | ($cmn<<3);
$result = $W_UNKNOWN;
$decrement = 0;
if (($cmn && ($fv0 || $fv1 || $sl0))) {
$result = $W_BIZARRE;
} elsif ($cmn) {
$result = $W_CMENE;
} elsif ($fv0 && $sl0) {
# If the shorter tail word is invalid due to slinku'i, yet the longer
# word formed by leaving the previous syllable attached is OK, then
# that is the correct result. (e.g baislinku'i is a valid fu'ivla as is)
if ($fv1) {
$decrement = 1;
$result = $W_FUIVLA;
} else {
$result = $W_BAD_SLINKUI;
}
} elsif ($fv0) {
$result = $W_FUIVLA;
} elsif ($fv1) {
$result = $W_FUIVLA;
$decrement = 1;
} else {
# Keep default
}
$table[$addr] = $result + ($decrement ? 0x80 : 0x0);
}
}
}
}
print "static unsigned char morf_enctab2[32] = {\n ";
for $i (0 .. 31) {
printf "0x%02x", $table[$i];
if ($i < 31) {
print ", ";
}
if ($i%8 == 7) {
print "\n ";
}
}
print "};\n\n";