/usr.bin/lex/flexdef.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 1049 lines · 352 code · 244 blank · 453 comment · 8 complexity · 46d623c1fdcb53aa1b801cb11a56f321 MD5 · raw file

  1. /* flexdef - definitions file for flex */
  2. /*-
  3. * Copyright (c) 1990 The Regents of the University of California.
  4. * All rights reserved.
  5. *
  6. * This code is derived from software contributed to Berkeley by
  7. * Vern Paxson.
  8. *
  9. * The United States Government has rights in this work pursuant
  10. * to contract no. DE-AC03-76SF00098 between the United States
  11. * Department of Energy and the University of California.
  12. *
  13. * Redistribution and use in source and binary forms are permitted provided
  14. * that: (1) source distributions retain this entire copyright notice and
  15. * comment, and (2) distributions including binaries display the following
  16. * acknowledgement: ``This product includes software developed by the
  17. * University of California, Berkeley and its contributors'' in the
  18. * documentation or other materials provided with the distribution and in
  19. * all advertising materials mentioning features or use of this software.
  20. * Neither the name of the University nor the names of its contributors may
  21. * be used to endorse or promote products derived from this software without
  22. * specific prior written permission.
  23. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  26. */
  27. /* @(#) $Header: /home/daffy/u0/vern/flex/RCS/flexdef.h,v 2.53 95/04/20 11:17:36 vern Exp $ (LBL) */
  28. /* $FreeBSD$ */
  29. #include <stdio.h>
  30. #include <ctype.h>
  31. #include "config.h"
  32. #ifdef __TURBOC__
  33. #define HAVE_STRING_H 1
  34. #define MS_DOS 1
  35. #ifndef __STDC__
  36. #define __STDC__ 1
  37. #endif
  38. #pragma warn -pro
  39. #pragma warn -rch
  40. #pragma warn -use
  41. #pragma warn -aus
  42. #pragma warn -par
  43. #pragma warn -pia
  44. #endif
  45. #ifdef HAVE_STRING_H
  46. #include <string.h>
  47. #else
  48. #include <strings.h>
  49. #endif
  50. #ifdef HAVE_SYS_TYPES_H
  51. #include <sys/types.h>
  52. #endif
  53. #ifdef HAVE_MALLOC_H
  54. #include <malloc.h>
  55. #endif
  56. #ifdef STDC_HEADERS
  57. #include <stdlib.h>
  58. #endif
  59. /* As an aid for the internationalization patch to flex, which
  60. * is maintained outside this distribution for copyright reasons.
  61. */
  62. #define _(String) (String)
  63. /* Always be prepared to generate an 8-bit scanner. */
  64. #define CSIZE 256
  65. #define Char unsigned char
  66. /* Size of input alphabet - should be size of ASCII set. */
  67. #ifndef DEFAULT_CSIZE
  68. #define DEFAULT_CSIZE 128
  69. #endif
  70. #ifndef PROTO
  71. #if __STDC__
  72. #define PROTO(proto) proto
  73. #else
  74. #define PROTO(proto) ()
  75. #endif
  76. #endif
  77. #ifdef VMS
  78. #ifndef __VMS_POSIX
  79. #define unlink remove
  80. #define SHORT_FILE_NAMES
  81. #endif
  82. #endif
  83. #ifdef MS_DOS
  84. #define SHORT_FILE_NAMES
  85. #endif
  86. /* Maximum line length we'll have to deal with. */
  87. #define MAXLINE 2048
  88. #ifndef MIN
  89. #define MIN(x,y) ((x) < (y) ? (x) : (y))
  90. #endif
  91. #ifndef MAX
  92. #define MAX(x,y) ((x) > (y) ? (x) : (y))
  93. #endif
  94. #ifndef ABS
  95. #define ABS(x) ((x) < 0 ? -(x) : (x))
  96. #endif
  97. /* ANSI C does not guarantee that isascii() is defined */
  98. #ifndef isascii
  99. #define isascii(c) ((c) <= 0177)
  100. #endif
  101. #define true 1
  102. #define false 0
  103. #define unspecified -1
  104. /* Special chk[] values marking the slots taking by end-of-buffer and action
  105. * numbers.
  106. */
  107. #define EOB_POSITION -1
  108. #define ACTION_POSITION -2
  109. /* Number of data items per line for -f output. */
  110. #define NUMDATAITEMS 10
  111. /* Number of lines of data in -f output before inserting a blank line for
  112. * readability.
  113. */
  114. #define NUMDATALINES 10
  115. /* transition_struct_out() definitions. */
  116. #define TRANS_STRUCT_PRINT_LENGTH 14
  117. /* Returns true if an nfa state has an epsilon out-transition slot
  118. * that can be used. This definition is currently not used.
  119. */
  120. #define FREE_EPSILON(state) \
  121. (transchar[state] == SYM_EPSILON && \
  122. trans2[state] == NO_TRANSITION && \
  123. finalst[state] != state)
  124. /* Returns true if an nfa state has an epsilon out-transition character
  125. * and both slots are free
  126. */
  127. #define SUPER_FREE_EPSILON(state) \
  128. (transchar[state] == SYM_EPSILON && \
  129. trans1[state] == NO_TRANSITION) \
  130. /* Maximum number of NFA states that can comprise a DFA state. It's real
  131. * big because if there's a lot of rules, the initial state will have a
  132. * huge epsilon closure.
  133. */
  134. #define INITIAL_MAX_DFA_SIZE 750
  135. #define MAX_DFA_SIZE_INCREMENT 750
  136. /* A note on the following masks. They are used to mark accepting numbers
  137. * as being special. As such, they implicitly limit the number of accepting
  138. * numbers (i.e., rules) because if there are too many rules the rule numbers
  139. * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 ==
  140. * 8192) so unlikely to actually cause any problems. A check is made in
  141. * new_rule() to ensure that this limit is not reached.
  142. */
  143. /* Mask to mark a trailing context accepting number. */
  144. #define YY_TRAILING_MASK 0x2000
  145. /* Mask to mark the accepting number of the "head" of a trailing context
  146. * rule.
  147. */
  148. #define YY_TRAILING_HEAD_MASK 0x4000
  149. /* Maximum number of rules, as outlined in the above note. */
  150. #define MAX_RULE (YY_TRAILING_MASK - 1)
  151. /* NIL must be 0. If not, its special meaning when making equivalence classes
  152. * (it marks the representative of a given e.c.) will be unidentifiable.
  153. */
  154. #define NIL 0
  155. #define JAM -1 /* to mark a missing DFA transition */
  156. #define NO_TRANSITION NIL
  157. #define UNIQUE -1 /* marks a symbol as an e.c. representative */
  158. #define INFINITY -1 /* for x{5,} constructions */
  159. #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
  160. #define MAX_CCLS_INCREMENT 100
  161. /* Size of table holding members of character classes. */
  162. #define INITIAL_MAX_CCL_TBL_SIZE 500
  163. #define MAX_CCL_TBL_SIZE_INCREMENT 250
  164. #define INITIAL_MAX_RULES 100 /* default maximum number of rules */
  165. #define MAX_RULES_INCREMENT 100
  166. #define INITIAL_MNS 2000 /* default maximum number of nfa states */
  167. #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */
  168. #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
  169. #define MAX_DFAS_INCREMENT 1000
  170. #define JAMSTATE -32766 /* marks a reference to the state that always jams */
  171. /* Maximum number of NFA states. */
  172. #define MAXIMUM_MNS 31999
  173. /* Enough so that if it's subtracted from an NFA state number, the result
  174. * is guaranteed to be negative.
  175. */
  176. #define MARKER_DIFFERENCE (MAXIMUM_MNS+2)
  177. /* Maximum number of nxt/chk pairs for non-templates. */
  178. #define INITIAL_MAX_XPAIRS 2000
  179. #define MAX_XPAIRS_INCREMENT 2000
  180. /* Maximum number of nxt/chk pairs needed for templates. */
  181. #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
  182. #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
  183. #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
  184. #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */
  185. #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */
  186. #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */
  187. #define SAME_TRANS -1 /* transition is the same as "default" entry for state */
  188. /* The following percentages are used to tune table compression:
  189. * The percentage the number of out-transitions a state must be of the
  190. * number of equivalence classes in order to be considered for table
  191. * compaction by using protos.
  192. */
  193. #define PROTO_SIZE_PERCENTAGE 15
  194. /* The percentage the number of homogeneous out-transitions of a state
  195. * must be of the number of total out-transitions of the state in order
  196. * that the state's transition table is first compared with a potential
  197. * template of the most common out-transition instead of with the first
  198. * proto in the proto queue.
  199. */
  200. #define CHECK_COM_PERCENTAGE 50
  201. /* The percentage the number of differences between a state's transition
  202. * table and the proto it was first compared with must be of the total
  203. * number of out-transitions of the state in order to keep the first
  204. * proto as a good match and not search any further.
  205. */
  206. #define FIRST_MATCH_DIFF_PERCENTAGE 10
  207. /* The percentage the number of differences between a state's transition
  208. * table and the most similar proto must be of the state's total number
  209. * of out-transitions to use the proto as an acceptable close match.
  210. */
  211. #define ACCEPTABLE_DIFF_PERCENTAGE 50
  212. /* The percentage the number of homogeneous out-transitions of a state
  213. * must be of the number of total out-transitions of the state in order
  214. * to consider making a template from the state.
  215. */
  216. #define TEMPLATE_SAME_PERCENTAGE 60
  217. /* The percentage the number of differences between a state's transition
  218. * table and the most similar proto must be of the state's total number
  219. * of out-transitions to create a new proto from the state.
  220. */
  221. #define NEW_PROTO_DIFF_PERCENTAGE 20
  222. /* The percentage the total number of out-transitions of a state must be
  223. * of the number of equivalence classes in order to consider trying to
  224. * fit the transition table into "holes" inside the nxt/chk table.
  225. */
  226. #define INTERIOR_FIT_PERCENTAGE 15
  227. /* Size of region set aside to cache the complete transition table of
  228. * protos on the proto queue to enable quick comparisons.
  229. */
  230. #define PROT_SAVE_SIZE 2000
  231. #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
  232. /* Maximum number of out-transitions a state can have that we'll rummage
  233. * around through the interior of the internal fast table looking for a
  234. * spot for it.
  235. */
  236. #define MAX_XTIONS_FULL_INTERIOR_FIT 4
  237. /* Maximum number of rules which will be reported as being associated
  238. * with a DFA state.
  239. */
  240. #define MAX_ASSOC_RULES 100
  241. /* Number that, if used to subscript an array, has a good chance of producing
  242. * an error; should be small enough to fit into a short.
  243. */
  244. #define BAD_SUBSCRIPT -32767
  245. /* Absolute value of largest number that can be stored in a short, with a
  246. * bit of slop thrown in for general paranoia.
  247. */
  248. #define MAX_SHORT 32700
  249. /* Declarations for global variables. */
  250. /* Variables for symbol tables:
  251. * sctbl - start-condition symbol table
  252. * ndtbl - name-definition symbol table
  253. * ccltab - character class text symbol table
  254. */
  255. struct hash_entry
  256. {
  257. struct hash_entry *prev, *next;
  258. char *name;
  259. char *str_val;
  260. int int_val;
  261. } ;
  262. typedef struct hash_entry **hash_table;
  263. #define NAME_TABLE_HASH_SIZE 101
  264. #define START_COND_HASH_SIZE 101
  265. #define CCL_HASH_SIZE 101
  266. extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE];
  267. extern struct hash_entry *sctbl[START_COND_HASH_SIZE];
  268. extern struct hash_entry *ccltab[CCL_HASH_SIZE];
  269. /* Variables for flags:
  270. * printstats - if true (-v), dump statistics
  271. * syntaxerror - true if a syntax error has been found
  272. * eofseen - true if we've seen an eof in the input file
  273. * ddebug - if true (-d), make a "debug" scanner
  274. * trace - if true (-T), trace processing
  275. * nowarn - if true (-w), do not generate warnings
  276. * spprdflt - if true (-s), suppress the default rule
  277. * interactive - if true (-I), generate an interactive scanner
  278. * caseins - if true (-i), generate a case-insensitive scanner
  279. * lex_compat - if true (-l), maximize compatibility with AT&T lex
  280. * do_yylineno - if true, generate code to maintain yylineno
  281. * useecs - if true (-Ce flag), use equivalence classes
  282. * fulltbl - if true (-Cf flag), don't compress the DFA state table
  283. * usemecs - if true (-Cm flag), use meta-equivalence classes
  284. * fullspd - if true (-F flag), use Jacobson method of table representation
  285. * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
  286. * performance_report - if > 0 (i.e., -p flag), generate a report relating
  287. * to scanner performance; if > 1 (-p -p), report on minor performance
  288. * problems, too
  289. * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file
  290. * listing backing-up states
  291. * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class;
  292. * otherwise, a standard C scanner
  293. * long_align - if true (-Ca flag), favor long-word alignment.
  294. * use_read - if true (-f, -F, or -Cr) then use read() for scanner input;
  295. * otherwise, use fread().
  296. * yytext_is_array - if true (i.e., %array directive), then declare
  297. * yytext as an array instead of a character pointer. Nice and inefficient.
  298. * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as
  299. * "no more files".
  300. * csize - size of character set for the scanner we're generating;
  301. * 128 for 7-bit chars and 256 for 8-bit
  302. * yymore_used - if true, yymore() is used in input rules
  303. * reject - if true, generate back-up tables for REJECT macro
  304. * real_reject - if true, scanner really uses REJECT (as opposed to just
  305. * having "reject" set for variable trailing context)
  306. * continued_action - true if this rule's action is to "fall through" to
  307. * the next rule's action (i.e., the '|' action)
  308. * in_rule - true if we're inside an individual rule, false if not.
  309. * yymore_really_used - whether to treat yymore() as really used, regardless
  310. * of what we think based on references to it in the user's actions.
  311. * reject_really_used - same for REJECT
  312. */
  313. extern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, spprdflt;
  314. extern int interactive, caseins, lex_compat, do_yylineno;
  315. extern int useecs, fulltbl, usemecs, fullspd;
  316. extern int gen_line_dirs, performance_report, backing_up_report;
  317. extern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap;
  318. extern int csize;
  319. extern int yymore_used, reject, real_reject, continued_action, in_rule;
  320. extern int yymore_really_used, reject_really_used;
  321. /* Variables used in the flex input routines:
  322. * datapos - characters on current output line
  323. * dataline - number of contiguous lines of data in current data
  324. * statement. Used to generate readable -f output
  325. * linenum - current input line number
  326. * out_linenum - current output line number
  327. * skelfile - the skeleton file
  328. * skel - compiled-in skeleton array
  329. * skel_ind - index into "skel" array, if skelfile is nil
  330. * yyin - input file
  331. * backing_up_file - file to summarize backing-up states to
  332. * infilename - name of input file
  333. * outfilename - name of output file
  334. * did_outfilename - whether outfilename was explicitly set
  335. * prefix - the prefix used for externally visible names ("yy" by default)
  336. * yyclass - yyFlexLexer subclass to use for YY_DECL
  337. * do_stdinit - whether to initialize yyin/yyout to stdin/stdout
  338. * use_stdout - the -t flag
  339. * input_files - array holding names of input files
  340. * num_input_files - size of input_files array
  341. * program_name - name with which program was invoked
  342. *
  343. * action_array - array to hold the rule actions
  344. * action_size - size of action_array
  345. * defs1_offset - index where the user's section 1 definitions start
  346. * in action_array
  347. * prolog_offset - index where the prolog starts in action_array
  348. * action_offset - index where the non-prolog starts in action_array
  349. * action_index - index where the next action should go, with respect
  350. * to "action_array"
  351. */
  352. extern int datapos, dataline, linenum, out_linenum;
  353. extern FILE *skelfile, *yyin, *backing_up_file;
  354. extern const char *skel[];
  355. extern int skel_ind;
  356. extern char *infilename, *outfilename;
  357. extern int did_outfilename;
  358. extern char *prefix, *yyclass;
  359. extern int do_stdinit, use_stdout;
  360. extern char **input_files;
  361. extern int num_input_files;
  362. extern char *program_name;
  363. extern char *action_array;
  364. extern int action_size;
  365. extern int defs1_offset, prolog_offset, action_offset, action_index;
  366. /* Variables for stack of states having only one out-transition:
  367. * onestate - state number
  368. * onesym - transition symbol
  369. * onenext - target state
  370. * onedef - default base entry
  371. * onesp - stack pointer
  372. */
  373. extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  374. extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  375. /* Variables for nfa machine data:
  376. * current_mns - current maximum on number of NFA states
  377. * num_rules - number of the last accepting state; also is number of
  378. * rules created so far
  379. * num_eof_rules - number of <<EOF>> rules
  380. * default_rule - number of the default rule
  381. * current_max_rules - current maximum number of rules
  382. * lastnfa - last nfa state number created
  383. * firstst - physically the first state of a fragment
  384. * lastst - last physical state of fragment
  385. * finalst - last logical state of fragment
  386. * transchar - transition character
  387. * trans1 - transition state
  388. * trans2 - 2nd transition state for epsilons
  389. * accptnum - accepting number
  390. * assoc_rule - rule associated with this NFA state (or 0 if none)
  391. * state_type - a STATE_xxx type identifying whether the state is part
  392. * of a normal rule, the leading state in a trailing context
  393. * rule (i.e., the state which marks the transition from
  394. * recognizing the text-to-be-matched to the beginning of
  395. * the trailing context), or a subsequent state in a trailing
  396. * context rule
  397. * rule_type - a RULE_xxx type identifying whether this a ho-hum
  398. * normal rule or one which has variable head & trailing
  399. * context
  400. * rule_linenum - line number associated with rule
  401. * rule_useful - true if we've determined that the rule can be matched
  402. */
  403. extern int current_mns, current_max_rules;
  404. extern int num_rules, num_eof_rules, default_rule, lastnfa;
  405. extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
  406. extern int *accptnum, *assoc_rule, *state_type;
  407. extern int *rule_type, *rule_linenum, *rule_useful;
  408. /* Different types of states; values are useful as masks, as well, for
  409. * routines like check_trailing_context().
  410. */
  411. #define STATE_NORMAL 0x1
  412. #define STATE_TRAILING_CONTEXT 0x2
  413. /* Global holding current type of state we're making. */
  414. extern int current_state_type;
  415. /* Different types of rules. */
  416. #define RULE_NORMAL 0
  417. #define RULE_VARIABLE 1
  418. /* True if the input rules include a rule with both variable-length head
  419. * and trailing context, false otherwise.
  420. */
  421. extern int variable_trailing_context_rules;
  422. /* Variables for protos:
  423. * numtemps - number of templates created
  424. * numprots - number of protos created
  425. * protprev - backlink to a more-recently used proto
  426. * protnext - forward link to a less-recently used proto
  427. * prottbl - base/def table entry for proto
  428. * protcomst - common state of proto
  429. * firstprot - number of the most recently used proto
  430. * lastprot - number of the least recently used proto
  431. * protsave contains the entire state array for protos
  432. */
  433. extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  434. extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  435. /* Variables for managing equivalence classes:
  436. * numecs - number of equivalence classes
  437. * nextecm - forward link of Equivalence Class members
  438. * ecgroup - class number or backward link of EC members
  439. * nummecs - number of meta-equivalence classes (used to compress
  440. * templates)
  441. * tecfwd - forward link of meta-equivalence classes members
  442. * tecbck - backward link of MEC's
  443. */
  444. /* Reserve enough room in the equivalence class arrays so that we
  445. * can use the CSIZE'th element to hold equivalence class information
  446. * for the NUL character. Later we'll move this information into
  447. * the 0th element.
  448. */
  449. extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
  450. /* Meta-equivalence classes are indexed starting at 1, so it's possible
  451. * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
  452. * slots total (since the arrays are 0-based). nextecm[] and ecgroup[]
  453. * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
  454. */
  455. extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
  456. /* Variables for start conditions:
  457. * lastsc - last start condition created
  458. * current_max_scs - current limit on number of start conditions
  459. * scset - set of rules active in start condition
  460. * scbol - set of rules active only at the beginning of line in a s.c.
  461. * scxclu - true if start condition is exclusive
  462. * sceof - true if start condition has EOF rule
  463. * scname - start condition name
  464. */
  465. extern int lastsc, *scset, *scbol, *scxclu, *sceof;
  466. extern int current_max_scs;
  467. extern char **scname;
  468. /* Variables for dfa machine data:
  469. * current_max_dfa_size - current maximum number of NFA states in DFA
  470. * current_max_xpairs - current maximum number of non-template xtion pairs
  471. * current_max_template_xpairs - current maximum number of template pairs
  472. * current_max_dfas - current maximum number DFA states
  473. * lastdfa - last dfa state number created
  474. * nxt - state to enter upon reading character
  475. * chk - check value to see if "nxt" applies
  476. * tnxt - internal nxt table for templates
  477. * base - offset into "nxt" for given state
  478. * def - where to go if "chk" disallows "nxt" entry
  479. * nultrans - NUL transition for each state
  480. * NUL_ec - equivalence class of the NUL character
  481. * tblend - last "nxt/chk" table entry being used
  482. * firstfree - first empty entry in "nxt/chk" table
  483. * dss - nfa state set for each dfa
  484. * dfasiz - size of nfa state set for each dfa
  485. * dfaacc - accepting set for each dfa state (if using REJECT), or accepting
  486. * number, if not
  487. * accsiz - size of accepting set for each dfa state
  488. * dhash - dfa state hash value
  489. * numas - number of DFA accepting states created; note that this
  490. * is not necessarily the same value as num_rules, which is the analogous
  491. * value for the NFA
  492. * numsnpairs - number of state/nextstate transition pairs
  493. * jambase - position in base/def where the default jam table starts
  494. * jamstate - state number corresponding to "jam" state
  495. * end_of_buffer_state - end-of-buffer dfa state number
  496. */
  497. extern int current_max_dfa_size, current_max_xpairs;
  498. extern int current_max_template_xpairs, current_max_dfas;
  499. extern int lastdfa, *nxt, *chk, *tnxt;
  500. extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
  501. extern union dfaacc_union
  502. {
  503. int *dfaacc_set;
  504. int dfaacc_state;
  505. } *dfaacc;
  506. extern int *accsiz, *dhash, numas;
  507. extern int numsnpairs, jambase, jamstate;
  508. extern int end_of_buffer_state;
  509. /* Variables for ccl information:
  510. * lastccl - ccl index of the last created ccl
  511. * current_maxccls - current limit on the maximum number of unique ccl's
  512. * cclmap - maps a ccl index to its set pointer
  513. * ccllen - gives the length of a ccl
  514. * cclng - true for a given ccl if the ccl is negated
  515. * cclreuse - counts how many times a ccl is re-used
  516. * current_max_ccl_tbl_size - current limit on number of characters needed
  517. * to represent the unique ccl's
  518. * ccltbl - holds the characters in each ccl - indexed by cclmap
  519. */
  520. extern int lastccl, *cclmap, *ccllen, *cclng, cclreuse;
  521. extern int current_maxccls, current_max_ccl_tbl_size;
  522. extern Char *ccltbl;
  523. /* Variables for miscellaneous information:
  524. * nmstr - last NAME scanned by the scanner
  525. * sectnum - section number currently being parsed
  526. * nummt - number of empty nxt/chk table entries
  527. * hshcol - number of hash collisions detected by snstods
  528. * dfaeql - number of times a newly created dfa was equal to an old one
  529. * numeps - number of epsilon NFA states created
  530. * eps2 - number of epsilon states which have 2 out-transitions
  531. * num_reallocs - number of times it was necessary to realloc() a group
  532. * of arrays
  533. * tmpuses - number of DFA states that chain to templates
  534. * totnst - total number of NFA states used to make DFA states
  535. * peakpairs - peak number of transition pairs we had to store internally
  536. * numuniq - number of unique transitions
  537. * numdup - number of duplicate transitions
  538. * hshsave - number of hash collisions saved by checking number of states
  539. * num_backing_up - number of DFA states requiring backing up
  540. * bol_needed - whether scanner needs beginning-of-line recognition
  541. */
  542. extern char nmstr[MAXLINE];
  543. extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  544. extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  545. extern int num_backing_up, bol_needed;
  546. void *allocate_array PROTO((int, size_t));
  547. void *reallocate_array PROTO((void*, int, size_t));
  548. void *flex_alloc PROTO((size_t));
  549. void *flex_realloc PROTO((void*, size_t));
  550. void flex_free PROTO((void*));
  551. #define allocate_integer_array(size) \
  552. (int *) allocate_array( size, sizeof( int ) )
  553. #define reallocate_integer_array(array,size) \
  554. (int *) reallocate_array( (void *) array, size, sizeof( int ) )
  555. #define allocate_int_ptr_array(size) \
  556. (int **) allocate_array( size, sizeof( int * ) )
  557. #define allocate_char_ptr_array(size) \
  558. (char **) allocate_array( size, sizeof( char * ) )
  559. #define allocate_dfaacc_union(size) \
  560. (union dfaacc_union *) \
  561. allocate_array( size, sizeof( union dfaacc_union ) )
  562. #define reallocate_int_ptr_array(array,size) \
  563. (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
  564. #define reallocate_char_ptr_array(array,size) \
  565. (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
  566. #define reallocate_dfaacc_union(array, size) \
  567. (union dfaacc_union *) \
  568. reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
  569. #define allocate_character_array(size) \
  570. (char *) allocate_array( size, sizeof( char ) )
  571. #define reallocate_character_array(array,size) \
  572. (char *) reallocate_array( (void *) array, size, sizeof( char ) )
  573. #define allocate_Character_array(size) \
  574. (Char *) allocate_array( size, sizeof( Char ) )
  575. #define reallocate_Character_array(array,size) \
  576. (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
  577. /* Used to communicate between scanner and parser. The type should really
  578. * be YYSTYPE, but we can't easily get our hands on it.
  579. */
  580. extern int yylval;
  581. /* External functions that are cross-referenced among the flex source files. */
  582. /* from file ccl.c */
  583. extern void ccladd PROTO((int, int)); /* add a single character to a ccl */
  584. extern int cclinit PROTO((void)); /* make an empty ccl */
  585. extern void cclnegate PROTO((int)); /* negate a ccl */
  586. /* List the members of a set of characters in CCL form. */
  587. extern void list_character_set PROTO((FILE*, int[]));
  588. /* from file dfa.c */
  589. /* Check a DFA state for backing up. */
  590. extern void check_for_backing_up PROTO((int, int[]));
  591. /* Check to see if NFA state set constitutes "dangerous" trailing context. */
  592. extern void check_trailing_context PROTO((int*, int, int*, int));
  593. /* Construct the epsilon closure of a set of ndfa states. */
  594. extern int *epsclosure PROTO((int*, int*, int[], int*, int*));
  595. /* Increase the maximum number of dfas. */
  596. extern void increase_max_dfas PROTO((void));
  597. extern void ntod PROTO((void)); /* convert a ndfa to a dfa */
  598. /* Converts a set of ndfa states into a dfa state. */
  599. extern int snstods PROTO((int[], int, int[], int, int, int*));
  600. /* from file ecs.c */
  601. /* Convert character classes to set of equivalence classes. */
  602. extern void ccl2ecl PROTO((void));
  603. /* Associate equivalence class numbers with class members. */
  604. extern int cre8ecs PROTO((int[], int[], int));
  605. /* Update equivalence classes based on character class transitions. */
  606. extern void mkeccl PROTO((Char[], int, int[], int[], int, int));
  607. /* Create equivalence class for single character. */
  608. extern void mkechar PROTO((int, int[], int[]));
  609. /* from file gen.c */
  610. extern void do_indent PROTO((void)); /* indent to the current level */
  611. /* Generate the code to keep backing-up information. */
  612. extern void gen_backing_up PROTO((void));
  613. /* Generate the code to perform the backing up. */
  614. extern void gen_bu_action PROTO((void));
  615. /* Generate full speed compressed transition table. */
  616. extern void genctbl PROTO((void));
  617. /* Generate the code to find the action number. */
  618. extern void gen_find_action PROTO((void));
  619. extern void genftbl PROTO((void)); /* generate full transition table */
  620. /* Generate the code to find the next compressed-table state. */
  621. extern void gen_next_compressed_state PROTO((char*));
  622. /* Generate the code to find the next match. */
  623. extern void gen_next_match PROTO((void));
  624. /* Generate the code to find the next state. */
  625. extern void gen_next_state PROTO((int));
  626. /* Generate the code to make a NUL transition. */
  627. extern void gen_NUL_trans PROTO((void));
  628. /* Generate the code to find the start state. */
  629. extern void gen_start_state PROTO((void));
  630. /* Generate data statements for the transition tables. */
  631. extern void gentabs PROTO((void));
  632. /* Write out a formatted string at the current indentation level. */
  633. extern void indent_put2s PROTO((char[], char[]));
  634. /* Write out a string + newline at the current indentation level. */
  635. extern void indent_puts PROTO((char[]));
  636. extern void make_tables PROTO((void)); /* generate transition tables */
  637. /* from file main.c */
  638. extern void check_options PROTO((void));
  639. extern void flexend PROTO((int));
  640. extern void usage PROTO((void));
  641. /* from file misc.c */
  642. /* Add a #define to the action file. */
  643. extern void action_define PROTO(( char *defname, int value ));
  644. /* Add the given text to the stored actions. */
  645. extern void add_action PROTO(( char *new_text ));
  646. /* True if a string is all lower case. */
  647. extern int all_lower PROTO((char *));
  648. /* True if a string is all upper case. */
  649. extern int all_upper PROTO((char *));
  650. /* Bubble sort an integer array. */
  651. extern void bubble PROTO((int [], int));
  652. /* Check a character to make sure it's in the expected range. */
  653. extern void check_char PROTO((int c));
  654. /* Replace upper-case letter to lower-case. */
  655. extern Char clower PROTO((int));
  656. /* Returns a dynamically allocated copy of a string. */
  657. extern char *copy_string PROTO((const char *));
  658. /* Returns a dynamically allocated copy of a (potentially) unsigned string. */
  659. extern Char *copy_unsigned_string PROTO((Char *));
  660. /* Shell sort a character array. */
  661. extern void cshell PROTO((Char [], int, int));
  662. /* Finish up a block of data declarations. */
  663. extern void dataend PROTO((void));
  664. /* Flush generated data statements. */
  665. extern void dataflush PROTO((void));
  666. /* Report an error message and terminate. */
  667. extern void flexerror PROTO((const char[]));
  668. /* Report a fatal error message and terminate. */
  669. extern void flexfatal PROTO((const char[]));
  670. /* Convert a hexadecimal digit string to an integer value. */
  671. extern int htoi PROTO((Char[]));
  672. /* Report an error message formatted with one integer argument. */
  673. extern void lerrif PROTO((const char[], int));
  674. /* Report an error message formatted with one string argument. */
  675. extern void lerrsf PROTO((const char[], const char[]));
  676. /* Spit out a "#line" statement. */
  677. extern void line_directive_out PROTO((FILE*, int));
  678. /* Mark the current position in the action array as the end of the section 1
  679. * user defs.
  680. */
  681. extern void mark_defs1 PROTO((void));
  682. /* Mark the current position in the action array as the end of the prolog. */
  683. extern void mark_prolog PROTO((void));
  684. /* Generate a data statement for a two-dimensional array. */
  685. extern void mk2data PROTO((int));
  686. extern void mkdata PROTO((int)); /* generate a data statement */
  687. /* Return the integer represented by a string of digits. */
  688. extern int myctoi PROTO((char []));
  689. /* Return character corresponding to escape sequence. */
  690. extern Char myesc PROTO((Char[]));
  691. /* Convert an octal digit string to an integer value. */
  692. extern int otoi PROTO((Char [] ));
  693. /* Output a (possibly-formatted) string to the generated scanner. */
  694. extern void out PROTO((const char []));
  695. extern void out_dec PROTO((const char [], int));
  696. extern void out_dec2 PROTO((const char [], int, int));
  697. extern void out_hex PROTO((const char [], unsigned int));
  698. extern void out_line_count PROTO((const char []));
  699. extern void out_str PROTO((const char [], const char []));
  700. extern void out_str3
  701. PROTO((const char [], const char [], const char [], const char []));
  702. extern void out_str_dec PROTO((const char [], const char [], int));
  703. extern void outc PROTO((int));
  704. extern void outn PROTO((const char []));
  705. /* Return a printable version of the given character, which might be
  706. * 8-bit.
  707. */
  708. extern char *readable_form PROTO((int));
  709. /* Write out one section of the skeleton file. */
  710. extern void skelout PROTO((void));
  711. /* Output a yy_trans_info structure. */
  712. extern void transition_struct_out PROTO((int, int));
  713. /* Only needed when using certain broken versions of bison to build parse.c. */
  714. extern void *yy_flex_xmalloc PROTO(( int ));
  715. /* Set a region of memory to 0. */
  716. extern void zero_out PROTO((char *, size_t));
  717. /* from file nfa.c */
  718. /* Add an accepting state to a machine. */
  719. extern void add_accept PROTO((int, int));
  720. /* Make a given number of copies of a singleton machine. */
  721. extern int copysingl PROTO((int, int));
  722. /* Debugging routine to write out an nfa. */
  723. extern void dumpnfa PROTO((int));
  724. /* Finish up the processing for a rule. */
  725. extern void finish_rule PROTO((int, int, int, int));
  726. /* Connect two machines together. */
  727. extern int link_machines PROTO((int, int));
  728. /* Mark each "beginning" state in a machine as being a "normal" (i.e.,
  729. * not trailing context associated) state.
  730. */
  731. extern void mark_beginning_as_normal PROTO((int));
  732. /* Make a machine that branches to two machines. */
  733. extern int mkbranch PROTO((int, int));
  734. extern int mkclos PROTO((int)); /* convert a machine into a closure */
  735. extern int mkopt PROTO((int)); /* make a machine optional */
  736. /* Make a machine that matches either one of two machines. */
  737. extern int mkor PROTO((int, int));
  738. /* Convert a machine into a positive closure. */
  739. extern int mkposcl PROTO((int));
  740. extern int mkrep PROTO((int, int, int)); /* make a replicated machine */
  741. /* Create a state with a transition on a given symbol. */
  742. extern int mkstate PROTO((int));
  743. extern void new_rule PROTO((void)); /* initialize for a new rule */
  744. /* from file parse.y */
  745. /* Build the "<<EOF>>" action for the active start conditions. */
  746. extern void build_eof_action PROTO((void));
  747. /* Write out a message formatted with one string, pinpointing its location. */
  748. extern void format_pinpoint_message PROTO((char[], char[]));
  749. /* Write out a message, pinpointing its location. */
  750. extern void pinpoint_message PROTO((char[]));
  751. /* Write out a warning, pinpointing it at the given line. */
  752. extern void line_warning PROTO(( char[], int ));
  753. /* Write out a message, pinpointing it at the given line. */
  754. extern void line_pinpoint PROTO(( char[], int ));
  755. /* Report a formatted syntax error. */
  756. extern void format_synerr PROTO((char [], char[]));
  757. extern void synerr PROTO((char [])); /* report a syntax error */
  758. extern void format_warn PROTO((char [], char[]));
  759. extern void warn PROTO((char [])); /* report a warning */
  760. extern void yyerror PROTO((char [])); /* report a parse error */
  761. extern int yyparse PROTO((void)); /* the YACC parser */
  762. /* from file scan.l */
  763. /* The Flex-generated scanner for flex. */
  764. extern int flexscan PROTO((void));
  765. /* Open the given file (if NULL, stdin) for scanning. */
  766. extern void set_input_file PROTO((char*));
  767. /* Wrapup a file in the lexical analyzer. */
  768. extern int yywrap PROTO((void));
  769. /* from file sym.c */
  770. /* Add symbol and definitions to symbol table. */
  771. extern int addsym PROTO((char[], char*, int, hash_table, int));
  772. /* Save the text of a character class. */
  773. extern void cclinstal PROTO ((Char [], int));
  774. /* Lookup the number associated with character class. */
  775. extern int ccllookup PROTO((Char []));
  776. /* Find symbol in symbol table. */
  777. extern struct hash_entry *findsym PROTO((char[], hash_table, int ));
  778. extern void ndinstal PROTO((char[], Char[])); /* install a name definition */
  779. extern Char *ndlookup PROTO((char[])); /* lookup a name definition */
  780. /* Increase maximum number of SC's. */
  781. extern void scextend PROTO((void));
  782. extern void scinstal PROTO((char[], int)); /* make a start condition */
  783. /* Lookup the number associated with a start condition. */
  784. extern int sclookup PROTO((char[]));
  785. /* from file tblcmp.c */
  786. /* Build table entries for dfa state. */
  787. extern void bldtbl PROTO((int[], int, int, int, int));
  788. extern void cmptmps PROTO((void)); /* compress template table entries */
  789. extern void expand_nxt_chk PROTO((void)); /* increase nxt/chk arrays */
  790. /* Finds a space in the table for a state to be placed. */
  791. extern int find_table_space PROTO((int*, int));
  792. extern void inittbl PROTO((void)); /* initialize transition tables */
  793. /* Make the default, "jam" table entries. */
  794. extern void mkdeftbl PROTO((void));
  795. /* Create table entries for a state (or state fragment) which has
  796. * only one out-transition.
  797. */
  798. extern void mk1tbl PROTO((int, int, int, int));
  799. /* Place a state into full speed transition table. */
  800. extern void place_state PROTO((int*, int, int));
  801. /* Save states with only one out-transition to be processed later. */
  802. extern void stack1 PROTO((int, int, int, int));
  803. /* from file yylex.c */
  804. extern int yylex PROTO((void));