Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
trieFA.h
Go to the documentation of this file.
1/* File - trieFA.h
2 *
3 * This file contains code to be included in the scanner file using a
4 * generated trie-based FA.
5 */
6
7typedef struct { /* An entry in the FA state table */
8 short def; /* If this state is an accepting state then*/
9 /* this is the definition, otherwise -1. */
10 short trans_base; /* The base index into the transition table.*/
11 long mask; /* The transition mask. */
12}TrieState ;
13
14typedef struct { /* An entry in the FA transition table. */
15 short c; /* The transition character (lowercase).*/
16 short next_state; /* The next state. */
17}TrieTrans ;
18
19#ifdef UNDERLINE
20static long CharMask[28] = {
21 0x0000001, 0x0000000, 0x0000004, 0x0000008,
22 0x0000010, 0x0000020, 0x0000040, 0x0000080,
23 0x0000100, 0x0000200, 0x0000400, 0x0000800,
24 0x0001000, 0x0002000, 0x0004000, 0x0008000,
25 0x0010000, 0x0020000, 0x0040000, 0x0080000,
26 0x0100000, 0x0200000, 0x0400000, 0x0800000,
27 0x1000000, 0x2000000, 0x4000000, 0x8000000,
28};
29
30#define IN_MASK_RANGE(C) (islower(C) || ((C) == '_'))
31#define MASK_INDEX(C) ((C) - '_')
32
33#else
34static long CharMask[26] = {
35 0x0000001, 0x0000002, 0x0000004, 0x0000008,
36 0x0000010, 0x0000020, 0x0000040, 0x0000080,
37 0x0000100, 0x0000200, 0x0000400, 0x0000800,
38 0x0001000, 0x0002000, 0x0004000, 0x0008000,
39 0x0010000, 0x0020000, 0x0040000, 0x0080000,
40 0x0100000, 0x0200000, 0x0400000, 0x0800000,
41 0x1000000, 0x2000000
42};
43
44#define IN_MASK_RANGE(C) islower(C)
45#define MASK_INDEX(C) ((C) - 'a')
46
47#endif
48
49static short TFA_State;
50
51/* TFA_Init:
52 *
53 * Initialize the trie FA.
54 */
55#define TFA_Init() TFA_State = 0
56
57/* TFA_Advance:
58 *
59 * Advance to the next state (or -1) on the lowercase letter c.
60 */
61#define TFA_Advance(C) { \
62 char c = C; \
63 if (TFA_State >= 0) { \
64 if (isupper((int)c)) \
65 c = (char)tolower((int)c); \
66 else if (! IN_MASK_RANGE(c)) { \
67 TFA_State = -1; \
68 goto TFA_done; \
69 } \
70 if (TrieStateTbl[TFA_State].mask & CharMask[MASK_INDEX(c)]) { \
71 short i = TrieStateTbl[TFA_State].trans_base; \
72 while (TrieTransTbl[i].c != c) \
73 i++; \
74 TFA_State = TrieTransTbl[i].next_state; \
75 } \
76 else \
77 TFA_State = -1; \
78 } \
79 TFA_done:; \
80} /* end of TFA_Advance. */
81
82/* TFA_Definition:
83 *
84 * Return the definition (if any) associated with the current state.
85 */
86#define TFA_Definition() \
87 ((TFA_State < 0) ? -1 : TrieStateTbl[TFA_State].def)
short def
Definition trieFA.h:8
long mask
Definition trieFA.h:11
short trans_base
Definition trieFA.h:10
short c
Definition trieFA.h:15
short next_state
Definition trieFA.h:16
static short TFA_State
Definition trieFA.h:49
static long CharMask[26]
Definition trieFA.h:34