1 /* 2 Copyright 2002-2004 John Plevyak, All Rights Reserved 3 */ 4 #ifndef _dparse_tables_H_ 5 #define _dparse_tables_H_ 6 7 #define SCANNER_BLOCKS_POW2 2 8 #define SCANNER_BLOCKS (1 << SCANNER_BLOCKS_POW2) 9 #define SCANNER_BLOCK_SHIFT (8 - SCANNER_BLOCKS_POW2) 10 #define SCANNER_BLOCK_MASK ((1 << SCANNER_BLOCK_SHIFT) - 1) 11 #define SCANNER_BLOCK_SIZE (256 / SCANNER_BLOCKS) 12 13 struct D_Parser; 14 struct D_ShiftTable; 15 16 #define D_PN(_x, _o) ((D_ParseNode *)((char *)(_x) + _o)) 17 18 typedef struct d_loc_t { 19 char *s, *pathname, *ws; 20 int col, line; 21 } d_loc_t; 22 23 typedef void (*D_WhiteSpaceFn)(struct D_Parser *p, d_loc_t *loc, void **p_globals); 24 typedef int (*D_ScanCode)(d_loc_t *loc, unsigned short *symbol, int *term_priority, unsigned char *op_assoc, 25 int *op_priority); 26 typedef int (*D_ReductionCode)(void *new_ps, void **children, int n_children, int pn_offset, struct D_Parser *parser); 27 28 typedef struct D_Reduction { 29 unsigned short nelements; 30 unsigned short symbol; 31 D_ReductionCode speculative_code; 32 D_ReductionCode final_code; 33 unsigned short op_assoc; 34 unsigned short rule_assoc; 35 int op_priority; 36 int rule_priority; 37 int action_index; 38 int npass_code; 39 D_ReductionCode *pass_code; 40 } D_Reduction; 41 42 typedef struct D_RightEpsilonHint { 43 unsigned short depth; 44 unsigned short preceeding_state; 45 D_Reduction *reduction; 46 } D_RightEpsilonHint; 47 48 typedef struct D_ErrorRecoveryHint { 49 unsigned short depth; 50 unsigned short symbol; 51 const char *string; 52 } D_ErrorRecoveryHint; 53 54 typedef struct D_Shift { 55 unsigned short symbol; 56 unsigned char shift_kind; 57 unsigned char op_assoc; 58 int op_priority; 59 int term_priority; 60 int action_index; 61 D_ReductionCode speculative_code; 62 } D_Shift; 63 64 typedef struct SB_uint8 { 65 D_Shift **shift; 66 unsigned char *scanner_block[SCANNER_BLOCKS]; 67 } SB_uint8; 68 69 typedef struct SB_uint16 { 70 D_Shift **shift; 71 unsigned short *scanner_block[SCANNER_BLOCKS]; 72 } SB_uint16; 73 74 typedef struct SB_uint32 { 75 D_Shift **shift; 76 unsigned int *scanner_block[SCANNER_BLOCKS]; 77 } SB_uint32; 78 79 typedef struct SB_trans_uint8 { 80 unsigned char *scanner_block[SCANNER_BLOCKS]; 81 } SB_trans_uint8; 82 83 typedef struct SB_trans_uint16 { 84 unsigned short *scanner_block[SCANNER_BLOCKS]; 85 } SB_trans_uint16; 86 87 typedef struct SB_trans_uint32 { 88 unsigned int *scanner_block[SCANNER_BLOCKS]; 89 } SB_trans_uint32; 90 91 #define D_SCAN_ALL 0 92 #define D_SCAN_LONGEST 1 93 #define D_SCAN_MIXED 2 94 #define D_SCAN_TRAILING 3 95 #define D_SCAN_RESERVED 4 96 #define D_SCAN_DEFAULT D_SCAN_ALL 97 98 typedef struct D_State { 99 unsigned char *goto_valid; 100 int goto_table_offset; 101 struct { 102 unsigned int n; 103 D_Reduction **v; 104 } reductions; 105 struct { 106 unsigned int n; 107 D_RightEpsilonHint *v; 108 } right_epsilon_hints; 109 struct { 110 unsigned int n; 111 D_ErrorRecoveryHint *v; 112 } error_recovery_hints; 113 int shifts; 114 D_ScanCode scanner_code; 115 void *scanner_table; 116 unsigned char scanner_size; 117 unsigned char accept; 118 unsigned char scan_kind; 119 void *transition_table; 120 D_Shift ***accepts_diff; 121 int reduces_to; 122 } D_State; 123 124 #define D_SHIFTS_CODE ((D_Shift **)-1) 125 126 #define D_SYMBOL_NTERM 1 127 #define D_SYMBOL_INTERNAL 2 128 #define D_SYMBOL_EBNF 3 129 #define D_SYMBOL_STRING 4 130 #define D_SYMBOL_REGEX 5 131 #define D_SYMBOL_CODE 6 132 #define D_SYMBOL_TOKEN 7 133 typedef struct D_Symbol { 134 unsigned int kind; 135 const char *name; 136 int name_len; 137 int start_symbol; 138 } D_Symbol; 139 140 #define D_PASS_PRE_ORDER 0x0001 141 #define D_PASS_POST_ORDER 0x0002 142 #define D_PASS_MANUAL 0x0004 143 #define D_PASS_FOR_ALL 0x0008 144 #define D_PASS_FOR_UNDEFINED 0x0010 145 typedef struct D_Pass { 146 char *name; 147 unsigned int name_len; 148 unsigned int kind; 149 unsigned int index; 150 } D_Pass; 151 152 typedef struct D_ParserTables { 153 unsigned int nstates; 154 D_State *state; 155 unsigned short *goto_table; 156 unsigned int whitespace_state; 157 unsigned int nsymbols; 158 D_Symbol *symbols; 159 D_WhiteSpaceFn default_white_space; 160 unsigned int npasses; 161 D_Pass *passes; 162 unsigned int save_parse_tree; 163 } D_ParserTables; 164 165 void parse_whitespace(struct D_Parser *p, d_loc_t *loc, void **p_globals); 166 167 #endif 168