summaryrefslogtreecommitdiff
path: root/algorithms/transducer/transducer.h
blob: 749331792e6e8691301a5c334b27210178dee286 (plain)
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
#define MAX_TOK_LEN 26 /* Hard coded max length of a token */


/* 
 * Temporary buffer for tokens.
 * 
 */
typedef struct TokenBuffer_s {
	char tok[MAX_TOK_LEN];
	int next;
} TokenBuffer;

/*
 * Struct that collects parser related data.
 *
 */
typedef struct ParserState_s {
	char* file_name;
	FILE* in;
	int cur_line;
	TokenBuffer* buf;
} ParserState;

/*
 * Used for temporary storage of transitions.
 *
 */
typedef struct Quadruple_s {
	char* src_state;
	char* input;
	char* output;
	char* to_state;
} Quadruple;

/*
 * Stores a transition.
 *
 */
typedef struct Transition_s {
	char* src_state;
	int input;
	char* output;
	char* to_state;
} Transition;

/*
 * The transducer struct.
 * num_transitions and max_transitions are used for memory management.
 *
 */
typedef struct Transducer_s {
	char* start_state;
	Transition* transitions;
	int num_transitions;
	int max_transitions;
	ParserState* p;
} Transducer;

/*
 * Struct that stores the string file.
 * max_chars and num_chars are used for memory management.
 *
 */
typedef struct StringFile_s {
	char* buf;
	int read_pos;
	int max_chars;
	int num_chars;
} StringFile;

/*
 * Struct for output.
 *
 */
typedef struct OutputList_s {
	struct OutputList_s* next;
	char* output;
} OutputList;

/*
 * Struct for iterator pattern.
 *
 */ 
typedef struct TransIter_s {
	char* src_state;
	int input;
	Transducer* t;
	Transition* found;
} TransIter;