contents index next

11. fsa_compiler_to_c: C Code Generation

This module provides predicates to create C code on the basis of a finite automaton. There are certain restrictions to the input automaton. The automaton must be:

The compiler performs the following operation to ensure that the above conditions hold:

recognizers:     m(expand_predicates(Sig* & fa(Fa0)))

string to string transducers:     t_minimize(expand_predicates(Sig* o fa(Fa0)))

string to weight transducers:     w_minimize(expand_predicates(Sig* o fa(Fa0))

where Sig is equivalent to the union of all one-letter atoms, and Fa0 is the input automaton.

The C program will contain definitions of the following functions:

int accepts(char *in)
int t_accepts(char *in,char *out)
int w_accepts(char *in,int *out)

In each case, the functions return 1 if the string in is accepted. Otherwise they return 0. For transducers the resulting string or weight is available in *out*.

If the global variable c_with_main is set to *on*, then the resulting C program will also contain a main function. This function is defined in such a way that it reads lines from standard input and applies the corresponding accept functions for each line. For recognizers, either yes or no is printed to standard error. For transducers, the transduction is written to standard output; if the input string is not in the domain of the transducer then no is written to standard error.

The representation of the finite-automaton in C is similar to the technique explained on page 43 (table 4.2) of Jan Daciuk's dissertation `Incremental Construction of Finite-State Automata and Transducers and their use in the Natural Language Processing'. Politechnika Gdanska, 1998.

11.1. List of Predicates

This section lists the predicates defined by this module.

11.1.1. fsa_compile_to_c(+Fa) fsa_compile_to_c(+FileIn,+FileOut)

In the first variant, a C program is written to standard output for the automaton Fa. The C program will read lines from standard input and report for each line whether it is a string accepted by Fa. In the second variant, the C program is written to FileOut on the basis of the automaton read in from FileIn.

11.1.2. fsa_compile_to_c_t(+Fa) fsa_compile_to_c_t(+FileIn,+FileOut)

In the first variant, a C program is written to standard output for the transducer Fa. The C program will read lines from standard input and print for each line its transduction according to Fa. In the second variant, the C program is written to FileOut on the basis of the automaton read in from FileIn. Remember that Fa must be deterministic for input.

11.1.3. fsa_compile_to_c_w(+Fa) fsa_compile_to_c_w(+FileIn,+FileOut)

In the first variant, a C program is written to standard output for the string to weight transducer Fa. The C program will read lines from standard input and print for each line its transduction according to Fa. In the second variant, the C program is written to FileOut on the basis of the automaton read in from FileIn. Remember that Fa must be deterministic for input.

11.1.4. fsa_compile_to_c_fa(+Fa,+FileOut)

A C program is written to FileOut for the automaton Fa. The C program will read lines from standard input and report for each line whether it is a string accepted by Fa.

11.1.5. fsa_compile_to_c_t_fa(+Fa,+FileOut)

A C program is written to FileOut for the transducer Fa. The C program will read lines from standard input and print for each line its transduction according to Fa.

11.1.6. fsa_compile_to_c_w_fa(+Fa,+FileOut)

A C program is written to FileOut for the string to weight transducer Fa. The C program will read lines from standard input and print for each line its transduction according to Fa.

contents index next