PageRenderTime 46ms CodeModel.GetById 11ms app.highlight 27ms RepoModel.GetById 1ms app.codeStats 1ms

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