1228072Sbapt 2228072Sbapt/* flexdef - definitions file for flex */ 3228072Sbapt 4228072Sbapt/* Copyright (c) 1990 The Regents of the University of California. */ 5228072Sbapt/* All rights reserved. */ 6228072Sbapt 7228072Sbapt/* This code is derived from software contributed to Berkeley by */ 8228072Sbapt/* Vern Paxson. */ 9228072Sbapt 10228072Sbapt/* The United States Government has rights in this work pursuant */ 11228072Sbapt/* to contract no. DE-AC03-76SF00098 between the United States */ 12228072Sbapt/* Department of Energy and the University of California. */ 13228072Sbapt 14228072Sbapt/* This file is part of flex. */ 15228072Sbapt 16228072Sbapt/* Redistribution and use in source and binary forms, with or without */ 17228072Sbapt/* modification, are permitted provided that the following conditions */ 18228072Sbapt/* are met: */ 19228072Sbapt 20228072Sbapt/* 1. Redistributions of source code must retain the above copyright */ 21228072Sbapt/* notice, this list of conditions and the following disclaimer. */ 22228072Sbapt/* 2. Redistributions in binary form must reproduce the above copyright */ 23228072Sbapt/* notice, this list of conditions and the following disclaimer in the */ 24228072Sbapt/* documentation and/or other materials provided with the distribution. */ 25228072Sbapt 26228072Sbapt/* Neither the name of the University nor the names of its contributors */ 27228072Sbapt/* may be used to endorse or promote products derived from this software */ 28228072Sbapt/* without specific prior written permission. */ 29228072Sbapt 30228072Sbapt/* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR */ 31228072Sbapt/* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED */ 32228072Sbapt/* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR */ 33228072Sbapt/* PURPOSE. */ 34228072Sbapt 35228072Sbapt#ifndef FLEXDEF_H 36228072Sbapt#define FLEXDEF_H 1 37228072Sbapt 38228072Sbapt#ifdef HAVE_CONFIG_H 39228072Sbapt#include <config.h> 40228072Sbapt#endif 41228072Sbapt 42228072Sbapt/* AIX requires this to be the first thing in the file. */ 43228072Sbapt#ifndef __GNUC__ 44228072Sbapt# if HAVE_ALLOCA_H 45228072Sbapt# include <alloca.h> 46228072Sbapt# else 47228072Sbapt# ifdef _AIX 48228072Sbapt #pragma alloca 49228072Sbapt# else 50228072Sbapt# ifndef alloca /* predefined by HP cc +Olibcalls */ 51228072Sbaptchar *alloca (); 52228072Sbapt# endif 53228072Sbapt# endif 54228072Sbapt# endif 55228072Sbapt#endif 56228072Sbapt 57228072Sbapt#ifdef STDC_HEADERS 58228072Sbapt#include <stdio.h> 59228072Sbapt#include <stdlib.h> 60228072Sbapt#include <stdarg.h> 61228072Sbapt#include <setjmp.h> 62228072Sbapt#include <ctype.h> 63228072Sbapt#include <string.h> 64228072Sbapt#endif 65228072Sbapt#ifdef HAVE_ASSERT_H 66228072Sbapt#include <assert.h> 67228072Sbapt#else 68228072Sbapt#define assert(Pred) 69228072Sbapt#endif 70228072Sbapt 71228072Sbapt#ifdef HAVE_LIMITS_H 72228072Sbapt#include <limits.h> 73228072Sbapt#endif 74228072Sbapt#ifdef HAVE_UNISTD_H 75228072Sbapt#include <unistd.h> 76228072Sbapt#endif 77228072Sbapt#ifdef HAVE_NETINET_IN_H 78228072Sbapt#include <netinet/in.h> 79228072Sbapt#endif 80228072Sbapt#ifdef HAVE_SYS_PARAMS_H 81228072Sbapt#include <sys/params.h> 82228072Sbapt#endif 83228072Sbapt#ifdef HAVE_SYS_WAIT_H 84228072Sbapt#include <sys/wait.h> 85228072Sbapt#endif 86228072Sbapt#ifdef HAVE_STDBOOL_H 87228072Sbapt#include <stdbool.h> 88228072Sbapt#else 89228072Sbapt#define bool int 90228072Sbapt#define true 1 91228072Sbapt#define false 0 92228072Sbapt#endif 93250125Sjkim#ifdef HAVE_REGEX_H 94228072Sbapt#include <regex.h> 95250125Sjkim#endif 96228072Sbapt#include "flexint.h" 97228072Sbapt 98228072Sbapt/* We use gettext. So, when we write strings which should be translated, we mark them with _() */ 99228072Sbapt#ifdef ENABLE_NLS 100228072Sbapt#ifdef HAVE_LOCALE_H 101228072Sbapt#include <locale.h> 102228072Sbapt#endif /* HAVE_LOCALE_H */ 103228072Sbapt#include "gettext.h" 104228072Sbapt#define _(String) gettext (String) 105228072Sbapt#else 106228072Sbapt#define _(STRING) STRING 107228072Sbapt#endif /* ENABLE_NLS */ 108228072Sbapt 109228072Sbapt/* Always be prepared to generate an 8-bit scanner. */ 110228072Sbapt#define CSIZE 256 111228072Sbapt#define Char unsigned char 112228072Sbapt 113228072Sbapt/* Size of input alphabet - should be size of ASCII set. */ 114228072Sbapt#ifndef DEFAULT_CSIZE 115228072Sbapt#define DEFAULT_CSIZE 128 116228072Sbapt#endif 117228072Sbapt 118228072Sbapt#ifndef PROTO 119228072Sbapt#if defined(__STDC__) 120228072Sbapt#define PROTO(proto) proto 121228072Sbapt#else 122228072Sbapt#define PROTO(proto) () 123228072Sbapt#endif 124228072Sbapt#endif 125228072Sbapt 126228072Sbapt#ifdef VMS 127228072Sbapt#ifndef __VMS_POSIX 128228072Sbapt#define unlink remove 129228072Sbapt#define SHORT_FILE_NAMES 130228072Sbapt#endif 131228072Sbapt#endif 132228072Sbapt 133228072Sbapt#ifdef MS_DOS 134228072Sbapt#define SHORT_FILE_NAMES 135228072Sbapt#endif 136228072Sbapt 137228072Sbapt 138228072Sbapt/* Maximum line length we'll have to deal with. */ 139228072Sbapt#define MAXLINE 2048 140228072Sbapt 141228072Sbapt#ifndef MIN 142228072Sbapt#define MIN(x,y) ((x) < (y) ? (x) : (y)) 143228072Sbapt#endif 144228072Sbapt#ifndef MAX 145228072Sbapt#define MAX(x,y) ((x) > (y) ? (x) : (y)) 146228072Sbapt#endif 147228072Sbapt#ifndef ABS 148228072Sbapt#define ABS(x) ((x) < 0 ? -(x) : (x)) 149228072Sbapt#endif 150228072Sbapt 151228072Sbapt 152228072Sbapt/* ANSI C does not guarantee that isascii() is defined */ 153228072Sbapt#ifndef isascii 154228072Sbapt#define isascii(c) ((c) <= 0177) 155228072Sbapt#endif 156228072Sbapt 157228072Sbapt#define unspecified -1 158228072Sbapt 159228072Sbapt/* Special chk[] values marking the slots taking by end-of-buffer and action 160228072Sbapt * numbers. 161228072Sbapt */ 162228072Sbapt#define EOB_POSITION -1 163228072Sbapt#define ACTION_POSITION -2 164228072Sbapt 165228072Sbapt/* Number of data items per line for -f output. */ 166228072Sbapt#define NUMDATAITEMS 10 167228072Sbapt 168228072Sbapt/* Number of lines of data in -f output before inserting a blank line for 169228072Sbapt * readability. 170228072Sbapt */ 171228072Sbapt#define NUMDATALINES 10 172228072Sbapt 173250876Sjkim/* Number of characters to print a line number, i.e., 1 + log10(INT_MAX) */ 174250876Sjkim#define NUMCHARLINES 10 175250876Sjkim 176228072Sbapt/* transition_struct_out() definitions. */ 177228072Sbapt#define TRANS_STRUCT_PRINT_LENGTH 14 178228072Sbapt 179228072Sbapt/* Returns true if an nfa state has an epsilon out-transition slot 180228072Sbapt * that can be used. This definition is currently not used. 181228072Sbapt */ 182228072Sbapt#define FREE_EPSILON(state) \ 183228072Sbapt (transchar[state] == SYM_EPSILON && \ 184228072Sbapt trans2[state] == NO_TRANSITION && \ 185228072Sbapt finalst[state] != state) 186228072Sbapt 187228072Sbapt/* Returns true if an nfa state has an epsilon out-transition character 188228072Sbapt * and both slots are free 189228072Sbapt */ 190228072Sbapt#define SUPER_FREE_EPSILON(state) \ 191228072Sbapt (transchar[state] == SYM_EPSILON && \ 192228072Sbapt trans1[state] == NO_TRANSITION) \ 193228072Sbapt 194228072Sbapt/* Maximum number of NFA states that can comprise a DFA state. It's real 195228072Sbapt * big because if there's a lot of rules, the initial state will have a 196228072Sbapt * huge epsilon closure. 197228072Sbapt */ 198228072Sbapt#define INITIAL_MAX_DFA_SIZE 750 199228072Sbapt#define MAX_DFA_SIZE_INCREMENT 750 200228072Sbapt 201228072Sbapt 202228072Sbapt/* A note on the following masks. They are used to mark accepting numbers 203228072Sbapt * as being special. As such, they implicitly limit the number of accepting 204228072Sbapt * numbers (i.e., rules) because if there are too many rules the rule numbers 205228072Sbapt * will overload the mask bits. Fortunately, this limit is \large/ (0x2000 == 206228072Sbapt * 8192) so unlikely to actually cause any problems. A check is made in 207228072Sbapt * new_rule() to ensure that this limit is not reached. 208228072Sbapt */ 209228072Sbapt 210228072Sbapt/* Mask to mark a trailing context accepting number. */ 211228072Sbapt#define YY_TRAILING_MASK 0x2000 212228072Sbapt 213228072Sbapt/* Mask to mark the accepting number of the "head" of a trailing context 214228072Sbapt * rule. 215228072Sbapt */ 216228072Sbapt#define YY_TRAILING_HEAD_MASK 0x4000 217228072Sbapt 218228072Sbapt/* Maximum number of rules, as outlined in the above note. */ 219228072Sbapt#define MAX_RULE (YY_TRAILING_MASK - 1) 220228072Sbapt 221228072Sbapt 222228072Sbapt/* NIL must be 0. If not, its special meaning when making equivalence classes 223228072Sbapt * (it marks the representative of a given e.c.) will be unidentifiable. 224228072Sbapt */ 225228072Sbapt#define NIL 0 226228072Sbapt 227228072Sbapt#define JAM -1 /* to mark a missing DFA transition */ 228228072Sbapt#define NO_TRANSITION NIL 229228072Sbapt#define UNIQUE -1 /* marks a symbol as an e.c. representative */ 230228072Sbapt#define INFINITE_REPEAT -1 /* for x{5,} constructions */ 231228072Sbapt 232228072Sbapt#define INITIAL_MAX_CCLS 100 /* max number of unique character classes */ 233228072Sbapt#define MAX_CCLS_INCREMENT 100 234228072Sbapt 235228072Sbapt/* Size of table holding members of character classes. */ 236228072Sbapt#define INITIAL_MAX_CCL_TBL_SIZE 500 237228072Sbapt#define MAX_CCL_TBL_SIZE_INCREMENT 250 238228072Sbapt 239228072Sbapt#define INITIAL_MAX_RULES 100 /* default maximum number of rules */ 240228072Sbapt#define MAX_RULES_INCREMENT 100 241228072Sbapt 242228072Sbapt#define INITIAL_MNS 2000 /* default maximum number of nfa states */ 243228072Sbapt#define MNS_INCREMENT 1000 /* amount to bump above by if it's not enough */ 244228072Sbapt 245228072Sbapt#define INITIAL_MAX_DFAS 1000 /* default maximum number of dfa states */ 246228072Sbapt#define MAX_DFAS_INCREMENT 1000 247228072Sbapt 248228072Sbapt#define JAMSTATE -32766 /* marks a reference to the state that always jams */ 249228072Sbapt 250228072Sbapt/* Maximum number of NFA states. */ 251228072Sbapt#define MAXIMUM_MNS 31999 252228072Sbapt#define MAXIMUM_MNS_LONG 1999999999 253228072Sbapt 254228072Sbapt/* Enough so that if it's subtracted from an NFA state number, the result 255228072Sbapt * is guaranteed to be negative. 256228072Sbapt */ 257228072Sbapt#define MARKER_DIFFERENCE (maximum_mns+2) 258228072Sbapt 259228072Sbapt/* Maximum number of nxt/chk pairs for non-templates. */ 260228072Sbapt#define INITIAL_MAX_XPAIRS 2000 261228072Sbapt#define MAX_XPAIRS_INCREMENT 2000 262228072Sbapt 263228072Sbapt/* Maximum number of nxt/chk pairs needed for templates. */ 264228072Sbapt#define INITIAL_MAX_TEMPLATE_XPAIRS 2500 265228072Sbapt#define MAX_TEMPLATE_XPAIRS_INCREMENT 2500 266228072Sbapt 267228072Sbapt#define SYM_EPSILON (CSIZE + 1) /* to mark transitions on the symbol epsilon */ 268228072Sbapt 269228072Sbapt#define INITIAL_MAX_SCS 40 /* maximum number of start conditions */ 270228072Sbapt#define MAX_SCS_INCREMENT 40 /* amount to bump by if it's not enough */ 271228072Sbapt 272228072Sbapt#define ONE_STACK_SIZE 500 /* stack of states with only one out-transition */ 273228072Sbapt#define SAME_TRANS -1 /* transition is the same as "default" entry for state */ 274228072Sbapt 275228072Sbapt/* The following percentages are used to tune table compression: 276228072Sbapt 277228072Sbapt * The percentage the number of out-transitions a state must be of the 278228072Sbapt * number of equivalence classes in order to be considered for table 279228072Sbapt * compaction by using protos. 280228072Sbapt */ 281228072Sbapt#define PROTO_SIZE_PERCENTAGE 15 282228072Sbapt 283228072Sbapt/* The percentage the number of homogeneous out-transitions of a state 284228072Sbapt * must be of the number of total out-transitions of the state in order 285228072Sbapt * that the state's transition table is first compared with a potential 286228072Sbapt * template of the most common out-transition instead of with the first 287228072Sbapt * proto in the proto queue. 288228072Sbapt */ 289228072Sbapt#define CHECK_COM_PERCENTAGE 50 290228072Sbapt 291228072Sbapt/* The percentage the number of differences between a state's transition 292228072Sbapt * table and the proto it was first compared with must be of the total 293228072Sbapt * number of out-transitions of the state in order to keep the first 294228072Sbapt * proto as a good match and not search any further. 295228072Sbapt */ 296228072Sbapt#define FIRST_MATCH_DIFF_PERCENTAGE 10 297228072Sbapt 298228072Sbapt/* The percentage the number of differences between a state's transition 299228072Sbapt * table and the most similar proto must be of the state's total number 300228072Sbapt * of out-transitions to use the proto as an acceptable close match. 301228072Sbapt */ 302228072Sbapt#define ACCEPTABLE_DIFF_PERCENTAGE 50 303228072Sbapt 304228072Sbapt/* The percentage the number of homogeneous out-transitions of a state 305228072Sbapt * must be of the number of total out-transitions of the state in order 306228072Sbapt * to consider making a template from the state. 307228072Sbapt */ 308228072Sbapt#define TEMPLATE_SAME_PERCENTAGE 60 309228072Sbapt 310228072Sbapt/* The percentage the number of differences between a state's transition 311228072Sbapt * table and the most similar proto must be of the state's total number 312228072Sbapt * of out-transitions to create a new proto from the state. 313228072Sbapt */ 314228072Sbapt#define NEW_PROTO_DIFF_PERCENTAGE 20 315228072Sbapt 316228072Sbapt/* The percentage the total number of out-transitions of a state must be 317228072Sbapt * of the number of equivalence classes in order to consider trying to 318228072Sbapt * fit the transition table into "holes" inside the nxt/chk table. 319228072Sbapt */ 320228072Sbapt#define INTERIOR_FIT_PERCENTAGE 15 321228072Sbapt 322228072Sbapt/* Size of region set aside to cache the complete transition table of 323228072Sbapt * protos on the proto queue to enable quick comparisons. 324228072Sbapt */ 325228072Sbapt#define PROT_SAVE_SIZE 2000 326228072Sbapt 327228072Sbapt#define MSP 50 /* maximum number of saved protos (protos on the proto queue) */ 328228072Sbapt 329228072Sbapt/* Maximum number of out-transitions a state can have that we'll rummage 330228072Sbapt * around through the interior of the internal fast table looking for a 331228072Sbapt * spot for it. 332228072Sbapt */ 333228072Sbapt#define MAX_XTIONS_FULL_INTERIOR_FIT 4 334228072Sbapt 335228072Sbapt/* Maximum number of rules which will be reported as being associated 336228072Sbapt * with a DFA state. 337228072Sbapt */ 338228072Sbapt#define MAX_ASSOC_RULES 100 339228072Sbapt 340228072Sbapt/* Number that, if used to subscript an array, has a good chance of producing 341228072Sbapt * an error; should be small enough to fit into a short. 342228072Sbapt */ 343228072Sbapt#define BAD_SUBSCRIPT -32767 344228072Sbapt 345228072Sbapt/* Absolute value of largest number that can be stored in a short, with a 346228072Sbapt * bit of slop thrown in for general paranoia. 347228072Sbapt */ 348228072Sbapt#define MAX_SHORT 32700 349228072Sbapt 350228072Sbapt 351228072Sbapt/* Declarations for global variables. */ 352228072Sbapt 353228072Sbapt 354228072Sbapt/* Variables for flags: 355228072Sbapt * printstats - if true (-v), dump statistics 356228072Sbapt * syntaxerror - true if a syntax error has been found 357228072Sbapt * eofseen - true if we've seen an eof in the input file 358228072Sbapt * ddebug - if true (-d), make a "debug" scanner 359228072Sbapt * trace - if true (-T), trace processing 360228072Sbapt * nowarn - if true (-w), do not generate warnings 361228072Sbapt * spprdflt - if true (-s), suppress the default rule 362228072Sbapt * interactive - if true (-I), generate an interactive scanner 363228072Sbapt * lex_compat - if true (-l), maximize compatibility with AT&T lex 364228072Sbapt * posix_compat - if true (-X), maximize compatibility with POSIX lex 365228072Sbapt * do_yylineno - if true, generate code to maintain yylineno 366228072Sbapt * useecs - if true (-Ce flag), use equivalence classes 367228072Sbapt * fulltbl - if true (-Cf flag), don't compress the DFA state table 368228072Sbapt * usemecs - if true (-Cm flag), use meta-equivalence classes 369228072Sbapt * fullspd - if true (-F flag), use Jacobson method of table representation 370228072Sbapt * gen_line_dirs - if true (i.e., no -L flag), generate #line directives 371228072Sbapt * performance_report - if > 0 (i.e., -p flag), generate a report relating 372228072Sbapt * to scanner performance; if > 1 (-p -p), report on minor performance 373228072Sbapt * problems, too 374228072Sbapt * backing_up_report - if true (i.e., -b flag), generate "lex.backup" file 375228072Sbapt * listing backing-up states 376228072Sbapt * C_plus_plus - if true (i.e., -+ flag), generate a C++ scanner class; 377228072Sbapt * otherwise, a standard C scanner 378228072Sbapt * reentrant - if true (-R), generate a reentrant C scanner. 379228072Sbapt * bison_bridge_lval - if true (--bison-bridge), bison pure calling convention. 380228072Sbapt * bison_bridge_lloc - if true (--bison-locations), bison yylloc. 381228072Sbapt * long_align - if true (-Ca flag), favor long-word alignment. 382228072Sbapt * use_read - if true (-f, -F, or -Cr) then use read() for scanner input; 383228072Sbapt * otherwise, use fread(). 384228072Sbapt * yytext_is_array - if true (i.e., %array directive), then declare 385250874Sjkim * yytext as an array instead of a character pointer. Nice and inefficient. 386228072Sbapt * do_yywrap - do yywrap() processing on EOF. If false, EOF treated as 387228072Sbapt * "no more files". 388228072Sbapt * csize - size of character set for the scanner we're generating; 389228072Sbapt * 128 for 7-bit chars and 256 for 8-bit 390228072Sbapt * yymore_used - if true, yymore() is used in input rules 391228072Sbapt * reject - if true, generate back-up tables for REJECT macro 392228072Sbapt * real_reject - if true, scanner really uses REJECT (as opposed to just 393228072Sbapt * having "reject" set for variable trailing context) 394228072Sbapt * continued_action - true if this rule's action is to "fall through" to 395228072Sbapt * the next rule's action (i.e., the '|' action) 396228072Sbapt * in_rule - true if we're inside an individual rule, false if not. 397228072Sbapt * yymore_really_used - whether to treat yymore() as really used, regardless 398228072Sbapt * of what we think based on references to it in the user's actions. 399228072Sbapt * reject_really_used - same for REJECT 400228072Sbapt */ 401228072Sbapt 402228072Sbaptextern int printstats, syntaxerror, eofseen, ddebug, trace, nowarn, 403228072Sbapt spprdflt; 404228072Sbaptextern int interactive, lex_compat, posix_compat, do_yylineno; 405228072Sbaptextern int useecs, fulltbl, usemecs, fullspd; 406228072Sbaptextern int gen_line_dirs, performance_report, backing_up_report; 407228072Sbaptextern int reentrant, bison_bridge_lval, bison_bridge_lloc; 408228072Sbaptextern bool ansi_func_defs, ansi_func_protos; 409228072Sbaptextern int C_plus_plus, long_align, use_read, yytext_is_array, do_yywrap; 410228072Sbaptextern int csize; 411228072Sbaptextern int yymore_used, reject, real_reject, continued_action, in_rule; 412228072Sbapt 413228072Sbaptextern int yymore_really_used, reject_really_used; 414228072Sbapt 415228072Sbapt 416228072Sbapt/* Variables used in the flex input routines: 417228072Sbapt * datapos - characters on current output line 418228072Sbapt * dataline - number of contiguous lines of data in current data 419228072Sbapt * statement. Used to generate readable -f output 420228072Sbapt * linenum - current input line number 421228072Sbapt * skelfile - the skeleton file 422228072Sbapt * skel - compiled-in skeleton array 423228072Sbapt * skel_ind - index into "skel" array, if skelfile is nil 424228072Sbapt * yyin - input file 425228072Sbapt * backing_up_file - file to summarize backing-up states to 426228072Sbapt * infilename - name of input file 427228072Sbapt * outfilename - name of output file 428228072Sbapt * headerfilename - name of the .h file to generate 429228072Sbapt * did_outfilename - whether outfilename was explicitly set 430228072Sbapt * prefix - the prefix used for externally visible names ("yy" by default) 431228072Sbapt * yyclass - yyFlexLexer subclass to use for YY_DECL 432228072Sbapt * do_stdinit - whether to initialize yyin/yyout to stdin/stdout 433228072Sbapt * use_stdout - the -t flag 434228072Sbapt * input_files - array holding names of input files 435228072Sbapt * num_input_files - size of input_files array 436228072Sbapt * program_name - name with which program was invoked 437228072Sbapt * 438228072Sbapt * action_array - array to hold the rule actions 439228072Sbapt * action_size - size of action_array 440228072Sbapt * defs1_offset - index where the user's section 1 definitions start 441228072Sbapt * in action_array 442228072Sbapt * prolog_offset - index where the prolog starts in action_array 443228072Sbapt * action_offset - index where the non-prolog starts in action_array 444228072Sbapt * action_index - index where the next action should go, with respect 445228072Sbapt * to "action_array" 446228072Sbapt */ 447228072Sbapt 448250125Sjkimextern int datapos, dataline, linenum; 449228072Sbaptextern FILE *skelfile, *yyin, *backing_up_file; 450228072Sbaptextern const char *skel[]; 451228072Sbaptextern int skel_ind; 452228072Sbaptextern char *infilename, *outfilename, *headerfilename; 453228072Sbaptextern int did_outfilename; 454228072Sbaptextern char *prefix, *yyclass, *extra_type; 455228072Sbaptextern int do_stdinit, use_stdout; 456228072Sbaptextern char **input_files; 457228072Sbaptextern int num_input_files; 458228072Sbaptextern char *program_name; 459228072Sbapt 460228072Sbaptextern char *action_array; 461228072Sbaptextern int action_size; 462228072Sbaptextern int defs1_offset, prolog_offset, action_offset, action_index; 463228072Sbapt 464228072Sbapt 465228072Sbapt/* Variables for stack of states having only one out-transition: 466228072Sbapt * onestate - state number 467228072Sbapt * onesym - transition symbol 468228072Sbapt * onenext - target state 469228072Sbapt * onedef - default base entry 470228072Sbapt * onesp - stack pointer 471228072Sbapt */ 472228072Sbapt 473228072Sbaptextern int onestate[ONE_STACK_SIZE], onesym[ONE_STACK_SIZE]; 474228072Sbaptextern int onenext[ONE_STACK_SIZE], onedef[ONE_STACK_SIZE], onesp; 475228072Sbapt 476228072Sbapt 477228072Sbapt/* Variables for nfa machine data: 478228072Sbapt * maximum_mns - maximal number of NFA states supported by tables 479228072Sbapt * current_mns - current maximum on number of NFA states 480228072Sbapt * num_rules - number of the last accepting state; also is number of 481228072Sbapt * rules created so far 482228072Sbapt * num_eof_rules - number of <<EOF>> rules 483228072Sbapt * default_rule - number of the default rule 484228072Sbapt * current_max_rules - current maximum number of rules 485228072Sbapt * lastnfa - last nfa state number created 486228072Sbapt * firstst - physically the first state of a fragment 487228072Sbapt * lastst - last physical state of fragment 488228072Sbapt * finalst - last logical state of fragment 489228072Sbapt * transchar - transition character 490228072Sbapt * trans1 - transition state 491228072Sbapt * trans2 - 2nd transition state for epsilons 492228072Sbapt * accptnum - accepting number 493228072Sbapt * assoc_rule - rule associated with this NFA state (or 0 if none) 494228072Sbapt * state_type - a STATE_xxx type identifying whether the state is part 495228072Sbapt * of a normal rule, the leading state in a trailing context 496228072Sbapt * rule (i.e., the state which marks the transition from 497228072Sbapt * recognizing the text-to-be-matched to the beginning of 498228072Sbapt * the trailing context), or a subsequent state in a trailing 499228072Sbapt * context rule 500228072Sbapt * rule_type - a RULE_xxx type identifying whether this a ho-hum 501228072Sbapt * normal rule or one which has variable head & trailing 502228072Sbapt * context 503228072Sbapt * rule_linenum - line number associated with rule 504228072Sbapt * rule_useful - true if we've determined that the rule can be matched 505228072Sbapt * rule_has_nl - true if rule could possibly match a newline 506228072Sbapt * ccl_has_nl - true if current ccl could match a newline 507228072Sbapt * nlch - default eol char 508228072Sbapt */ 509228072Sbapt 510228072Sbaptextern int maximum_mns, current_mns, current_max_rules; 511228072Sbaptextern int num_rules, num_eof_rules, default_rule, lastnfa; 512228072Sbaptextern int *firstst, *lastst, *finalst, *transchar, *trans1, *trans2; 513228072Sbaptextern int *accptnum, *assoc_rule, *state_type; 514228072Sbaptextern int *rule_type, *rule_linenum, *rule_useful; 515228072Sbaptextern bool *rule_has_nl, *ccl_has_nl; 516228072Sbaptextern int nlch; 517228072Sbapt 518228072Sbapt/* Different types of states; values are useful as masks, as well, for 519228072Sbapt * routines like check_trailing_context(). 520228072Sbapt */ 521228072Sbapt#define STATE_NORMAL 0x1 522228072Sbapt#define STATE_TRAILING_CONTEXT 0x2 523228072Sbapt 524228072Sbapt/* Global holding current type of state we're making. */ 525228072Sbapt 526228072Sbaptextern int current_state_type; 527228072Sbapt 528228072Sbapt/* Different types of rules. */ 529228072Sbapt#define RULE_NORMAL 0 530228072Sbapt#define RULE_VARIABLE 1 531228072Sbapt 532228072Sbapt/* True if the input rules include a rule with both variable-length head 533228072Sbapt * and trailing context, false otherwise. 534228072Sbapt */ 535228072Sbaptextern int variable_trailing_context_rules; 536228072Sbapt 537228072Sbapt 538228072Sbapt/* Variables for protos: 539228072Sbapt * numtemps - number of templates created 540228072Sbapt * numprots - number of protos created 541228072Sbapt * protprev - backlink to a more-recently used proto 542228072Sbapt * protnext - forward link to a less-recently used proto 543228072Sbapt * prottbl - base/def table entry for proto 544228072Sbapt * protcomst - common state of proto 545228072Sbapt * firstprot - number of the most recently used proto 546228072Sbapt * lastprot - number of the least recently used proto 547228072Sbapt * protsave contains the entire state array for protos 548228072Sbapt */ 549228072Sbapt 550228072Sbaptextern int numtemps, numprots, protprev[MSP], protnext[MSP], prottbl[MSP]; 551228072Sbaptextern int protcomst[MSP], firstprot, lastprot, protsave[PROT_SAVE_SIZE]; 552228072Sbapt 553228072Sbapt 554228072Sbapt/* Variables for managing equivalence classes: 555228072Sbapt * numecs - number of equivalence classes 556228072Sbapt * nextecm - forward link of Equivalence Class members 557228072Sbapt * ecgroup - class number or backward link of EC members 558228072Sbapt * nummecs - number of meta-equivalence classes (used to compress 559228072Sbapt * templates) 560228072Sbapt * tecfwd - forward link of meta-equivalence classes members 561228072Sbapt * tecbck - backward link of MEC's 562228072Sbapt */ 563228072Sbapt 564228072Sbapt/* Reserve enough room in the equivalence class arrays so that we 565228072Sbapt * can use the CSIZE'th element to hold equivalence class information 566228072Sbapt * for the NUL character. Later we'll move this information into 567228072Sbapt * the 0th element. 568228072Sbapt */ 569228072Sbaptextern int numecs, nextecm[CSIZE + 1], ecgroup[CSIZE + 1], nummecs; 570228072Sbapt 571228072Sbapt/* Meta-equivalence classes are indexed starting at 1, so it's possible 572228072Sbapt * that they will require positions from 1 .. CSIZE, i.e., CSIZE + 1 573228072Sbapt * slots total (since the arrays are 0-based). nextecm[] and ecgroup[] 574228072Sbapt * don't require the extra position since they're indexed from 1 .. CSIZE - 1. 575228072Sbapt */ 576228072Sbaptextern int tecfwd[CSIZE + 1], tecbck[CSIZE + 1]; 577228072Sbapt 578228072Sbapt 579228072Sbapt/* Variables for start conditions: 580228072Sbapt * lastsc - last start condition created 581228072Sbapt * current_max_scs - current limit on number of start conditions 582228072Sbapt * scset - set of rules active in start condition 583228072Sbapt * scbol - set of rules active only at the beginning of line in a s.c. 584228072Sbapt * scxclu - true if start condition is exclusive 585228072Sbapt * sceof - true if start condition has EOF rule 586228072Sbapt * scname - start condition name 587228072Sbapt */ 588228072Sbapt 589228072Sbaptextern int lastsc, *scset, *scbol, *scxclu, *sceof; 590228072Sbaptextern int current_max_scs; 591228072Sbaptextern char **scname; 592228072Sbapt 593228072Sbapt 594228072Sbapt/* Variables for dfa machine data: 595228072Sbapt * current_max_dfa_size - current maximum number of NFA states in DFA 596228072Sbapt * current_max_xpairs - current maximum number of non-template xtion pairs 597228072Sbapt * current_max_template_xpairs - current maximum number of template pairs 598228072Sbapt * current_max_dfas - current maximum number DFA states 599228072Sbapt * lastdfa - last dfa state number created 600228072Sbapt * nxt - state to enter upon reading character 601228072Sbapt * chk - check value to see if "nxt" applies 602228072Sbapt * tnxt - internal nxt table for templates 603228072Sbapt * base - offset into "nxt" for given state 604228072Sbapt * def - where to go if "chk" disallows "nxt" entry 605228072Sbapt * nultrans - NUL transition for each state 606228072Sbapt * NUL_ec - equivalence class of the NUL character 607228072Sbapt * tblend - last "nxt/chk" table entry being used 608228072Sbapt * firstfree - first empty entry in "nxt/chk" table 609228072Sbapt * dss - nfa state set for each dfa 610228072Sbapt * dfasiz - size of nfa state set for each dfa 611228072Sbapt * dfaacc - accepting set for each dfa state (if using REJECT), or accepting 612228072Sbapt * number, if not 613228072Sbapt * accsiz - size of accepting set for each dfa state 614228072Sbapt * dhash - dfa state hash value 615228072Sbapt * numas - number of DFA accepting states created; note that this 616228072Sbapt * is not necessarily the same value as num_rules, which is the analogous 617228072Sbapt * value for the NFA 618228072Sbapt * numsnpairs - number of state/nextstate transition pairs 619228072Sbapt * jambase - position in base/def where the default jam table starts 620228072Sbapt * jamstate - state number corresponding to "jam" state 621228072Sbapt * end_of_buffer_state - end-of-buffer dfa state number 622228072Sbapt */ 623228072Sbapt 624228072Sbaptextern int current_max_dfa_size, current_max_xpairs; 625228072Sbaptextern int current_max_template_xpairs, current_max_dfas; 626228072Sbaptextern int lastdfa, *nxt, *chk, *tnxt; 627228072Sbaptextern int *base, *def, *nultrans, NUL_ec, tblend, firstfree, **dss, 628228072Sbapt *dfasiz; 629228072Sbaptextern union dfaacc_union { 630228072Sbapt int *dfaacc_set; 631228072Sbapt int dfaacc_state; 632228072Sbapt} *dfaacc; 633228072Sbaptextern int *accsiz, *dhash, numas; 634228072Sbaptextern int numsnpairs, jambase, jamstate; 635228072Sbaptextern int end_of_buffer_state; 636228072Sbapt 637228072Sbapt/* Variables for ccl information: 638228072Sbapt * lastccl - ccl index of the last created ccl 639228072Sbapt * current_maxccls - current limit on the maximum number of unique ccl's 640228072Sbapt * cclmap - maps a ccl index to its set pointer 641228072Sbapt * ccllen - gives the length of a ccl 642228072Sbapt * cclng - true for a given ccl if the ccl is negated 643228072Sbapt * cclreuse - counts how many times a ccl is re-used 644228072Sbapt * current_max_ccl_tbl_size - current limit on number of characters needed 645228072Sbapt * to represent the unique ccl's 646228072Sbapt * ccltbl - holds the characters in each ccl - indexed by cclmap 647228072Sbapt */ 648228072Sbapt 649228072Sbaptextern int lastccl, *cclmap, *ccllen, *cclng, cclreuse; 650228072Sbaptextern int current_maxccls, current_max_ccl_tbl_size; 651228072Sbaptextern Char *ccltbl; 652228072Sbapt 653228072Sbapt 654228072Sbapt/* Variables for miscellaneous information: 655228072Sbapt * nmstr - last NAME scanned by the scanner 656228072Sbapt * sectnum - section number currently being parsed 657228072Sbapt * nummt - number of empty nxt/chk table entries 658228072Sbapt * hshcol - number of hash collisions detected by snstods 659228072Sbapt * dfaeql - number of times a newly created dfa was equal to an old one 660228072Sbapt * numeps - number of epsilon NFA states created 661228072Sbapt * eps2 - number of epsilon states which have 2 out-transitions 662228072Sbapt * num_reallocs - number of times it was necessary to realloc() a group 663228072Sbapt * of arrays 664228072Sbapt * tmpuses - number of DFA states that chain to templates 665228072Sbapt * totnst - total number of NFA states used to make DFA states 666228072Sbapt * peakpairs - peak number of transition pairs we had to store internally 667228072Sbapt * numuniq - number of unique transitions 668228072Sbapt * numdup - number of duplicate transitions 669228072Sbapt * hshsave - number of hash collisions saved by checking number of states 670228072Sbapt * num_backing_up - number of DFA states requiring backing up 671228072Sbapt * bol_needed - whether scanner needs beginning-of-line recognition 672228072Sbapt */ 673228072Sbapt 674228072Sbaptextern char nmstr[MAXLINE]; 675228072Sbaptextern int sectnum, nummt, hshcol, dfaeql, numeps, eps2, num_reallocs; 676228072Sbaptextern int tmpuses, totnst, peakpairs, numuniq, numdup, hshsave; 677228072Sbaptextern int num_backing_up, bol_needed; 678228072Sbapt 679228072Sbaptvoid *allocate_array PROTO ((int, size_t)); 680228072Sbaptvoid *reallocate_array PROTO ((void *, int, size_t)); 681228072Sbapt 682228072Sbaptvoid *flex_alloc PROTO ((size_t)); 683228072Sbaptvoid *flex_realloc PROTO ((void *, size_t)); 684228072Sbaptvoid flex_free PROTO ((void *)); 685228072Sbapt 686228072Sbapt#define allocate_integer_array(size) \ 687228072Sbapt (int *) allocate_array( size, sizeof( int ) ) 688228072Sbapt 689228072Sbapt#define reallocate_integer_array(array,size) \ 690228072Sbapt (int *) reallocate_array( (void *) array, size, sizeof( int ) ) 691228072Sbapt 692228072Sbapt#define allocate_bool_array(size) \ 693228072Sbapt (bool *) allocate_array( size, sizeof( bool ) ) 694228072Sbapt 695228072Sbapt#define reallocate_bool_array(array,size) \ 696228072Sbapt (bool *) reallocate_array( (void *) array, size, sizeof( bool ) ) 697228072Sbapt 698228072Sbapt#define allocate_int_ptr_array(size) \ 699228072Sbapt (int **) allocate_array( size, sizeof( int * ) ) 700228072Sbapt 701228072Sbapt#define allocate_char_ptr_array(size) \ 702228072Sbapt (char **) allocate_array( size, sizeof( char * ) ) 703228072Sbapt 704228072Sbapt#define allocate_dfaacc_union(size) \ 705228072Sbapt (union dfaacc_union *) \ 706228072Sbapt allocate_array( size, sizeof( union dfaacc_union ) ) 707228072Sbapt 708228072Sbapt#define reallocate_int_ptr_array(array,size) \ 709228072Sbapt (int **) reallocate_array( (void *) array, size, sizeof( int * ) ) 710228072Sbapt 711228072Sbapt#define reallocate_char_ptr_array(array,size) \ 712228072Sbapt (char **) reallocate_array( (void *) array, size, sizeof( char * ) ) 713228072Sbapt 714228072Sbapt#define reallocate_dfaacc_union(array, size) \ 715228072Sbapt (union dfaacc_union *) \ 716228072Sbapt reallocate_array( (void *) array, size, sizeof( union dfaacc_union ) ) 717228072Sbapt 718228072Sbapt#define allocate_character_array(size) \ 719228072Sbapt (char *) allocate_array( size, sizeof( char ) ) 720228072Sbapt 721228072Sbapt#define reallocate_character_array(array,size) \ 722228072Sbapt (char *) reallocate_array( (void *) array, size, sizeof( char ) ) 723228072Sbapt 724228072Sbapt#define allocate_Character_array(size) \ 725228072Sbapt (Char *) allocate_array( size, sizeof( Char ) ) 726228072Sbapt 727228072Sbapt#define reallocate_Character_array(array,size) \ 728228072Sbapt (Char *) reallocate_array( (void *) array, size, sizeof( Char ) ) 729228072Sbapt 730228072Sbapt 731228072Sbapt/* Used to communicate between scanner and parser. The type should really 732228072Sbapt * be YYSTYPE, but we can't easily get our hands on it. 733228072Sbapt */ 734228072Sbaptextern int yylval; 735228072Sbapt 736228072Sbapt 737228072Sbapt/* External functions that are cross-referenced among the flex source files. */ 738228072Sbapt 739228072Sbapt 740228072Sbapt/* from file ccl.c */ 741228072Sbapt 742228072Sbaptextern void ccladd PROTO ((int, int)); /* add a single character to a ccl */ 743228072Sbaptextern int cclinit PROTO ((void)); /* make an empty ccl */ 744228072Sbaptextern void cclnegate PROTO ((int)); /* negate a ccl */ 745228072Sbaptextern int ccl_set_diff (int a, int b); /* set difference of two ccls. */ 746228072Sbaptextern int ccl_set_union (int a, int b); /* set union of two ccls. */ 747228072Sbapt 748228072Sbapt/* List the members of a set of characters in CCL form. */ 749228072Sbaptextern void list_character_set PROTO ((FILE *, int[])); 750228072Sbapt 751228072Sbapt 752228072Sbapt/* from file dfa.c */ 753228072Sbapt 754228072Sbapt/* Check a DFA state for backing up. */ 755228072Sbaptextern void check_for_backing_up PROTO ((int, int[])); 756228072Sbapt 757228072Sbapt/* Check to see if NFA state set constitutes "dangerous" trailing context. */ 758228072Sbaptextern void check_trailing_context PROTO ((int *, int, int *, int)); 759228072Sbapt 760228072Sbapt/* Construct the epsilon closure of a set of ndfa states. */ 761228072Sbaptextern int *epsclosure PROTO ((int *, int *, int[], int *, int *)); 762228072Sbapt 763228072Sbapt/* Increase the maximum number of dfas. */ 764228072Sbaptextern void increase_max_dfas PROTO ((void)); 765228072Sbapt 766228072Sbaptextern void ntod PROTO ((void)); /* convert a ndfa to a dfa */ 767228072Sbapt 768228072Sbapt/* Converts a set of ndfa states into a dfa state. */ 769228072Sbaptextern int snstods PROTO ((int[], int, int[], int, int, int *)); 770228072Sbapt 771228072Sbapt 772228072Sbapt/* from file ecs.c */ 773228072Sbapt 774228072Sbapt/* Convert character classes to set of equivalence classes. */ 775228072Sbaptextern void ccl2ecl PROTO ((void)); 776228072Sbapt 777228072Sbapt/* Associate equivalence class numbers with class members. */ 778228072Sbaptextern int cre8ecs PROTO ((int[], int[], int)); 779228072Sbapt 780228072Sbapt/* Update equivalence classes based on character class transitions. */ 781228072Sbaptextern void mkeccl PROTO ((Char[], int, int[], int[], int, int)); 782228072Sbapt 783228072Sbapt/* Create equivalence class for single character. */ 784228072Sbaptextern void mkechar PROTO ((int, int[], int[])); 785228072Sbapt 786228072Sbapt 787228072Sbapt/* from file gen.c */ 788228072Sbapt 789228072Sbaptextern void do_indent PROTO ((void)); /* indent to the current level */ 790228072Sbapt 791228072Sbapt/* Generate the code to keep backing-up information. */ 792228072Sbaptextern void gen_backing_up PROTO ((void)); 793228072Sbapt 794228072Sbapt/* Generate the code to perform the backing up. */ 795228072Sbaptextern void gen_bu_action PROTO ((void)); 796228072Sbapt 797228072Sbapt/* Generate full speed compressed transition table. */ 798228072Sbaptextern void genctbl PROTO ((void)); 799228072Sbapt 800228072Sbapt/* Generate the code to find the action number. */ 801228072Sbaptextern void gen_find_action PROTO ((void)); 802228072Sbapt 803228072Sbaptextern void genftbl PROTO ((void)); /* generate full transition table */ 804228072Sbapt 805228072Sbapt/* Generate the code to find the next compressed-table state. */ 806228072Sbaptextern void gen_next_compressed_state PROTO ((char *)); 807228072Sbapt 808228072Sbapt/* Generate the code to find the next match. */ 809228072Sbaptextern void gen_next_match PROTO ((void)); 810228072Sbapt 811228072Sbapt/* Generate the code to find the next state. */ 812228072Sbaptextern void gen_next_state PROTO ((int)); 813228072Sbapt 814228072Sbapt/* Generate the code to make a NUL transition. */ 815228072Sbaptextern void gen_NUL_trans PROTO ((void)); 816228072Sbapt 817228072Sbapt/* Generate the code to find the start state. */ 818228072Sbaptextern void gen_start_state PROTO ((void)); 819228072Sbapt 820228072Sbapt/* Generate data statements for the transition tables. */ 821228072Sbaptextern void gentabs PROTO ((void)); 822228072Sbapt 823228072Sbapt/* Write out a formatted string at the current indentation level. */ 824228072Sbaptextern void indent_put2s PROTO ((const char *, const char *)); 825228072Sbapt 826228072Sbapt/* Write out a string + newline at the current indentation level. */ 827228072Sbaptextern void indent_puts PROTO ((const char *)); 828228072Sbapt 829228072Sbaptextern void make_tables PROTO ((void)); /* generate transition tables */ 830228072Sbapt 831228072Sbapt 832228072Sbapt/* from file main.c */ 833228072Sbapt 834228072Sbaptextern void check_options PROTO ((void)); 835228072Sbaptextern void flexend PROTO ((int)); 836228072Sbaptextern void usage PROTO ((void)); 837228072Sbapt 838228072Sbapt 839228072Sbapt/* from file misc.c */ 840228072Sbapt 841228072Sbapt/* Add a #define to the action file. */ 842228072Sbaptextern void action_define PROTO ((const char *defname, int value)); 843228072Sbapt 844228072Sbapt/* Add the given text to the stored actions. */ 845228072Sbaptextern void add_action PROTO ((const char *new_text)); 846228072Sbapt 847228072Sbapt/* True if a string is all lower case. */ 848250874Sjkimextern int all_lower PROTO ((char *)); 849228072Sbapt 850228072Sbapt/* True if a string is all upper case. */ 851250874Sjkimextern int all_upper PROTO ((char *)); 852228072Sbapt 853250125Sjkim/* Compare two integers for use by qsort. */ 854250125Sjkimextern int intcmp PROTO ((const void *, const void *)); 855228072Sbapt 856228072Sbapt/* Check a character to make sure it's in the expected range. */ 857228072Sbaptextern void check_char PROTO ((int c)); 858228072Sbapt 859228072Sbapt/* Replace upper-case letter to lower-case. */ 860228072Sbaptextern Char clower PROTO ((int)); 861228072Sbapt 862228072Sbapt/* Returns a dynamically allocated copy of a string. */ 863250874Sjkimextern char *copy_string PROTO ((const char *)); 864228072Sbapt 865228072Sbapt/* Returns a dynamically allocated copy of a (potentially) unsigned string. */ 866250874Sjkimextern Char *copy_unsigned_string PROTO ((Char *)); 867228072Sbapt 868250125Sjkim/* Compare two characters for use by qsort with '\0' sorting last. */ 869250125Sjkimextern int cclcmp PROTO ((const void *, const void *)); 870228072Sbapt 871228072Sbapt/* Finish up a block of data declarations. */ 872228072Sbaptextern void dataend PROTO ((void)); 873228072Sbapt 874228072Sbapt/* Flush generated data statements. */ 875228072Sbaptextern void dataflush PROTO ((void)); 876228072Sbapt 877228072Sbapt/* Report an error message and terminate. */ 878228072Sbaptextern void flexerror PROTO ((const char *)); 879228072Sbapt 880228072Sbapt/* Report a fatal error message and terminate. */ 881228072Sbaptextern void flexfatal PROTO ((const char *)); 882228072Sbapt 883228072Sbapt/* Report a fatal error with a pinpoint, and terminate */ 884228072Sbapt#if HAVE_DECL___FUNC__ 885228072Sbapt#define flex_die(msg) \ 886228072Sbapt do{ \ 887228072Sbapt fprintf (stderr,\ 888228072Sbapt _("%s: fatal internal error at %s:%d (%s): %s\n"),\ 889228072Sbapt program_name, __FILE__, (int)__LINE__,\ 890228072Sbapt __func__,msg);\ 891228072Sbapt FLEX_EXIT(1);\ 892228072Sbapt }while(0) 893228072Sbapt#else /* ! HAVE_DECL___FUNC__ */ 894228072Sbapt#define flex_die(msg) \ 895228072Sbapt do{ \ 896228072Sbapt fprintf (stderr,\ 897228072Sbapt _("%s: fatal internal error at %s:%d %s\n"),\ 898228072Sbapt program_name, __FILE__, (int)__LINE__,\ 899228072Sbapt msg);\ 900228072Sbapt FLEX_EXIT(1);\ 901228072Sbapt }while(0) 902228072Sbapt#endif /* ! HAVE_DECL___func__ */ 903228072Sbapt 904228072Sbapt/* Convert a hexadecimal digit string to an integer value. */ 905228072Sbaptextern int htoi PROTO ((Char[])); 906228072Sbapt 907228072Sbapt/* Report an error message formatted with one integer argument. */ 908228072Sbaptextern void lerrif PROTO ((const char *, int)); 909228072Sbapt 910228072Sbapt/* Report an error message formatted with one string argument. */ 911228072Sbaptextern void lerrsf PROTO ((const char *, const char *)); 912228072Sbapt 913250128Sjkim/* Like lerrsf, but also exit after displaying message. */ 914250128Sjkimextern void lerrsf_fatal PROTO ((const char *, const char *)); 915250128Sjkim 916228072Sbapt/* Spit out a "#line" statement. */ 917228072Sbaptextern void line_directive_out PROTO ((FILE *, int)); 918228072Sbapt 919228072Sbapt/* Mark the current position in the action array as the end of the section 1 920228072Sbapt * user defs. 921228072Sbapt */ 922228072Sbaptextern void mark_defs1 PROTO ((void)); 923228072Sbapt 924228072Sbapt/* Mark the current position in the action array as the end of the prolog. */ 925228072Sbaptextern void mark_prolog PROTO ((void)); 926228072Sbapt 927250874Sjkim/* Generate a data statement for a two-dimensional array. */ 928228072Sbaptextern void mk2data PROTO ((int)); 929228072Sbapt 930228072Sbaptextern void mkdata PROTO ((int)); /* generate a data statement */ 931228072Sbapt 932228072Sbapt/* Return the integer represented by a string of digits. */ 933228072Sbaptextern int myctoi PROTO ((const char *)); 934228072Sbapt 935228072Sbapt/* Return character corresponding to escape sequence. */ 936228072Sbaptextern Char myesc PROTO ((Char[])); 937228072Sbapt 938228072Sbapt/* Convert an octal digit string to an integer value. */ 939228072Sbaptextern int otoi PROTO ((Char[])); 940228072Sbapt 941228072Sbapt/* Output a (possibly-formatted) string to the generated scanner. */ 942228072Sbaptextern void out PROTO ((const char *)); 943228072Sbaptextern void out_dec PROTO ((const char *, int)); 944228072Sbaptextern void out_dec2 PROTO ((const char *, int, int)); 945228072Sbaptextern void out_hex PROTO ((const char *, unsigned int)); 946228072Sbaptextern void out_str PROTO ((const char *, const char *)); 947228072Sbaptextern void out_str3 948228072SbaptPROTO ((const char *, const char *, const char *, const char *)); 949228072Sbaptextern void out_str_dec PROTO ((const char *, const char *, int)); 950228072Sbaptextern void outc PROTO ((int)); 951228072Sbaptextern void outn PROTO ((const char *)); 952228072Sbaptextern void out_m4_define (const char* def, const char* val); 953228072Sbapt 954228072Sbapt/* Return a printable version of the given character, which might be 955228072Sbapt * 8-bit. 956228072Sbapt */ 957228072Sbaptextern char *readable_form PROTO ((int)); 958228072Sbapt 959228072Sbapt/* Write out one section of the skeleton file. */ 960228072Sbaptextern void skelout PROTO ((void)); 961228072Sbapt 962228072Sbapt/* Output a yy_trans_info structure. */ 963228072Sbaptextern void transition_struct_out PROTO ((int, int)); 964228072Sbapt 965228072Sbapt/* Only needed when using certain broken versions of bison to build parse.c. */ 966228072Sbaptextern void *yy_flex_xmalloc PROTO ((int)); 967228072Sbapt 968228072Sbapt/* Set a region of memory to 0. */ 969228072Sbaptextern void zero_out PROTO ((char *, size_t)); 970228072Sbapt 971228072Sbapt 972228072Sbapt/* from file nfa.c */ 973228072Sbapt 974228072Sbapt/* Add an accepting state to a machine. */ 975228072Sbaptextern void add_accept PROTO ((int, int)); 976228072Sbapt 977228072Sbapt/* Make a given number of copies of a singleton machine. */ 978228072Sbaptextern int copysingl PROTO ((int, int)); 979228072Sbapt 980228072Sbapt/* Debugging routine to write out an nfa. */ 981228072Sbaptextern void dumpnfa PROTO ((int)); 982228072Sbapt 983228072Sbapt/* Finish up the processing for a rule. */ 984228072Sbaptextern void finish_rule PROTO ((int, int, int, int, int)); 985228072Sbapt 986228072Sbapt/* Connect two machines together. */ 987228072Sbaptextern int link_machines PROTO ((int, int)); 988228072Sbapt 989228072Sbapt/* Mark each "beginning" state in a machine as being a "normal" (i.e., 990228072Sbapt * not trailing context associated) state. 991228072Sbapt */ 992250874Sjkimextern void mark_beginning_as_normal PROTO ((int)); 993228072Sbapt 994228072Sbapt/* Make a machine that branches to two machines. */ 995228072Sbaptextern int mkbranch PROTO ((int, int)); 996228072Sbapt 997228072Sbaptextern int mkclos PROTO ((int)); /* convert a machine into a closure */ 998228072Sbaptextern int mkopt PROTO ((int)); /* make a machine optional */ 999228072Sbapt 1000228072Sbapt/* Make a machine that matches either one of two machines. */ 1001228072Sbaptextern int mkor PROTO ((int, int)); 1002228072Sbapt 1003228072Sbapt/* Convert a machine into a positive closure. */ 1004228072Sbaptextern int mkposcl PROTO ((int)); 1005228072Sbapt 1006228072Sbaptextern int mkrep PROTO ((int, int, int)); /* make a replicated machine */ 1007228072Sbapt 1008228072Sbapt/* Create a state with a transition on a given symbol. */ 1009228072Sbaptextern int mkstate PROTO ((int)); 1010228072Sbapt 1011228072Sbaptextern void new_rule PROTO ((void)); /* initialize for a new rule */ 1012228072Sbapt 1013228072Sbapt 1014228072Sbapt/* from file parse.y */ 1015228072Sbapt 1016228072Sbapt/* Build the "<<EOF>>" action for the active start conditions. */ 1017228072Sbaptextern void build_eof_action PROTO ((void)); 1018228072Sbapt 1019228072Sbapt/* Write out a message formatted with one string, pinpointing its location. */ 1020228072Sbaptextern void format_pinpoint_message PROTO ((const char *, const char *)); 1021228072Sbapt 1022228072Sbapt/* Write out a message, pinpointing its location. */ 1023228072Sbaptextern void pinpoint_message PROTO ((const char *)); 1024228072Sbapt 1025228072Sbapt/* Write out a warning, pinpointing it at the given line. */ 1026228072Sbaptextern void line_warning PROTO ((const char *, int)); 1027228072Sbapt 1028228072Sbapt/* Write out a message, pinpointing it at the given line. */ 1029228072Sbaptextern void line_pinpoint PROTO ((const char *, int)); 1030228072Sbapt 1031228072Sbapt/* Report a formatted syntax error. */ 1032228072Sbaptextern void format_synerr PROTO ((const char *, const char *)); 1033228072Sbaptextern void synerr PROTO ((const char *)); /* report a syntax error */ 1034228072Sbaptextern void format_warn PROTO ((const char *, const char *)); 1035228072Sbaptextern void warn PROTO ((const char *)); /* report a warning */ 1036228072Sbaptextern void yyerror PROTO ((const char *)); /* report a parse error */ 1037228072Sbaptextern int yyparse PROTO ((void)); /* the YACC parser */ 1038228072Sbapt 1039228072Sbapt 1040228072Sbapt/* from file scan.l */ 1041228072Sbapt 1042228072Sbapt/* The Flex-generated scanner for flex. */ 1043228072Sbaptextern int flexscan PROTO ((void)); 1044228072Sbapt 1045228072Sbapt/* Open the given file (if NULL, stdin) for scanning. */ 1046228072Sbaptextern void set_input_file PROTO ((char *)); 1047228072Sbapt 1048228072Sbapt/* Wrapup a file in the lexical analyzer. */ 1049228072Sbaptextern int yywrap PROTO ((void)); 1050228072Sbapt 1051228072Sbapt 1052228072Sbapt/* from file sym.c */ 1053228072Sbapt 1054228072Sbapt/* Save the text of a character class. */ 1055228072Sbaptextern void cclinstal PROTO ((Char[], int)); 1056228072Sbapt 1057228072Sbapt/* Lookup the number associated with character class. */ 1058228072Sbaptextern int ccllookup PROTO ((Char[])); 1059228072Sbapt 1060228072Sbaptextern void ndinstal PROTO ((const char *, Char[])); /* install a name definition */ 1061228072Sbaptextern Char *ndlookup PROTO ((const char *)); /* lookup a name definition */ 1062228072Sbapt 1063228072Sbapt/* Increase maximum number of SC's. */ 1064228072Sbaptextern void scextend PROTO ((void)); 1065228072Sbaptextern void scinstal PROTO ((const char *, int)); /* make a start condition */ 1066228072Sbapt 1067228072Sbapt/* Lookup the number associated with a start condition. */ 1068228072Sbaptextern int sclookup PROTO ((const char *)); 1069228072Sbapt 1070228072Sbapt 1071228072Sbapt/* from file tblcmp.c */ 1072228072Sbapt 1073228072Sbapt/* Build table entries for dfa state. */ 1074228072Sbaptextern void bldtbl PROTO ((int[], int, int, int, int)); 1075228072Sbapt 1076228072Sbaptextern void cmptmps PROTO ((void)); /* compress template table entries */ 1077228072Sbaptextern void expand_nxt_chk PROTO ((void)); /* increase nxt/chk arrays */ 1078228072Sbapt 1079228072Sbapt/* Finds a space in the table for a state to be placed. */ 1080228072Sbaptextern int find_table_space PROTO ((int *, int)); 1081228072Sbaptextern void inittbl PROTO ((void)); /* initialize transition tables */ 1082228072Sbapt 1083228072Sbapt/* Make the default, "jam" table entries. */ 1084228072Sbaptextern void mkdeftbl PROTO ((void)); 1085228072Sbapt 1086228072Sbapt/* Create table entries for a state (or state fragment) which has 1087228072Sbapt * only one out-transition. 1088228072Sbapt */ 1089228072Sbaptextern void mk1tbl PROTO ((int, int, int, int)); 1090228072Sbapt 1091228072Sbapt/* Place a state into full speed transition table. */ 1092228072Sbaptextern void place_state PROTO ((int *, int, int)); 1093228072Sbapt 1094228072Sbapt/* Save states with only one out-transition to be processed later. */ 1095228072Sbaptextern void stack1 PROTO ((int, int, int, int)); 1096228072Sbapt 1097228072Sbapt 1098228072Sbapt/* from file yylex.c */ 1099228072Sbapt 1100228072Sbaptextern int yylex PROTO ((void)); 1101228072Sbapt 1102228072Sbapt/* A growable array. See buf.c. */ 1103228072Sbaptstruct Buf { 1104228072Sbapt void *elts; /* elements. */ 1105228072Sbapt int nelts; /* number of elements. */ 1106228072Sbapt size_t elt_size; /* in bytes. */ 1107228072Sbapt int nmax; /* max capacity of elements. */ 1108228072Sbapt}; 1109228072Sbapt 1110228072Sbaptextern void buf_init PROTO ((struct Buf * buf, size_t elem_size)); 1111228072Sbaptextern void buf_destroy PROTO ((struct Buf * buf)); 1112228072Sbaptextern struct Buf *buf_append 1113228072SbaptPROTO ((struct Buf * buf, const void *ptr, int n_elem)); 1114228072Sbaptextern struct Buf *buf_concat PROTO((struct Buf* dest, const struct Buf* src)); 1115228072Sbaptextern struct Buf *buf_strappend PROTO ((struct Buf *, const char *str)); 1116228072Sbaptextern struct Buf *buf_strnappend 1117228072SbaptPROTO ((struct Buf *, const char *str, int nchars)); 1118228072Sbaptextern struct Buf *buf_strdefine 1119228072SbaptPROTO ((struct Buf * buf, const char *str, const char *def)); 1120228072Sbaptextern struct Buf *buf_prints PROTO((struct Buf *buf, const char *fmt, const char* s)); 1121228072Sbaptextern struct Buf *buf_m4_define PROTO((struct Buf *buf, const char* def, const char* val)); 1122228072Sbaptextern struct Buf *buf_m4_undefine PROTO((struct Buf *buf, const char* def)); 1123228072Sbaptextern struct Buf *buf_print_strings PROTO((struct Buf * buf, FILE* out)); 1124228072Sbaptextern struct Buf *buf_linedir PROTO((struct Buf *buf, const char* filename, int lineno)); 1125228072Sbapt 1126228072Sbaptextern struct Buf userdef_buf; /* a string buffer for #define's generated by user-options on cmd line. */ 1127228072Sbaptextern struct Buf defs_buf; /* a char* buffer to save #define'd some symbols generated by flex. */ 1128228072Sbaptextern struct Buf yydmap_buf; /* a string buffer to hold yydmap elements */ 1129228072Sbaptextern struct Buf m4defs_buf; /* Holds m4 definitions. */ 1130228072Sbaptextern struct Buf top_buf; /* contains %top code. String buffer. */ 1131228072Sbapt 1132228072Sbapt/* For blocking out code from the header file. */ 1133228072Sbapt#define OUT_BEGIN_CODE() outn("m4_ifdef( [[M4_YY_IN_HEADER]],,[[") 1134228072Sbapt#define OUT_END_CODE() outn("]])") 1135228072Sbapt 1136228072Sbapt/* For setjmp/longjmp (instead of calling exit(2)). Linkage in main.c */ 1137228072Sbaptextern jmp_buf flex_main_jmp_buf; 1138228072Sbapt 1139228072Sbapt#define FLEX_EXIT(status) longjmp(flex_main_jmp_buf,(status)+1) 1140228072Sbapt 1141228072Sbapt/* Removes all \n and \r chars from tail of str. returns str. */ 1142228072Sbaptextern char *chomp (char *str); 1143228072Sbapt 1144228072Sbapt/* ctype functions forced to return boolean */ 1145228072Sbapt#define b_isalnum(c) (isalnum(c)?true:false) 1146228072Sbapt#define b_isalpha(c) (isalpha(c)?true:false) 1147228072Sbapt#define b_isascii(c) (isascii(c)?true:false) 1148228072Sbapt#define b_isblank(c) (isblank(c)?true:false) 1149228072Sbapt#define b_iscntrl(c) (iscntrl(c)?true:false) 1150228072Sbapt#define b_isdigit(c) (isdigit(c)?true:false) 1151228072Sbapt#define b_isgraph(c) (isgraph(c)?true:false) 1152228072Sbapt#define b_islower(c) (islower(c)?true:false) 1153228072Sbapt#define b_isprint(c) (isprint(c)?true:false) 1154228072Sbapt#define b_ispunct(c) (ispunct(c)?true:false) 1155228072Sbapt#define b_isspace(c) (isspace(c)?true:false) 1156228072Sbapt#define b_isupper(c) (isupper(c)?true:false) 1157228072Sbapt#define b_isxdigit(c) (isxdigit(c)?true:false) 1158228072Sbapt 1159228072Sbapt/* return true if char is uppercase or lowercase. */ 1160228072Sbaptbool has_case(int c); 1161228072Sbapt 1162228072Sbapt/* Change case of character if possible. */ 1163228072Sbaptint reverse_case(int c); 1164228072Sbapt 1165228072Sbapt/* return false if [c1-c2] is ambiguous for a caseless scanner. */ 1166228072Sbaptbool range_covers_case (int c1, int c2); 1167228072Sbapt 1168228072Sbapt/* 1169228072Sbapt * From "filter.c" 1170228072Sbapt */ 1171228072Sbapt 1172228072Sbapt/** A single stdio filter to execute. 1173228072Sbapt * The filter may be external, such as "sed", or it 1174228072Sbapt * may be internal, as a function call. 1175228072Sbapt */ 1176228072Sbaptstruct filter { 1177228072Sbapt int (*filter_func)(struct filter*); /**< internal filter function */ 1178228072Sbapt void * extra; /**< extra data passed to filter_func */ 1179228072Sbapt int argc; /**< arg count */ 1180228072Sbapt const char ** argv; /**< arg vector, \0-terminated */ 1181228072Sbapt struct filter * next; /**< next filter or NULL */ 1182228072Sbapt}; 1183228072Sbapt 1184228072Sbapt/* output filter chain */ 1185228072Sbaptextern struct filter * output_chain; 1186228072Sbaptextern struct filter *filter_create_ext PROTO((struct filter * chain, const char *cmd, ...)); 1187228072Sbaptstruct filter *filter_create_int PROTO((struct filter *chain, 1188228072Sbapt int (*filter_func) (struct filter *), 1189228072Sbapt void *extra)); 1190228072Sbaptextern bool filter_apply_chain PROTO((struct filter * chain)); 1191228072Sbaptextern int filter_truncate (struct filter * chain, int max_len); 1192228072Sbaptextern int filter_tee_header PROTO((struct filter *chain)); 1193228072Sbaptextern int filter_fix_linedirs PROTO((struct filter *chain)); 1194228072Sbapt 1195228072Sbapt 1196228072Sbapt/* 1197228072Sbapt * From "regex.c" 1198228072Sbapt */ 1199228072Sbapt 1200228072Sbaptextern regex_t regex_linedir, regex_blank_line; 1201228072Sbaptbool flex_init_regex(void); 1202228072Sbaptvoid flex_regcomp(regex_t *preg, const char *regex, int cflags); 1203228072Sbaptchar *regmatch_dup (regmatch_t * m, const char *src); 1204228072Sbaptchar *regmatch_cpy (regmatch_t * m, char *dest, const char *src); 1205228072Sbaptint regmatch_len (regmatch_t * m); 1206228072Sbaptint regmatch_strtol (regmatch_t * m, const char *src, char **endptr, int base); 1207228072Sbaptbool regmatch_empty (regmatch_t * m); 1208228072Sbapt 1209228072Sbapt/* From "scanflags.h" */ 1210228072Sbapttypedef unsigned int scanflags_t; 1211228072Sbaptextern scanflags_t* _sf_stk; 1212228072Sbaptextern size_t _sf_top_ix, _sf_max; /**< stack of scanner flags. */ 1213228072Sbapt#define _SF_CASE_INS 0x0001 1214228072Sbapt#define _SF_DOT_ALL 0x0002 1215228072Sbapt#define _SF_SKIP_WS 0x0004 1216228072Sbapt#define sf_top() (_sf_stk[_sf_top_ix]) 1217228072Sbapt#define sf_case_ins() (sf_top() & _SF_CASE_INS) 1218228072Sbapt#define sf_dot_all() (sf_top() & _SF_DOT_ALL) 1219228072Sbapt#define sf_skip_ws() (sf_top() & _SF_SKIP_WS) 1220228072Sbapt#define sf_set_case_ins(X) ((X) ? (sf_top() |= _SF_CASE_INS) : (sf_top() &= ~_SF_CASE_INS)) 1221228072Sbapt#define sf_set_dot_all(X) ((X) ? (sf_top() |= _SF_DOT_ALL) : (sf_top() &= ~_SF_DOT_ALL)) 1222228072Sbapt#define sf_set_skip_ws(X) ((X) ? (sf_top() |= _SF_SKIP_WS) : (sf_top() &= ~_SF_SKIP_WS)) 1223228072Sbaptextern void sf_init(void); 1224228072Sbaptextern void sf_push(void); 1225228072Sbaptextern void sf_pop(void); 1226228072Sbapt 1227228072Sbapt 1228228072Sbapt#endif /* not defined FLEXDEF_H */ 1229