8a031d3c3567e7e37cc467a5437f0990e9e31337
[idzebra-moved-to-github.git] / include / dfa.h
1 /*
2  * Copyright (C) 1994-1997, Index Data I/S 
3  * All rights reserved.
4  * Sebastian Hammer, Adam Dickmeiss
5  *
6  * $Log: dfa.h,v $
7  * Revision 1.8  1997-09-18 08:59:18  adam
8  * Extra generic handle for the character mapping routines.
9  *
10  * Revision 1.7  1997/09/05 15:29:59  adam
11  * Changed prototype for chr_map_input - added const.
12  * Added support for C++, headers uses extern "C" for public definitions.
13  *
14  * Revision 1.6  1996/06/04 10:20:10  adam
15  * Added support for character mapping.
16  *
17  * Revision 1.5  1996/01/08  09:09:48  adam
18  * Function dfa_parse got 'const' string argument.
19  *
20  * Revision 1.4  1995/01/25  11:31:04  adam
21  * Simple error reporting when parsing regular expressions.
22  *
23  * Revision 1.3  1995/01/24  16:01:30  adam
24  * Added -ansi to CFLAGS.
25  * New functions and change of data structures.
26  *
27  * Revision 1.2  1994/09/26  16:31:23  adam
28  * Minor changes. xmalloc declares xcalloc now.
29  *
30  * Revision 1.1  1994/09/26  10:17:43  adam
31  * Dfa-module header files.
32  *
33  */
34
35 #ifndef DFA_H
36 #define DFA_H
37
38 #include <bset.h>
39 #include <set.h>
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 struct DFA_tran {
46     unsigned char ch[2];      /* transition on ch[0] <= c <= ch[1] to */
47     unsigned short to;        /* this state */
48 };
49
50 struct DFA_trans {
51     struct DFA_trans *next;   /* next DFA transition block */
52     struct DFA_tran *tran_block; /* pointer to transitions */
53     int  ptr;                 /* index of next transition in tran_block */
54     int  size;                /* allocated size of tran_block */
55 };
56
57 struct DFA_state {
58     struct DFA_state *next;   /* next entry in free/unmarked/marked list */
59     struct DFA_state *link;   /* link to next entry in hash chain */
60     struct DFA_tran *trans;   /* transition list */
61     Set set;                  /* set of positions (important nfa states) */
62     short no;                 /* no of this state */
63     short tran_no;            /* no of transitions to other states */
64     short rule_no;            /* if non-zero, this holds accept rule no */
65     short rule_nno;           /* accept rule no - except start rules */
66 };
67
68 struct DFA {
69     int no_states;
70     struct DFA_state  **states;
71     struct DFA_states *state_info;
72     struct DFA_parse  *parse_info;
73 };
74
75 struct DFA *dfa_init (void);
76 void dfa_set_cmap (struct DFA *dfa, void *vp,
77                    const char **(*cmap)(void *vp, const char **from, int len));
78 int dfa_parse (struct DFA *, const char **);
79 void dfa_mkstate (struct DFA *);
80 void dfa_delete (struct DFA **);
81
82 void dfa_parse_cmap_clean (struct DFA *d);
83 void dfa_parse_cmap_new (struct DFA *d, const int *cmap);
84 void dfa_parse_cmap_del (struct DFA *d, int from);
85 void dfa_parse_cmap_add (struct DFA *d, int from, int to);
86
87 extern int  debug_dfa_trav;
88 extern int  debug_dfa_tran;
89 extern int  debug_dfa_followpos;
90 extern int  dfa_verbose;
91
92 extern unsigned short
93         dfa_thompson_chars[],
94         dfa_ccl_chars[];
95
96 #define L_LP 1
97 #define L_RP 2
98 #define L_CHAR 3
99 #define L_CHARS 4
100 #define L_ANY 5
101 #define L_ALT 6
102 #define L_ANYZ 7
103 #define L_WILD 8
104 #define L_QUEST 9
105 #define L_CLOS1 10
106 #define L_CLOS0 11
107 #define L_END 12
108 #define L_START 13
109
110 #define DFA_ERR_SYNTAX 1
111 #define DFA_ERR_LP     2
112 #define DFA_ERR_RP     3
113
114 #ifdef __cplusplus
115 }
116 #endif
117
118 #endif