Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

397 lines
8.7 KiB

  1. #include <assert.h>
  2. #include <ctype.h>
  3. #include <stdio.h>
  4. /* machine-dependent definitions */
  5. /* the following definitions are for the Tahoe */
  6. /* they might have to be changed for other machines */
  7. /* MAXCHAR is the largest unsigned character value */
  8. /* MAXSHORT is the largest value of a C short */
  9. /* MINSHORT is the most negative value of a C short */
  10. /* MAXTABLE is the maximum table size */
  11. /* BITS_PER_WORD is the number of bits in a C unsigned */
  12. /* WORDSIZE computes the number of words needed to */
  13. /* store n bits */
  14. /* BIT returns the value of the n-th bit starting */
  15. /* from r (0-indexed) */
  16. /* SETBIT sets the n-th bit starting from r */
  17. #define MAXCHAR 255
  18. #define MAXSHORT 32767
  19. #define MINSHORT -32768
  20. #define MAXTABLE 32500
  21. #define BITS_PER_WORD 32
  22. #define WORDSIZE(n) (((n)+(BITS_PER_WORD-1))/BITS_PER_WORD)
  23. #define BIT(r, n) ((((r)[(n)>>5])>>((n)&31))&1)
  24. #define SETBIT(r, n) ((r)[(n)>>5]|=((unsigned)1<<((n)&31)))
  25. /* character names */
  26. #define NUL '\0' /* the null character */
  27. #define NEWLINE '\n' /* line feed */
  28. #define SP ' ' /* space */
  29. #define BS '\b' /* backspace */
  30. #define HT '\t' /* horizontal tab */
  31. #define VT '\013' /* vertical tab */
  32. #define CR '\r' /* carriage return */
  33. #define FF '\f' /* form feed */
  34. #define QUOTE '\'' /* single quote */
  35. #define DOUBLE_QUOTE '\"' /* double quote */
  36. #define BACKSLASH '\\' /* backslash */
  37. /* defines for constructing filenames */
  38. #define CODE_SUFFIX ".code.c"
  39. #define DEFINES_SUFFIX ".tab.h"
  40. #define OUTPUT_SUFFIX ".tab.c"
  41. #define VERBOSE_SUFFIX ".output"
  42. /* keyword codes */
  43. #define TOKEN 0
  44. #define LEFT 1
  45. #define RIGHT 2
  46. #define NONASSOC 3
  47. #define MARK 4
  48. #define TEXT 5
  49. #define TYPE 6
  50. #define START 7
  51. #define UNION 8
  52. #define IDENT 9
  53. /* symbol classes */
  54. #define UNKNOWN 0
  55. #define TERM 1
  56. #define NONTERM 2
  57. /* the undefined value */
  58. #define UNDEFINED (-1)
  59. /* action codes */
  60. #define SHIFT 1
  61. #define REDUCE 2
  62. /* character macros */
  63. #define IS_IDENT(c) (isalnum(c) || (c) == '_' || (c) == '.' || (c) == '$')
  64. #define IS_OCTAL(c) ((c) >= '0' && (c) <= '7')
  65. #define NUMERIC_VALUE(c) ((c) - '0')
  66. /* symbol macros */
  67. #define ISTOKEN(s) ((s) < start_symbol)
  68. #define ISVAR(s) ((s) >= start_symbol)
  69. /* storage allocation macros */
  70. #define CALLOC(k,n) (calloc((unsigned)(k),(unsigned)(n)))
  71. #define FREE(x) (free((char*)(x)))
  72. #define MALLOC(n) (malloc((unsigned)(n)))
  73. #define NEW(t) ((t*)allocate(sizeof(t)))
  74. #define NEW2(n,t) ((t*)allocate((unsigned)((n)*sizeof(t))))
  75. #define REALLOC(p,n) (realloc((char*)(p),(unsigned)(n)))
  76. /* the structure of a symbol table entry */
  77. typedef struct bucket bucket;
  78. struct bucket
  79. {
  80. struct bucket *link;
  81. struct bucket *next;
  82. char *name;
  83. char *tag;
  84. short value;
  85. short index;
  86. short prec;
  87. char class;
  88. char assoc;
  89. };
  90. /* the structure of the LR(0) state machine */
  91. typedef struct core core;
  92. struct core
  93. {
  94. struct core *next;
  95. struct core *link;
  96. short number;
  97. short accessing_symbol;
  98. short nitems;
  99. short items[1];
  100. };
  101. /* the structure used to record shifts */
  102. typedef struct shifts shifts;
  103. struct shifts
  104. {
  105. struct shifts *next;
  106. short number;
  107. short nshifts;
  108. short shift[1];
  109. };
  110. /* the structure used to store reductions */
  111. typedef struct reductions reductions;
  112. struct reductions
  113. {
  114. struct reductions *next;
  115. short number;
  116. short nreds;
  117. short rules[1];
  118. };
  119. /* the structure used to represent parser actions */
  120. typedef struct action action;
  121. struct action
  122. {
  123. struct action *next;
  124. short symbol;
  125. short number;
  126. short prec;
  127. char action_code;
  128. char assoc;
  129. char suppressed;
  130. };
  131. /* global variables */
  132. extern char dflag;
  133. extern char lflag;
  134. extern char rflag;
  135. extern char tflag;
  136. extern char vflag;
  137. extern char *symbol_prefix;
  138. extern char *myname;
  139. extern char *cptr;
  140. extern char *line;
  141. extern int lineno;
  142. extern int outline;
  143. extern char *banner[];
  144. extern char *tables[];
  145. #if defined (TRIPLISH)
  146. extern char *includefiles[];
  147. #endif
  148. #if defined(KYLEP_CHANGE)
  149. extern char *header1[];
  150. extern char *header2[];
  151. extern char *header3[];
  152. #if defined (TRIPLISH)
  153. extern char *header4[];
  154. #endif
  155. #else
  156. extern char *header[];
  157. #endif
  158. extern char *body[];
  159. extern char *trailer[];
  160. #if defined (TRIPLISH)
  161. extern char *TriplishBody[];
  162. extern char *TriplishTrailer[];
  163. #endif
  164. extern char *action_file_name;
  165. extern char *code_file_name;
  166. extern char *defines_file_name;
  167. extern char *input_file_name;
  168. extern char *output_file_name;
  169. extern char *text_file_name;
  170. extern char *union_file_name;
  171. extern char *verbose_file_name;
  172. extern FILE *action_file;
  173. extern FILE *code_file;
  174. extern FILE *defines_file;
  175. extern FILE *input_file;
  176. extern FILE *output_file;
  177. extern FILE *text_file;
  178. extern FILE *union_file;
  179. extern FILE *verbose_file;
  180. extern int nitems;
  181. extern int nrules;
  182. extern int nsyms;
  183. extern int ntokens;
  184. extern int nvars;
  185. extern int ntags;
  186. extern char unionized;
  187. extern char line_format[];
  188. extern int start_symbol;
  189. extern char **symbol_name;
  190. extern short *symbol_value;
  191. extern short *symbol_prec;
  192. extern char *symbol_assoc;
  193. extern short *ritem;
  194. extern short *rlhs;
  195. extern short *rrhs;
  196. extern short *rprec;
  197. extern char *rassoc;
  198. extern short **derives;
  199. extern char *nullable;
  200. extern bucket *first_symbol;
  201. extern bucket *last_symbol;
  202. extern int nstates;
  203. extern core *first_state;
  204. extern shifts *first_shift;
  205. extern reductions *first_reduction;
  206. extern short *accessing_symbol;
  207. extern core **state_table;
  208. extern shifts **shift_table;
  209. extern reductions **reduction_table;
  210. extern unsigned *LA;
  211. extern short *LAruleno;
  212. extern short *lookaheads;
  213. extern short *goto_map;
  214. extern short *from_state;
  215. extern short *to_state;
  216. extern action **parser;
  217. extern int SRtotal;
  218. extern int RRtotal;
  219. extern short *SRconflicts;
  220. extern short *RRconflicts;
  221. extern short *defred;
  222. extern short *rules_used;
  223. extern short nunused;
  224. extern short final_state;
  225. /* global functions */
  226. extern char *allocate();
  227. extern bucket *lookup();
  228. extern bucket *make_bucket();
  229. /* system variables */
  230. extern int errno;
  231. /* system functions */
  232. #if defined(KYLEP_CHANGE)
  233. #include <stdlib.h>
  234. #include <string.h>
  235. #include <io.h>
  236. #define mktemp _mktemp
  237. #define unlink _unlink
  238. #else
  239. extern void free();
  240. extern char *calloc();
  241. extern char *malloc();
  242. extern char *realloc();
  243. extern char *strcpy();
  244. #endif // KYLEP_CHANGE
  245. #if defined(KYLEP_CHANGE)
  246. extern char *baseclass;
  247. extern char *ctorargs;
  248. /* BYACC prototypes, with type safety */
  249. void reflexive_transitive_closure( unsigned * R, int n );
  250. void set_first_derives();
  251. void closure( short * nucleus, int n );
  252. void finalize_closure();
  253. /* From main.c */
  254. int done( int k );
  255. /* From error.c */
  256. void no_space();
  257. void fatal( char * msg );
  258. void open_error( char * filename );
  259. void unterminated_comment( int c_lineno, char * c_line, char * c_cptr );
  260. void unterminated_string( int s_lineno, char * s_line, char * s_cptr );
  261. void unterminated_text( int t_lineno, char * t_line, char * t_cptr );
  262. void unterminated_union( int u_lineno, char * u_line, char * u_cptr );
  263. void syntax_error( int st_lineno, char * st_line, char * st_cptr );
  264. void unexpected_EOF();
  265. void over_unionized( char * u_cptr );
  266. void illegal_character( char * c_cptr );
  267. void used_reserved( char * s );
  268. void illegal_tag( int t_lineno, char * t_line, char * t_cptr );
  269. void tokenized_start( char * s );
  270. void retyped_warning( char * s );
  271. void reprec_warning( char * s );
  272. void revalued_warning( char * s );
  273. void terminal_start( char * s );
  274. void restarted_warning();
  275. void no_grammar();
  276. void terminal_lhs( int s_lineno );
  277. void default_action_warning();
  278. void dollar_warning( int a_lineno, int i );
  279. void dollar_error( int a_lineno, char * a_line, char * a_cptr );
  280. void untyped_lhs();
  281. void unknown_rhs( int i );
  282. void untyped_rhs( int i, char * s );
  283. void unterminated_action( int a_lineno, char * a_line, char * a_cptr );
  284. void prec_redeclared();
  285. void undefined_goal( char * s );
  286. void undefined_symbol_warning( char * s );
  287. /* From reader.c */
  288. void reader();
  289. /* From lr0.c */
  290. void lr0();
  291. /* From lalr.c */
  292. void lalr();
  293. /* From mkpar.c */
  294. void make_parser();
  295. void free_parser();
  296. /* From verbose.c */
  297. void verbose();
  298. /* From output.c */
  299. void output();
  300. /* From skeleton.c */
  301. void write_section( char * section[], FILE * f );
  302. /* From symtab.c */
  303. void create_symbol_table();
  304. void free_symbol_table();
  305. void free_symbols();
  306. #if defined (TRIPLISH)
  307. enum eParser
  308. {
  309. eSQLParser,
  310. eTriplishParser
  311. };
  312. #endif
  313. #endif //KYLEP_CHANGE