Annotation of researchv10dc/cmd/dag/TrieFA.ins.c, revision 1.1.1.1

1.1       root        1: /* File - TrieFA.ins.c
                      2:  *
                      3:  *    This file contains code to be included in the scanner file using a
                      4:  * generated trie-based FA.
                      5:  */
                      6: 
                      7: #include "TrieFA.h"
                      8: 
                      9: #ifdef UNDERLINE
                     10: static long CharMask[28] = {
                     11:        0x0000001,      0x0000000,      0x0000004,      0x0000008,      // mask for _, unused, a and b.
                     12:        0x0000010,      0x0000020,      0x0000040,      0x0000080,      // mask for c, d, e and f.
                     13:        0x0000100,      0x0000200,      0x0000400,      0x0000800,      // mask for g, h, i and j.
                     14:        0x0001000,      0x0002000,      0x0004000,      0x0008000,      // mask for k, l, m and n.
                     15:        0x0010000,      0x0020000,      0x0040000,      0x0080000,      // mask for o, p, q and r.
                     16:        0x0100000,      0x0200000,      0x0400000,      0x0800000,      // mask for s, t, u and v.
                     17:        0x1000000,      0x2000000,  0x4000000,  0x8000000,      // mask for w, x, y and z.
                     18: };
                     19: 
                     20: #define IN_MASK_RANGE(C)       (islower(C) || ((C) == '_'))
                     21: #define MASK_INDEX(C)  ((C) - '_')
                     22: 
                     23: #else
                     24: static long CharMask[26] = {
                     25:        0x0000001,      0x0000002,      0x0000004,      0x0000008,      // mask for a, b, c and d.
                     26:        0x0000010,      0x0000020,      0x0000040,      0x0000080,      // mask for e, f, g and h
                     27:        0x0000100,      0x0000200,      0x0000400,      0x0000800,      // mask for i, j, k and l.
                     28:        0x0001000,      0x0002000,      0x0004000,      0x0008000,      // mask for m, n, o and p.
                     29:        0x0010000,      0x0020000,      0x0040000,      0x0080000,      // mask for q, r, s and t.
                     30:        0x0100000,      0x0200000,      0x0400000,      0x0800000,      // mask for u, v, w and x.
                     31:        0x1000000,      0x2000000                                                       // mask for y and z.
                     32: };
                     33: 
                     34: #define IN_MASK_RANGE(C)       islower(C)
                     35: #define MASK_INDEX(C)          ((C) - 'a')
                     36: 
                     37: #endif
                     38: 
                     39: static short           TFA_State;
                     40: 
                     41: /* TFA_Init:
                     42:  *
                     43:  *    Initialize the trie FA.
                     44:  */
                     45: inline void TFA_Init ()
                     46: {
                     47:        TFA_State = 0;
                     48: 
                     49: }
                     50: 
                     51: /* TFA_Advance:
                     52:  *
                     53:  *    Advance to the next state (or -1) on the lowercase letter c.  This should be an
                     54:  * inline routine, but the C++ implementation isn't advanced enough so we use a macro.
                     55:  */
                     56: #define TFA_Advance(C) {                                                                                                                       \
                     57:        char            c = C;                                                                                                                          \
                     58:        if (TFA_State >= 0) {                                                                                                                   \
                     59:                if (isupper(c))                                                                                                                         \
                     60:                        c = tolower(c);                                                                                                                 \
                     61:                else if (! IN_MASK_RANGE(c)) {                                                                                          \
                     62:                        TFA_State = -1;                                                                                                                 \
                     63:                        goto TFA_done;                                                                                                                  \
                     64:                }                                                                                                                                                       \
                     65:                if (TrieStateTbl[TFA_State].mask & CharMask[MASK_INDEX(c)]) {                           \
                     66:                        short           i = TrieStateTbl[TFA_State].trans_base;                                         \
                     67:                        while (TrieTransTbl[i].c != c)                                                                                  \
                     68:                                i++;                                                                                                                            \
                     69:                        TFA_State = TrieTransTbl[i].next_state;                                                                 \
                     70:                }                                                                                                                                                       \
                     71:                else                                                                                                                                            \
                     72:                        TFA_State = -1;                                                                                                                 \
                     73:        }                                                                                                                                                               \
                     74:   TFA_done:;                                                                                                                                           \
                     75: } /* end of TFA_Advance. */
                     76: 
                     77: /* TFA_Definition:
                     78:  *
                     79:  *    Return the definition (if any) associated with the current state.
                     80:  */
                     81: inline int TFA_Definition ()
                     82: {
                     83:        return (TFA_State < 0) ? -1 : TrieStateTbl[TFA_State].def;
                     84: 
                     85: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.