flexdef.h 35 KB

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