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