Given a style file fsa.sty that associates translations to pictorial elements of finite state automata, one can specify the code that is associated with a finite state automaton through pictorial specifications similar to the following one:
The code created from the above example is introduced to the following program.
#include <stdio.h>
<.defines.>
<.spec of fsa.>
void main()
{ char *str;
FILE *file_in, *file_out;
file_in = fopen("scan.in", "r");
file_out = fopen("scan.out", "w");
WHILE TRUE DO
str = fsa(file_in);
IF (((int) *str) == 8) |
(((int) *str) == 10) THEN
exit(0);
FI
fprintf(file_out, "'%s' -> %d\n",
(str + 1), *str);
free(str);
END
}
-_-_-
#define IF if (
#define THEN ) {
#define ELSE }else{
#define ELSEIF }else if(
#define FI }
#define WHILE while(
#define FOR for(
#define WITH ;
#define STEP ;
#define DO ){
#define BEGIN {
#define END }
#define CASE switch(
#define OF ){
#define AND &
#define FALSE 0
#define TRUE 1
-_-_-
The program prog.c, obtained from the compilation of the source literate program, produces the output file scan.out on input file scan.in.