flexdef.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. /* @(#) $Id$ (LBL) */
  28. #ifndef FILE
  29. #include <stdio.h>
  30. #endif
  31. /* always be prepared to generate an 8-bit scanner */
  32. #define FLEX_8_BIT_CHARS
  33. #ifdef FLEX_8_BIT_CHARS
  34. #define CSIZE 256
  35. #define Char unsigned char
  36. #else
  37. #define Char char
  38. #define CSIZE 128
  39. #endif
  40. /* size of input alphabet - should be size of ASCII set */
  41. #ifndef DEFAULT_CSIZE
  42. #define DEFAULT_CSIZE 128
  43. #endif
  44. #ifndef PROTO
  45. #ifdef __STDC__
  46. #define PROTO(proto) proto
  47. #else
  48. #define PROTO(proto) ()
  49. #endif
  50. #endif
  51. #ifndef ACK_MOD
  52. #ifdef USG
  53. #define SYS_V
  54. #endif
  55. #ifdef SYS_V
  56. #include <string.h>
  57. #else
  58. #include <strings.h>
  59. #ifdef lint
  60. char *sprintf(); /* keep lint happy */
  61. #endif
  62. #ifdef SCO_UNIX
  63. void *memset();
  64. #else
  65. char *memset();
  66. #endif
  67. #endif
  68. #else /* ACK_MOD */
  69. extern char *strcpy();
  70. #endif /* ACK_MOD */
  71. #ifndef ACK_MOD
  72. #ifdef AMIGA
  73. #define bzero(s, n) setmem((char *)(s), n, '\0')
  74. #ifndef abs
  75. #define abs(x) ((x) < 0 ? -(x) : (x))
  76. #endif
  77. #else
  78. #define bzero(s, n) (void) memset((char *)(s), '\0', n)
  79. #endif
  80. #endif /* not ACK_MOD */
  81. #ifdef VMS
  82. #define unlink delete
  83. #define SHORT_FILE_NAMES
  84. #endif
  85. #ifdef __STDC__
  86. #ifdef __GNUC__
  87. #include <stddef.h>
  88. void *malloc( size_t );
  89. void free( void* );
  90. #else
  91. #include <stdlib.h>
  92. #endif
  93. #else /* ! __STDC__ */
  94. char *malloc(), *realloc();
  95. #endif
  96. /* maximum line length we'll have to deal with */
  97. #define MAXLINE BUFSIZ
  98. /* maximum size of file name */
  99. #define FILENAMESIZE 1024
  100. #ifndef min
  101. #define min(x,y) ((x) < (y) ? (x) : (y))
  102. #endif
  103. #ifndef max
  104. #define max(x,y) ((x) > (y) ? (x) : (y))
  105. #endif
  106. #ifdef MS_DOS
  107. #ifndef abs
  108. #define abs(x) ((x) < 0 ? -(x) : (x))
  109. #endif
  110. #define SHORT_FILE_NAMES
  111. #endif
  112. #define true 1
  113. #define false 0
  114. #ifndef DEFAULT_SKELETON_FILE
  115. #define DEFAULT_SKELETON_FILE "flex.skel"
  116. #endif
  117. /* special chk[] values marking the slots taking by end-of-buffer and action
  118. * numbers
  119. */
  120. #define EOB_POSITION -1
  121. #define ACTION_POSITION -2
  122. /* number of data items per line for -f output */
  123. #define NUMDATAITEMS 10
  124. /* number of lines of data in -f output before inserting a blank line for
  125. * readability.
  126. */
  127. #define NUMDATALINES 10
  128. /* transition_struct_out() definitions */
  129. #define TRANS_STRUCT_PRINT_LENGTH 15
  130. /* returns true if an nfa state has an epsilon out-transition slot
  131. * that can be used. This definition is currently not used.
  132. */
  133. #define FREE_EPSILON(state) \
  134. (transchar[state] == SYM_EPSILON && \
  135. trans2[state] == NO_TRANSITION && \
  136. finalst[state] != state)
  137. /* returns true if an nfa state has an epsilon out-transition character
  138. * and both slots are free
  139. */
  140. #define SUPER_FREE_EPSILON(state) \
  141. (transchar[state] == SYM_EPSILON && \
  142. trans1[state] == NO_TRANSITION) \
  143. /* maximum number of NFA states that can comprise a DFA state. It's real
  144. * big because if there's a lot of rules, the initial state will have a
  145. * huge epsilon closure.
  146. */
  147. #define INITIAL_MAX_DFA_SIZE 750
  148. #define MAX_DFA_SIZE_INCREMENT 750
  149. /* a note on the following masks. They are used to mark accepting numbers
  150. * as being special. As such, they implicitly limit the number of accepting
  151. * numbers (i.e., rules) because if there are too many rules the rule numbers
  152. * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 ==
  153. * 8192) so unlikely to actually cause any problems. A check is made in
  154. * new_rule() to ensure that this limit is not reached.
  155. */
  156. /* mask to mark a trailing context accepting number */
  157. #define YY_TRAILING_MASK 0x2000
  158. /* mask to mark the accepting number of the "head" of a trailing context rule */
  159. #define YY_TRAILING_HEAD_MASK 0x4000
  160. /* maximum number of rules, as outlined in the above note */
  161. #define MAX_RULE (YY_TRAILING_MASK - 1)
  162. /* NIL must be 0. If not, its special meaning when making equivalence classes
  163. * (it marks the representative of a given e.c.) will be unidentifiable
  164. */
  165. #define NIL 0
  166. #define JAM -1 /* to mark a missing DFA transition */
  167. #define NO_TRANSITION NIL
  168. #define UNIQUE -1 /* marks a symbol as an e.c. representative */
  169. #define INFINITY -1 /* for x{5,} constructions */
  170. #define INITIAL_MAX_CCLS 100 /* max number of unique character classes */
  171. #define MAX_CCLS_INCREMENT 100
  172. /* size of table holding members of character classes */
  173. #define INITIAL_MAX_CCL_TBL_SIZE 500
  174. #define MAX_CCL_TBL_SIZE_INCREMENT 250
  175. #define INITIAL_MAX_RULES 100 /* default maximum number of rules */
  176. #define MAX_RULES_INCREMENT 100
  177. #define INITIAL_MNS 2000 /* default maximum number of nfa states */
  178. #define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */
  179. #define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */
  180. #define MAX_DFAS_INCREMENT 1000
  181. #define JAMSTATE -32766 /* marks a reference to the state that always jams */
  182. /* enough so that if it's subtracted from an NFA state number, the result
  183. * is guaranteed to be negative
  184. */
  185. #define MARKER_DIFFERENCE 32000
  186. #define MAXIMUM_MNS 31999
  187. /* maximum number of nxt/chk pairs for non-templates */
  188. #define INITIAL_MAX_XPAIRS 2000
  189. #define MAX_XPAIRS_INCREMENT 2000
  190. /* maximum number of nxt/chk pairs needed for templates */
  191. #define INITIAL_MAX_TEMPLATE_XPAIRS 2500
  192. #define MAX_TEMPLATE_XPAIRS_INCREMENT 2500
  193. #define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */
  194. #define INITIAL_MAX_SCS 40 /* maximum number of start conditions */
  195. #define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */
  196. #define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */
  197. #define SAME_TRANS -1 /* transition is the same as "default" entry for state */
  198. /* the following percentages are used to tune table compression:
  199. * the percentage the number of out-transitions a state must be of the
  200. * number of equivalence classes in order to be considered for table
  201. * compaction by using protos
  202. */
  203. #define PROTO_SIZE_PERCENTAGE 15
  204. /* the percentage the number of homogeneous out-transitions of a state
  205. * must be of the number of total out-transitions of the state in order
  206. * that the state's transition table is first compared with a potential
  207. * template of the most common out-transition instead of with the first
  208. * proto in the proto queue
  209. */
  210. #define CHECK_COM_PERCENTAGE 50
  211. /* the percentage the number of differences between a state's transition
  212. * table and the proto it was first compared with must be of the total
  213. * number of out-transitions of the state in order to keep the first
  214. * proto as a good match and not search any further
  215. */
  216. #define FIRST_MATCH_DIFF_PERCENTAGE 10
  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 use the proto as an acceptable close match
  220. */
  221. #define ACCEPTABLE_DIFF_PERCENTAGE 50
  222. /* the percentage the number of homogeneous out-transitions of a state
  223. * must be of the number of total out-transitions of the state in order
  224. * to consider making a template from the state
  225. */
  226. #define TEMPLATE_SAME_PERCENTAGE 60
  227. /* the percentage the number of differences between a state's transition
  228. * table and the most similar proto must be of the state's total number
  229. * of out-transitions to create a new proto from the state
  230. */
  231. #define NEW_PROTO_DIFF_PERCENTAGE 20
  232. /* the percentage the total number of out-transitions of a state must be
  233. * of the number of equivalence classes in order to consider trying to
  234. * fit the transition table into "holes" inside the nxt/chk table.
  235. */
  236. #define INTERIOR_FIT_PERCENTAGE 15
  237. /* size of region set aside to cache the complete transition table of
  238. * protos on the proto queue to enable quick comparisons
  239. */
  240. #define PROT_SAVE_SIZE 2000
  241. #define MSP 50 /* maximum number of saved protos (protos on the proto queue) */
  242. /* maximum number of out-transitions a state can have that we'll rummage
  243. * around through the interior of the internal fast table looking for a
  244. * spot for it
  245. */
  246. #define MAX_XTIONS_FULL_INTERIOR_FIT 4
  247. /* maximum number of rules which will be reported as being associated
  248. * with a DFA state
  249. */
  250. #define MAX_ASSOC_RULES 100
  251. /* number that, if used to subscript an array, has a good chance of producing
  252. * an error; should be small enough to fit into a short
  253. */
  254. #define BAD_SUBSCRIPT -32767
  255. /* absolute value of largest number that can be stored in a short, with a
  256. * bit of slop thrown in for general paranoia.
  257. */
  258. #define MAX_SHORT 32766
  259. /* Declarations for global variables. */
  260. /* variables for symbol tables:
  261. * sctbl - start-condition symbol table
  262. * ndtbl - name-definition symbol table
  263. * ccltab - character class text symbol table
  264. */
  265. struct hash_entry
  266. {
  267. struct hash_entry *prev, *next;
  268. char *name;
  269. char *str_val;
  270. int int_val;
  271. } ;
  272. typedef struct hash_entry *hash_table[];
  273. #define NAME_TABLE_HASH_SIZE 101
  274. #define START_COND_HASH_SIZE 101
  275. #define CCL_HASH_SIZE 101
  276. extern struct hash_entry *ndtbl[NAME_TABLE_HASH_SIZE];
  277. extern struct hash_entry *sctbl[START_COND_HASH_SIZE];
  278. extern struct hash_entry *ccltab[CCL_HASH_SIZE];
  279. /* variables for flags:
  280. * printstats - if true (-v), dump statistics
  281. * syntaxerror - true if a syntax error has been found
  282. * eofseen - true if we've seen an eof in the input file
  283. * ddebug - if true (-d), make a "debug" scanner
  284. * trace - if true (-T), trace processing
  285. * spprdflt - if true (-s), suppress the default rule
  286. * interactive - if true (-I), generate an interactive scanner
  287. * caseins - if true (-i), generate a case-insensitive scanner
  288. * useecs - if true (-Ce flag), use equivalence classes
  289. * fulltbl - if true (-Cf flag), don't compress the DFA state table
  290. * usemecs - if true (-Cm flag), use meta-equivalence classes
  291. * fullspd - if true (-F flag), use Jacobson method of table representation
  292. * gen_line_dirs - if true (i.e., no -L flag), generate #line directives
  293. * performance_report - if true (i.e., -p flag), generate a report relating
  294. * to scanner performance
  295. * backtrack_report - if true (i.e., -b flag), generate "lex.backtrack" file
  296. * listing backtracking states
  297. * csize - size of character set for the scanner we're generating;
  298. * 128 for 7-bit chars and 256 for 8-bit
  299. * yymore_used - if true, yymore() is used in input rules
  300. * reject - if true, generate backtracking tables for REJECT macro
  301. * real_reject - if true, scanner really uses REJECT (as opposed to just
  302. * having "reject" set for variable trailing context)
  303. * continued_action - true if this rule's action is to "fall through" to
  304. * the next rule's action (i.e., the '|' action)
  305. * yymore_really_used - has a REALLY_xxx value indicating whether a
  306. * %used or %notused was used with yymore()
  307. * reject_really_used - same for REJECT
  308. */
  309. extern int printstats, syntaxerror, eofseen, ddebug, trace, spprdflt;
  310. extern int interactive, caseins, useecs, fulltbl, usemecs;
  311. extern int fullspd, gen_line_dirs, performance_report, backtrack_report, csize;
  312. extern int yymore_used, reject, real_reject, continued_action;
  313. #define REALLY_NOT_DETERMINED 0
  314. #define REALLY_USED 1
  315. #define REALLY_NOT_USED 2
  316. extern int yymore_really_used, reject_really_used;
  317. /* variables used in the flex input routines:
  318. * datapos - characters on current output line
  319. * dataline - number of contiguous lines of data in current data
  320. * statement. Used to generate readable -f output
  321. * linenum - current input line number
  322. * skelfile - the skeleton file
  323. * yyin - input file
  324. * temp_action_file - temporary file to hold actions
  325. * backtrack_file - file to summarize backtracking states to
  326. * infilename - name of input file
  327. * action_file_name - name of the temporary file
  328. * input_files - array holding names of input files
  329. * num_input_files - size of input_files array
  330. * program_name - name with which program was invoked
  331. */
  332. extern int datapos, dataline, linenum;
  333. extern FILE *skelfile, *yyin, *temp_action_file, *backtrack_file;
  334. extern char *infilename;
  335. extern char *action_file_name;
  336. extern char **input_files;
  337. extern int num_input_files;
  338. extern char *program_name;
  339. /* variables for stack of states having only one out-transition:
  340. * onestate - state number
  341. * onesym - transition symbol
  342. * onenext - target state
  343. * onedef - default base entry
  344. * onesp - stack pointer
  345. */
  346. extern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE];
  347. extern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp;
  348. /* variables for nfa machine data:
  349. * current_mns - current maximum on number of NFA states
  350. * num_rules - number of the last accepting state; also is number of
  351. * rules created so far
  352. * current_max_rules - current maximum number of rules
  353. * lastnfa - last nfa state number created
  354. * firstst - physically the first state of a fragment
  355. * lastst - last physical state of fragment
  356. * finalst - last logical state of fragment
  357. * transchar - transition character
  358. * trans1 - transition state
  359. * trans2 - 2nd transition state for epsilons
  360. * accptnum - accepting number
  361. * assoc_rule - rule associated with this NFA state (or 0 if none)
  362. * state_type - a STATE_xxx type identifying whether the state is part
  363. * of a normal rule, the leading state in a trailing context
  364. * rule (i.e., the state which marks the transition from
  365. * recognizing the text-to-be-matched to the beginning of
  366. * the trailing context), or a subsequent state in a trailing
  367. * context rule
  368. * rule_type - a RULE_xxx type identifying whether this a a ho-hum
  369. * normal rule or one which has variable head & trailing
  370. * context
  371. * rule_linenum - line number associated with rule
  372. */
  373. extern int current_mns, num_rules, current_max_rules, lastnfa;
  374. extern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2;
  375. extern int *accptnum, *assoc_rule, *state_type, *rule_type, *rule_linenum;
  376. /* different types of states; values are useful as masks, as well, for
  377. * routines like check_trailing_context()
  378. */
  379. #define STATE_NORMAL 0x1
  380. #define STATE_TRAILING_CONTEXT 0x2
  381. /* global holding current type of state we're making */
  382. extern int current_state_type;
  383. /* different types of rules */
  384. #define RULE_NORMAL 0
  385. #define RULE_VARIABLE 1
  386. /* true if the input rules include a rule with both variable-length head
  387. * and trailing context, false otherwise
  388. */
  389. extern int variable_trailing_context_rules;
  390. /* variables for protos:
  391. * numtemps - number of templates created
  392. * numprots - number of protos created
  393. * protprev - backlink to a more-recently used proto
  394. * protnext - forward link to a less-recently used proto
  395. * prottbl - base/def table entry for proto
  396. * protcomst - common state of proto
  397. * firstprot - number of the most recently used proto
  398. * lastprot - number of the least recently used proto
  399. * protsave contains the entire state array for protos
  400. */
  401. extern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP];
  402. extern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE];
  403. /* variables for managing equivalence classes:
  404. * numecs - number of equivalence classes
  405. * nextecm - forward link of Equivalence Class members
  406. * ecgroup - class number or backward link of EC members
  407. * nummecs - number of meta-equivalence classes (used to compress
  408. * templates)
  409. * tecfwd - forward link of meta-equivalence classes members
  410. * tecbck - backward link of MEC's
  411. * xlation - maps character codes to their translations, or nil if no %t table
  412. * num_xlations - number of different xlation values
  413. */
  414. /* reserve enough room in the equivalence class arrays so that we
  415. * can use the CSIZE'th element to hold equivalence class information
  416. * for the NUL character. Later we'll move this information into
  417. * the 0th element.
  418. */
  419. extern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs;
  420. /* meta-equivalence classes are indexed starting at 1, so it's possible
  421. * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1
  422. * slots total (since the arrays are 0-based). nextecm[] and ecgroup[]
  423. * don't require the extra position since they're indexed from 1 .. CSIZE - 1.
  424. */
  425. extern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1];
  426. extern int *xlation;
  427. extern int num_xlations;
  428. /* variables for start conditions:
  429. * lastsc - last start condition created
  430. * current_max_scs - current limit on number of start conditions
  431. * scset - set of rules active in start condition
  432. * scbol - set of rules active only at the beginning of line in a s.c.
  433. * scxclu - true if start condition is exclusive
  434. * sceof - true if start condition has EOF rule
  435. * scname - start condition name
  436. * actvsc - stack of active start conditions for the current rule
  437. */
  438. extern int lastsc, current_max_scs, *scset, *scbol, *scxclu, *sceof, *actvsc;
  439. extern char **scname;
  440. /* variables for dfa machine data:
  441. * current_max_dfa_size - current maximum number of NFA states in DFA
  442. * current_max_xpairs - current maximum number of non-template xtion pairs
  443. * current_max_template_xpairs - current maximum number of template pairs
  444. * current_max_dfas - current maximum number DFA states
  445. * lastdfa - last dfa state number created
  446. * nxt - state to enter upon reading character
  447. * chk - check value to see if "nxt" applies
  448. * tnxt - internal nxt table for templates
  449. * base - offset into "nxt" for given state
  450. * def - where to go if "chk" disallows "nxt" entry
  451. * nultrans - NUL transition for each state
  452. * NUL_ec - equivalence class of the NUL character
  453. * tblend - last "nxt/chk" table entry being used
  454. * firstfree - first empty entry in "nxt/chk" table
  455. * dss - nfa state set for each dfa
  456. * dfasiz - size of nfa state set for each dfa
  457. * dfaacc - accepting set for each dfa state (or accepting number, if
  458. * -r is not given)
  459. * accsiz - size of accepting set for each dfa state
  460. * dhash - dfa state hash value
  461. * numas - number of DFA accepting states created; note that this
  462. * is not necessarily the same value as num_rules, which is the analogous
  463. * value for the NFA
  464. * numsnpairs - number of state/nextstate transition pairs
  465. * jambase - position in base/def where the default jam table starts
  466. * jamstate - state number corresponding to "jam" state
  467. * end_of_buffer_state - end-of-buffer dfa state number
  468. */
  469. extern int current_max_dfa_size, current_max_xpairs;
  470. extern int current_max_template_xpairs, current_max_dfas;
  471. extern int lastdfa, lasttemp, *nxt, *chk, *tnxt;
  472. extern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, *dfasiz;
  473. extern union dfaacc_union
  474. {
  475. int *dfaacc_set;
  476. int dfaacc_state;
  477. } *dfaacc;
  478. extern int *accsiz, *dhash, numas;
  479. extern int numsnpairs, jambase, jamstate;
  480. extern int end_of_buffer_state;
  481. /* variables for ccl information:
  482. * lastccl - ccl index of the last created ccl
  483. * current_maxccls - current limit on the maximum number of unique ccl's
  484. * cclmap - maps a ccl index to its set pointer
  485. * ccllen - gives the length of a ccl
  486. * cclng - true for a given ccl if the ccl is negated
  487. * cclreuse - counts how many times a ccl is re-used
  488. * current_max_ccl_tbl_size - current limit on number of characters needed
  489. * to represent the unique ccl's
  490. * ccltbl - holds the characters in each ccl - indexed by cclmap
  491. */
  492. extern int lastccl, current_maxccls, *cclmap, *ccllen, *cclng, cclreuse;
  493. extern int current_max_ccl_tbl_size;
  494. extern Char *ccltbl;
  495. /* variables for miscellaneous information:
  496. * starttime - real-time when we started
  497. * endtime - real-time when we ended
  498. * nmstr - last NAME scanned by the scanner
  499. * sectnum - section number currently being parsed
  500. * nummt - number of empty nxt/chk table entries
  501. * hshcol - number of hash collisions detected by snstods
  502. * dfaeql - number of times a newly created dfa was equal to an old one
  503. * numeps - number of epsilon NFA states created
  504. * eps2 - number of epsilon states which have 2 out-transitions
  505. * num_reallocs - number of times it was necessary to realloc() a group
  506. * of arrays
  507. * tmpuses - number of DFA states that chain to templates
  508. * totnst - total number of NFA states used to make DFA states
  509. * peakpairs - peak number of transition pairs we had to store internally
  510. * numuniq - number of unique transitions
  511. * numdup - number of duplicate transitions
  512. * hshsave - number of hash collisions saved by checking number of states
  513. * num_backtracking - number of DFA states requiring back-tracking
  514. * bol_needed - whether scanner needs beginning-of-line recognition
  515. */
  516. extern char *starttime, *endtime, nmstr[MAXLINE];
  517. extern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs;
  518. extern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave;
  519. extern int num_backtracking, bol_needed;
  520. void *allocate_array(), *reallocate_array();
  521. #define allocate_integer_array(size) \
  522. (int *) allocate_array( size, sizeof( int ) )
  523. #define reallocate_integer_array(array,size) \
  524. (int *) reallocate_array( (void *) array, size, sizeof( int ) )
  525. #define allocate_int_ptr_array(size) \
  526. (int **) allocate_array( size, sizeof( int * ) )
  527. #define allocate_char_ptr_array(size) \
  528. (char **) allocate_array( size, sizeof( char * ) )
  529. #define allocate_dfaacc_union(size) \
  530. (union dfaacc_union *) \
  531. allocate_array( size, sizeof( union dfaacc_union ) )
  532. #define reallocate_int_ptr_array(array,size) \
  533. (int **) reallocate_array( (void *) array, size, sizeof( int * ) )
  534. #define reallocate_char_ptr_array(array,size) \
  535. (char **) reallocate_array( (void *) array, size, sizeof( char * ) )
  536. #define reallocate_dfaacc_union(array, size) \
  537. (union dfaacc_union *) \
  538. reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) )
  539. #define allocate_character_array(size) \
  540. (Char *) allocate_array( size, sizeof( Char ) )
  541. #define reallocate_character_array(array,size) \
  542. (Char *) reallocate_array( (void *) array, size, sizeof( Char ) )
  543. /* used to communicate between scanner and parser. The type should really
  544. * be YYSTYPE, but we can't easily get our hands on it.
  545. */
  546. extern int yylval;
  547. /* external functions that are cross-referenced among the flex source files */
  548. /* from file ccl.c */
  549. extern void ccladd PROTO((int, int)); /* Add a single character to a ccl */
  550. extern int cclinit PROTO(()); /* make an empty ccl */
  551. extern void cclnegate PROTO((int)); /* negate a ccl */
  552. /* list the members of a set of characters in CCL form */
  553. extern void list_character_set PROTO((FILE*, int[]));
  554. /* from file dfa.c */
  555. /* increase the maximum number of dfas */
  556. extern void increase_max_dfas PROTO(());
  557. extern void ntod PROTO(()); /* convert a ndfa to a dfa */
  558. /* from file ecs.c */
  559. /* convert character classes to set of equivalence classes */
  560. extern void ccl2ecl PROTO(());
  561. /* associate equivalence class numbers with class members */
  562. extern int cre8ecs PROTO((int[], int[], int));
  563. /* associate equivalence class numbers using %t table */
  564. extern int ecs_from_xlation PROTO((int[]));
  565. /* update equivalence classes based on character class transitions */
  566. extern void mkeccl PROTO((Char[], int, int[], int[], int, int));
  567. /* create equivalence class for single character */
  568. extern void mkechar PROTO((int, int[], int[]));
  569. /* from file gen.c */
  570. extern void make_tables PROTO(()); /* generate transition tables */
  571. /* from file main.c */
  572. extern void flexend PROTO((int));
  573. /* from file misc.c */
  574. /* write out the actions from the temporary file to lex.yy.c */
  575. extern void action_out PROTO(());
  576. /* true if a string is all lower case */
  577. extern int all_lower PROTO((register Char *));
  578. /* true if a string is all upper case */
  579. extern int all_upper PROTO((register Char *));
  580. /* bubble sort an integer array */
  581. extern void bubble PROTO((int [], int));
  582. /* shell sort a character array */
  583. extern void cshell PROTO((Char [], int, int));
  584. extern void dataend PROTO(()); /* finish up a block of data declarations */
  585. /* report an error message and terminate */
  586. extern void flexerror PROTO((char[]));
  587. /* report a fatal error message and terminate */
  588. extern void flexfatal PROTO((char[]));
  589. /* report an error message formatted with one integer argument */
  590. extern void lerrif PROTO((char[], int));
  591. /* report an error message formatted with one string argument */
  592. extern void lerrsf PROTO((char[], char[]));
  593. /* spit out a "# line" statement */
  594. extern void line_directive_out PROTO((FILE*));
  595. /* generate a data statment for a two-dimensional array */
  596. extern void mk2data PROTO((int));
  597. extern void mkdata PROTO((int)); /* generate a data statement */
  598. /* return the integer represented by a string of digits */
  599. extern int myctoi PROTO((Char []));
  600. /* write out one section of the skeleton file */
  601. extern void skelout PROTO(());
  602. /* output a yy_trans_info structure */
  603. extern void transition_struct_out PROTO((int, int));
  604. /* from file nfa.c */
  605. /* add an accepting state to a machine */
  606. extern void add_accept PROTO((int, int));
  607. /* make a given number of copies of a singleton machine */
  608. extern int copysingl PROTO((int, int));
  609. /* debugging routine to write out an nfa */
  610. extern void dumpnfa PROTO((int));
  611. /* finish up the processing for a rule */
  612. extern void finish_rule PROTO((int, int, int, int));
  613. /* connect two machines together */
  614. extern int link_machines PROTO((int, int));
  615. /* mark each "beginning" state in a machine as being a "normal" (i.e.,
  616. * not trailing context associated) state
  617. */
  618. extern void mark_beginning_as_normal PROTO((register int));
  619. /* make a machine that branches to two machines */
  620. extern int mkbranch PROTO((int, int));
  621. extern int mkclos PROTO((int)); /* convert a machine into a closure */
  622. extern int mkopt PROTO((int)); /* make a machine optional */
  623. /* make a machine that matches either one of two machines */
  624. extern int mkor PROTO((int, int));
  625. /* convert a machine into a positive closure */
  626. extern int mkposcl PROTO((int));
  627. extern int mkrep PROTO((int, int, int)); /* make a replicated machine */
  628. /* create a state with a transition on a given symbol */
  629. extern int mkstate PROTO((int));
  630. extern void new_rule PROTO(()); /* initialize for a new rule */
  631. /* from file parse.y */
  632. /* write out a message formatted with one string, pinpointing its location */
  633. extern void format_pinpoint_message PROTO((char[], char[]));
  634. /* write out a message, pinpointing its location */
  635. extern void pinpoint_message PROTO((char[]));
  636. extern void synerr PROTO((char [])); /* report a syntax error */
  637. extern int yyparse PROTO(()); /* the YACC parser */
  638. /* from file scan.l */
  639. extern int flexscan PROTO(()); /* the Flex-generated scanner for flex */
  640. /* open the given file (if NULL, stdin) for scanning */
  641. extern void set_input_file PROTO((char*));
  642. extern int yywrap PROTO(()); /* wrapup a file in the lexical analyzer */
  643. /* from file sym.c */
  644. /* save the text of a character class */
  645. extern void cclinstal PROTO ((Char [], int));
  646. /* lookup the number associated with character class */
  647. extern int ccllookup PROTO((Char []));
  648. extern void ndinstal PROTO((char[], Char[])); /* install a name definition */
  649. extern void scinstal PROTO((char[], int)); /* make a start condition */
  650. /* lookup the number associated with a start condition */
  651. extern int sclookup PROTO((char[]));
  652. /* from file tblcmp.c */
  653. /* build table entries for dfa state */
  654. extern void bldtbl PROTO((int[], int, int, int, int));
  655. extern void cmptmps PROTO(()); /* compress template table entries */
  656. extern void inittbl PROTO(()); /* initialize transition tables */
  657. extern void mkdeftbl PROTO(()); /* make the default, "jam" table entries */
  658. /* create table entries for a state (or state fragment) which has
  659. * only one out-transition */
  660. extern void mk1tbl PROTO((int, int, int, int));
  661. /* place a state into full speed transition table */
  662. extern void place_state PROTO((int*, int, int));
  663. /* save states with only one out-transition to be processed later */
  664. extern void stack1 PROTO((int, int, int, int));
  665. /* from file yylex.c */
  666. extern int yylex PROTO(());
  667. /* The Unix kernel calls used here */
  668. extern int read PROTO((int, char*, int));
  669. extern int unlink PROTO((char*));
  670. extern int write PROTO((int, char*, int));