4.3BSD-Reno/share/man/cat1/lex.0

Compare this file to the similar file:
Show the results in this format:

LEX(1)			    UNIX Reference Manual			LEX(1)

NNAAMMEE
     lleexx - fast lexical analyzer generator

SSYYNNOOPPSSIISS
     lleexx [[--bbccddffiinnppssttvvFFIILLTT88] --CC[efmF] --SS_s_k_e_l_e_t_o_n]
     lleexx [_f_i_l_e ...]

DDEESSCCRRIIPPTTIIOONN
     LLeexx is a tool for generating _s_c_a_n_n_e_r_s: programs which recognized lexical
     patterns in text.	LLeexx reads the given input files, or its standard input
     if no file names are given, for a description of a scanner to generate.
     The description is in the form of pairs of regular expressions and C
     code, called _r_u_l_e_s.  LLeexx generates as output a C source file, _l_e_x._y_y._c,
     which defines a routine yyyylleexx().  This file is compiled and linked with
     the --llffll library to produce an executable.  When the executable is run,
     it analyzes its input for occurrences of the regular expressions.	When-
     ever it finds one, it executes the corresponding C code.

     For full documentation, see _L_e_x_d_o_c.  This manual entry is intended for
     use as a quick reference.

OOPPTTIIOONNSS
     LLeexx has the following options:

     --bb    Generate backtracking information to _l_e_x._b_a_c_k_t_r_a_c_k.	This is a list
	   of scanner states which require backtracking and the input charac-
	   ters on which they do so.  By adding rules one can remove back-
	   tracking states.  If all backtracking states are eliminated and --ff
	   or --FF is used, the generated scanner will run faster.

     --cc    is a do-nothing, deprecated option included for POSIX compliance.

	   _N_O_T_E: in previous releases of LLeexx [--cc] specified table-compression
	   options.  This functionality is now given by the --CC flag.  To ease
	   the the impact of this change, when lleexx encounters --cc,, it currently
	   issues a warning message and assumes that --CC was desired instead.
	   In the future this "promotion" of --cc to --CC will go away in the name
	   of full POSIX compliance (unless the POSIX meaning is removed
	   first).

     --dd    makes the generated scanner run in _d_e_b_u_g mode.  Whenever a pattern
	   is recognized and the global _y_y__L_e_x__d_e_b_u_g is non-zero (which is the
	   default), the scanner will write to stderr a line of the form:

		 --accepting rule at line 53 ("the matched text")

	   The line number refers to the location of the rule in the file de-
	   fining the scanner (i.e., the file that was fed to lex).  Messages
	   are also generated when the scanner backtracks, accepts the default
	   rule, reaches the end of its input buffer (or encounters a NUL; the
	   two look the same as far as the scanner's concerned), or reaches an
	   end-of-file.

     --ff    specifies (take your pick) _f_u_l_l _t_a_b_l_e or _f_a_s_t _s_c_a_n_n_e_r.  No table
	   compression is done.  The result is large but fast.	This option is
	   equivalent to --CCff (see below).

     --ii    instructs lleexx to generate a _c_a_s_e-_i_n_s_e_n_s_i_t_i_v_e scanner.  The case of
	   letters given in the lleexx input patterns will be ignored, and tokens
	   in the input will be matched regardless of case.  The matched text
	   given in _y_y_t_e_x_t will have the preserved case (i.e., it will not be
	   folded).

     --nn    is another do-nothing, deprecated option included only for POSIX
	   compliance.
     --pp    generates a performance report to stderr.  The report consists of
	   comments regarding features of the lleexx input file which will cause
	   a loss of performance in the resulting scanner.

     --ss    causes the _d_e_f_a_u_l_t _r_u_l_e (that unmatched scanner input is echoed to
	   _s_t_d_o_u_t) to be suppressed.  If the scanner encounters input that
	   does not match any of its rules, it aborts with an error.

     --tt    instructs lleexx to write the scanner it generates to standard output
	   instead of _l_e_x._y_y._c.

     --vv    specifies that lleexx should write to stderr a summary of statistics
	   regarding the scanner it generates.

     --FF    specifies that the _f_a_s_t scanner table representation should be
	   used.  This representation is about as fast as the full table
	   representation (--ff), and for some sets of patterns will be consid-
	   erably smaller (and for others, larger).  See _L_e_x_d_o_c for details.

	   This option is equivalent to --CCFF (see below).

     --II    instructs lleexx to generate an _i_n_t_e_r_a_c_t_i_v_e scanner, that is, a
	   scanner which stops immediately rather than looking ahead if it
	   knows that the currently scanned text cannot be part of a longer
	   rule's match.  Again, see _L_e_x_d_o_c for details.

	   Note, --II cannot be used in conjunction with _f_u_l_l or _f_a_s_t _t_a_b_l_e_s,
	   i.e., the --ff, --FF, --CCff, or --CCFF flags.

     --LL    instructs lleexx not to generate #line directives in _l_e_x._y_y._c.	The
	   default is to generate such directives so error messages in the ac-
	   tions will be correctly located with respect to the original lleexx
	   input file, and not to the fairly meaningless line numbers of
	   _l_e_x._y_y._c.

     --TT    makes lleexx run in _t_r_a_c_e mode.  It will generate a lot of messages to
	   stdout concerning the form of the input and the resultant non-
	   deterministic and deterministic finite automata.  This option is
	   mostly for use in maintaining lleexx.

     --88    instructs lleexx to generate an 8-bit scanner.	On some sites, this is
	   the default.  On others, the default is 7-bit characters.  To see
	   which is the case, check the verbose (--vv) output for "equivalence
	   classes created".  If the denominator of the number shown is 128,
	   then by default lleexx is generating 7-bit characters.	If it is 256,
	   then the default is 8-bit characters.

     --CC[eeffmmFF]
	   controls the degree of table compression. The default setting is
	   --CCeemm.

	   --CC	 A lone --CC specifies that the scanner tables should be
		 compressed but neither equivalence classes nor meta-
		 equivalence classes should be used.

	   --CCee	 directs lleexx to construct _e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s_e_s, i.e., sets of
		 characters which have identical lexical properties.
		 Equivalence classes usually give dramatic reductions in the
		 final table/object file sizes (typically a factor of 2-5) and
		 are pretty cheap performance-wise (one array look-up per
		 character scanned).

	   --CCff	 specifies that the _f_u_l_l scanner tables should be generated -
		 lleexx should not compress the tables by taking advantages of
		 similar transition functions for different states.

	   --CCFF	 specifies that the alternate fast scanner representation
		 (described in _L_e_x_d_o_c) should be used.

	   --CCmm	 directs lleexx to construct _m_e_t_a-_e_q_u_i_v_a_l_e_n_c_e _c_l_a_s_s_e_s, which are
		 sets of equivalence classes (or characters, if equivalence
		 classes are not being used) that are commonly used together.
		 Meta-equivalence classes are often a big win when using
		 compressed tables, but they have a moderate performance im-
		 pact (one or two "if" tests and one array look-up per charac-
		 ter scanned).

	   --CCeemm
		 (default) Generate both equivalence classes and meta-
		 equivalence classes.  This setting provides the highest de-
		 gree of table compression.

	   Faster-executing scanners can be traded off at the cost of larger
	   tables with the following generally being true:

			    slowest & smallest
				  -Cem
				  -Cm
				  -Ce
				  -C
				  -C{f,F}e
				  -C{f,F}
			    fastest & largest

	   --CC options are not cumulative; whenever the flag is encountered,
	   the previous -C settings are forgotten.

	   The options --CCff or --CCFF and --CCmm do not make sense together - there
	   is no opportunity for meta-equivalence classes if the table is not
	   being compressed.  Otherwise the options may be freely mixed.

     --SS_s_k_e_l_e_t_o_n__f_i_l_e
	   overrides the default skeleton file from which lleexx constructs its
	   scanners.  Useful for lleexx maintenance or development.

SSUUMMMMAARRYY OOFF LLeexx RREEGGUULLAARR EEXXPPRREESSSSIIOONNSS
     The patterns in the input are written using an extended set of regular
     expressions.  These are:

     x	     match the character 'x'
     .	     any character except newline
     [xyz]   a "character class"; in this case, the pattern matches either an
	     'x', a 'y', or a 'z'
     [abj-oZ]
	     a "character class" with a range in it; matches an 'a', a 'b',
	     any letter from 'j' through 'o', or a 'Z'
     [Li ^A-Z]
	     a "negated character class", i.e., any character but those in the
	     class.  In this case, any character EXCEPT an uppercase letter.
     [Li ^A-Z\n]
	     any character EXCEPT an uppercase letter or a newline
     r*      zero or more r's, where r is any regular expression
     r+      one or more r's
     r?      zero or one r's (that is, "an optional r")
     r{2,5}
	     anywhere from two to five r's
     r{2,}   two or more r's
     r{4}    exactly 4 r's
     {name}
	     the expansion of the "name" definition (see above)
     [xyz]\"foo"
	     the literal string: [xyz]"foo
     \X      if X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v', then the ANSI-C
	     interpretation of \x.  Otherwise, a literal 'X' (used to escape
	     operators such as '*')
     \123    the character with octal value 123
     \x2a    the character with hexadecimal value 2a
     (r)     match an r; parentheses are used to override precedence (see
	     below)
     rs      the regular expression r followed by the regular expression s;
	     called "concatenation"
     rs      either an r or an s
     r/s     an r but only if it is followed by an s.  The s is not part of
	     the matched text.	This type of pattern is called as "trailing
	     context".
     ^r      an r, but only at the beginning of a line
     r$      an r, but only at the end of a line.  Equivalent to "r/\n".
     <s>r    an r, but only in start condition s (see below for discussion of
	     start conditions)
     <s1,s2,s3>r
	     same, but in any of start conditions s1, s2, or s3
     <<EOF>>
	     an end-of-file
     <s1,s2><<EOF>>
	     an end-of-file when in start condition s1 or s2

     The regular expressions listed above are grouped according to precedence,
     from highest precedence at the top to lowest at the bottom.  Those
     grouped together have equal precedence.

     Some notes on patterns:

     Negated character classes _m_a_t_c_h _n_e_w_l_i_n_e_s unless "\n" (or an equivalent
     escape sequence) is one of the characters explicitly present in the
     negated character class (e.g., " [^A-Z\n] ").

     A rule can have at most one instance of trailing context (the '/' opera-
     tor or the '$' operator).	The start condition, '^', and "<<EOF>>" pat-
     terns can only occur at the beginning of a pattern, and, as well as with
     '/' and '$', cannot be grouped inside parentheses.  The following are all
     illegal:

		       foo/bar$
		       foo(bar$)
		       foo^bar
		       <sc1>foo<sc2>bar

SSUUMMMMAARRYY OOFF SSPPEECCIIAALL AACCTTIIOONNSS
     In addition to arbitrary C code, the following can appear in actions:

     EECCHHOO      Copies _y_y_t_e_x_t to the scanner's output.

     BBEEGGIINN     Followed by the name of a start condition places the scanner in
	       the corresponding start condition.

     RREEJJEECCTT    Directs the scanner to proceed on to the "second best" rule
	       which matched the input (or a prefix of the input).  _y_y_t_e_x_t and
	       _y_y_l_e_n_g are set up appropriately.  Note that RREEJJEECCTT is a partic-
	       ularly expensive feature in terms scanner performance; if it is
	       used in _a_n_y of the scanner's actions it will slow down _a_l_l of
	       the scanner's matching.	Furthermore, RREEJJEECCTT cannot be used
	       with the --ff or --FF options.

	       Note also that unlike the other special actions, RREEJJEECCTT is a
	       _b_r_a_n_c_h; code immediately following it in the action will _n_o_t be
	       executed.

     yyyymmoorree()
	       tells the scanner that the next time it matches a rule, the
	       corresponding token should be _a_p_p_e_n_d_e_d onto the current value
	       of _y_y_t_e_x_t rather than replacing it.

     yyyylleessss(_n)
	       returns all but the first _n characters of the current token
	       back to the input stream, where they will be rescanned when the
	       scanner looks for the next match.  _y_y_t_e_x_t and _y_y_l_e_n_g are ad-
	       justed appropriately (e.g., _y_y_l_e_n_g will now be equal to _n).

     uunnppuutt(_c)
	       puts the character _c back onto the input stream.  It will be
	       the next character scanned.

     iinnppuutt()   reads the next character from the input stream (this routine is
	       called yyyyiinnppuutt() if the scanner is compiled using _C ++).

     yyyytteerrmmiinnaattee()
	       can be used in lieu of a return statement in an action.	It
	       terminates the scanner and returns a 0 to the scanner's caller,
	       indicating "all done".

	       By default, yyyytteerrmmiinnaattee() is also called when an end-of-file is
	       encountered.  It is a macro and may be redefined.

     YYYY__NNEEWW__FFIILLEE
	       is an action available only in <<EOF>> rules.  It means "Okay,
	       I've set up a new input file, continue scanning".

     yyyy__ccrreeaattee__bbuuffffeerr(_f_i_l_e, _s_i_z_e)
	       takes a FFIILLEE pointer and an integer _s_i_z_e.  It returns a
	       YY_BUFFER_STATE handle to a new input buffer large enough to
	       accomodate _s_i_z_e characters and associated with the given file.
	       When in doubt, use _Y_Y__B_U_F__S_I_Z_E for the size.

     yyyy__sswwiittcchh__ttoo__bbuuffffeerr(_n_e_w__b_u_f_f_e_r)
	       switches the scanner's processing to scan for tokens from the
	       given buffer, which must be a YY_BUFFER_STATE.

     yyyy__ddeelleettee__bbuuffffeerr(_b_u_f_f_e_r)
	       deletes the given buffer.

VVAALLUUEESS AAVVAAIILLAABBLLEE TTOO TTHHEE UUSSEERR
     _c_h_a_r *_y_y_t_e_x_t
	       holds the text of the current token.  It may not be modified.

     _i_n_t _y_y_l_e_n_g
	       holds the length of the current token.  It may not be modified.

     _F_I_L_E *_y_y_i_n
	       is the file which by default lleexx reads from.  It may be rede-
	       fined but doing so only makes sense before scanning begins.
	       Changing it in the middle of scanning will have unexpected
	       results since lleexx buffers its input.  Once scanning terminates
	       because an end-of-file has been seen,
	       vvooiidd yyyyrreessttaarrtt(_F_I_L_E *_n_e_w__f_i_l_e) may be called to point _y_y_i_n at
	       the new input file.

     _F_I_L_E *_y_y_o_u_t
	       is the file to which _E_C_H_O actions are done.  It can be reas-
	       signed by the user.

     _Y_Y__C_U_R_R_E_N_T__B_U_F_F_E_R
	       returns a YY_BUFFER_STATE handle to the current buffer.

MMAACCRROOSS TTHHEE UUSSEERR CCAANN RREEDDEEFFIINNEE
     _Y_Y__D_E_C_L   controls how the scanning routine is declared.  By default, it
	       is "int yylex()", or, if prototypes are being used, "int
	       yylex(void)".  This definition may be changed by redefining the
	       "YY_DECL" macro.  Note that if you give arguments to the scan-
	       ning routine using a K&R-style/non-prototyped function declara-
	       tion, you must terminate the definition with a semi-colon (;).

     _Y_Y__I_N_P_U_T
	       The nature of how the scanner gets its input can be controlled
	       by redefining the YY_INPUT macro.  YY_INPUT's calling sequence
	       is "YY_INPUT(buf,result,max_size)".  Its action is to place up
	       to _m_a_x __s_i_z_e characters in the character array _b_u_f and return
	       in the integer variable _r_e_s_u_l_t either the number of characters
	       read or the constant YY_NULL (0 on Unix systems) to indicate
	       EOF.  The default YY_INPUT reads from the global file-pointer
	       "yyin".	A sample redefinition of YY_INPUT (in the definitions
	       section of the input file):

		     %{
		     #undef YY_INPUT
		     #define YY_INPUT(buf,result,max_size) \
			 result = ((buf[0] = getchar()) == EOF) ? YY_NULL : 1;
		     %}

     _Y_Y__I_N_P_U_T
	       When the scanner receives an end-of-file indication from
	       YY_INPUT, it then checks the yyyywwrraapp() function.	If yyyywwrraapp()
	       returns false (zero), then it is assumed that the function has
	       gone ahead and set up _y_y_i_n to point to another input file, and
	       scanning continues.  If it returns true (non-zero), then the
	       scanner terminates, returning 0 to its caller.

     _y_y_w_r_a_p    The default yyyywwrraapp() always returns 1.  Presently, to redefine
	       it you must first "#undef yywrap", as it is currently imple-
	       mented as a macro.  It is likely that yyyywwrraapp() will soon be de-
	       fined to be a function rather than a macro.

     _Y_Y__U_S_E_R__A_C_T_I_O_N
	       can be redefined to provide an action which is always executed
	       prior to the matched rule's action.

     _Y_Y__U_S_E_R__I_N_I_T
	       The macro _Y_Y __U_S_E_R__I_N_I_T may be redefined to provide an action
	       which is always executed before the first scan.

     _Y_Y__B_R_E_A_K
	       In the generated scanner, the actions are all gathered in one
	       large switch statement and separated using _Y_Y __B_R_E_A_K, which may
	       be redefined.  By default, it is simply a "break", to separate
	       each rule's action from the following rule's.

FFIILLEESS
     _l_e_x._s_k_e_l	     skeleton scanner.
     _l_e_x._y_y._c	     generated scanner (called _l_e_x_y_y._c on some systems).
     _l_e_x._b_a_c_k_t_r_a_c_k   backtracking information for --bb
     _f_l_a_g	     (called _l_e_x._b_c_k on some systems).


SSEEEE AALLSSOO
     lex(1), yacc(1), sed(1), awk(1).
     _l_e_x_d_o_c
     M.  E.  Lesk and E.  Schmidt, _L_E_X - _L_e_x_i_c_a_l _A_n_a_l_y_z_e_r _G_e_n_e_r_a_t_o_r

DDIIAAGGNNOOSSTTIICCSS
     reject_used_but_not_detected undefined
	       or
     yymore_used_but_not_detected undefined
	       These errors can occur at compile time.	They indicate that the
	       scanner uses RREEJJEECCTT or yyyymmoorree() but that lleexx failed to notice
	       the fact, meaning that lleexx scanned the first two sections look-
	       ing for occurrences of these actions and failed to find any,
	       but somehow you snuck some in  via a #include file, for example
	       .  Make an explicit reference to the action in your lleexx input
	       file.  Note that previously lleexx supported a %used/%unused
	       mechanism for dealing with this problem; this feature is still
	       supported but now deprecated, and will go away soon unless the
	       author hears from people who can argue compellingly that they
	       need it.

     lex scanner jammed
	       a scanner compiled with --ss has encountered an input string
	       which wasn't matched by any of its rules.

     lex input buffer overflowed
	       a scanner rule matched a string long enough to overflow the
	       scanner's internal input buffer	16K bytes - controlled by
	       _Y_Y__B_U_F__M_A_X in _l_e_x._s_k_e_l.

     scanner requires -8 flag
	       Your scanner specification includes recognizing 8-bit charac-
	       ters and you did not specify the -8 flag  and your site has not
	       installed lex with -8 as the default .

     too many %t classes!
	       You managed to put every single character into its own %t
	       class.  LLeexx requires that at least one of the classes share
	       characters.

HHIISSTTOORRYY
     A lleexx appeared in Version 6 AT&T Unix.  The version this man page
     describes is derived from code contributed by Vern Paxson.

AAUUTTHHOORR
     Vern Paxson, with the help of many ideas and much inspiration from Van
     Jacobson.	Original version by Jef Poskanzer.

     See _L_e_x_d_o_c for additional credits and the address to send comments to.

BBUUGGSS
     Some trailing context patterns cannot be properly matched and generate
     warning messages ("Dangerous trailing context").  These are patterns
     where the ending of the first part of the rule matches the beginning of
     the second part, such as "zx*/xy*", where the 'x*' matches the 'x' at the
     beginning of the trailing context.  (Note that the POSIX draft states
     that the text matched by such patterns is undefined.)

     For some trailing context rules, parts which are actually fixed-length
     are not recognized as such, leading to the abovementioned performance
     loss.  In particular, parts using '|' or {n} (such as "foo{3}") are al-
     ways considered variable-length.

     Combining trailing context with the special '|' action can result in
     _f_i_x_e_d trailing context being turned into the more expensive _v_a_r_i_a_b_l_e
     trailing context.	This happens in the following example:

		       %%
		       abc  |
		       xyz/def

     Use of uunnppuutt() invalidates yytext and yyleng.


     Use of uunnppuutt() to push back more text than was matched can result in the
     pushed-back text matching a beginning-of-line ('^') rule even though it
     didn't come at the beginning of the line (though this is rare!).

     Pattern-matching of NUL's is substantially slower than matching other
     characters.

     LLeexx does not generate correct #line directives for code internal to the
     scanner; thus, bugs in _l_e_x._s_k_e_l yield bogus line numbers.

     Due to both buffering of input and read-ahead, you cannot intermix calls
     to <stdio.h> routines, such as, for example, ggeettcchhaarr(), with lleexx rules
     and expect it to work.  Call iinnppuutt() instead.

     The total table entries listed by the --vv flag excludes the number of
     table entries needed to determine what rule has been matched.  The number
     of entries is equal to the number of DFA states if the scanner does not
     use RREEJJEECCTT, and somewhat greater than the number of states if it does.

     RREEJJEECCTT cannot be used with the --ff or --FF options.

     Some of the macros, such as yyyywwrraapp(), may in the future become functions
     which live in the --llffll library.  This will doubtless break a lot of code,
     but may be required for POSIX-compliance.

     The lleexx internal algorithms need documentation.