|
|
1.1 ! root 1: /* useful constants */ ! 2: #define NULL 0 ! 3: #define TRUE 1 ! 4: #define FALSE 0 ! 5: #define HAT '\177' /* character to mark real beg. of line */ ! 6: ! 7: /* ! 8: * character class ! 9: */ ! 10: typedef struct CClass { ! 11: char map[16]; /* 16 bytes == 128 bits, one bit per char */ ! 12: }Class; ! 13: ! 14: /* ! 15: * sub-expression matches ! 16: */ ! 17: #define NSUBEXP 10 ! 18: typedef struct Subexp{ ! 19: char *startp[NSUBEXP]; ! 20: char *endp[NSUBEXP]; ! 21: }Subexp; ! 22: ! 23: /* ! 24: * Machine instructions ! 25: */ ! 26: typedef struct Inst{ ! 27: int type; /* < 0200 ==> literal, otherwise action */ ! 28: union { ! 29: int sid; /* sub-expression id for RBRA and LBRA */ ! 30: struct Inst *other; /* instructions pointer */ ! 31: } u; ! 32: struct Inst *left; ! 33: }Inst; ! 34: #define next left /* Left branch is usually just next ptr */ ! 35: #define subid u.sid ! 36: #define right u.other ! 37: ! 38: /* ! 39: * Program definition ! 40: */ ! 41: #define NCLASS 16 ! 42: typedef struct Program{ ! 43: Subexp se; /* .bss */ ! 44: Inst *startinst; /* pc */ ! 45: Class class[NCLASS]; /* .data */ ! 46: Inst firstinst[5]; /* .text */ ! 47: }Prog; ! 48: ! 49: /* ! 50: * Actions and Tokens ! 51: * ! 52: * 02xx are operators, value == precedence ! 53: * 03xx are tokens, i.e. operands for operators ! 54: */ ! 55: #define OPERATOR 0200 /* Bitmask of all operators */ ! 56: #define START 0200 /* Start, used for marker on stack */ ! 57: #define RBRA 0201 /* Right bracket, ) */ ! 58: #define LBRA 0202 /* Left bracket, ( */ ! 59: #define OR 0203 /* Alternation, | */ ! 60: #define CAT 0204 /* Concatentation, implicit operator */ ! 61: #define STAR 0205 /* Closure, * */ ! 62: #define PLUS 0206 /* a+ == aa* */ ! 63: #define QUEST 0207 /* a? == a|nothing, i.e. 0 or 1 a's */ ! 64: #define ANY 0300 /* Any character, . */ ! 65: #define NOP 0301 /* No operation, internal use only */ ! 66: #define BOL 0302 /* Beginning of line, ^ */ ! 67: #define EOL 0303 /* End of line, $ */ ! 68: #define CCLASS 0304 /* Character class, [] */ ! 69: #define END 0377 /* Terminate: match found */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.