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