#!/bin/bash

FST="$1"

sort "$FST" > "$FST.sort"

rm "$FST.sort"

#!/bin/bash

FST="$1"

sort "$FST" > "$FST.sort"

cat <<EOF
int pos=0;
int total=0;

EOF

while read DEP ARR CHAR WEIGHT ; do
    : ${WEIGHT:=0}

    if [[ $DEP != $PREV_DEP ]]; then
        cat <<EOF
    }

NODE_$DEP :
    pos++;
    switch (token[pos-1]) {
EOF
    fi

    cat <<EOF
    case '$CHAR':
        total += $WEIGHT;
        goto NODE_$ARR;
EOF

    PREV_DEP=$DEP
done < "$FST.sort"

rm "$FST.sort"

Set the bases of the parsing algorithm
FEATURE/MAJOR: Set the bases of the parsing algorithm

For each source node, we will build something like this :

NODE_7 :
    pos++
    switch(token[pos-1]) {
    case 'X' :
        total += 6;
        goto NODE_21;
    case 'Y' :
        total += 0;
        goto NODE_42;
    }

It would be generated by a .fst file with:
7 21 X 6
7 42 Y
