1993-08-06 23:34:17 +04:00
|
|
|
.\" Copyright (c) 1990 The Regents of the University of California.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the University of
|
|
|
|
.\" California, Berkeley and its contributors.
|
|
|
|
.\" 4. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" from: @(#)lex.1 5.13 (Berkeley) 7/24/91
|
|
|
|
.\" $Id: lex.1,v 1.4 1993/08/06 19:41:44 mycroft Exp $
|
|
|
|
.\"
|
|
|
|
.Dd July 24, 1991
|
|
|
|
.Dt LEX 1
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm lex
|
|
|
|
.Nd fast lexical analyzer generator
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm lex
|
|
|
|
.Oo
|
|
|
|
.Op Fl bcdfinpstvFILT8
|
|
|
|
.Fl C Ns Ns Op Cm efmF
|
|
|
|
.Fl S Ns Ns Ar skeleton
|
|
|
|
.Oc
|
|
|
|
.Op Ar
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
.Nm Lex
|
1993-03-21 12:45:37 +03:00
|
|
|
is a tool for generating
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar scanners :
|
1993-03-21 12:45:37 +03:00
|
|
|
programs which recognized lexical patterns in text.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm Lex
|
1993-03-21 12:45:37 +03:00
|
|
|
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
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em rules .
|
|
|
|
.Nm Lex
|
1993-03-21 12:45:37 +03:00
|
|
|
generates as output a C source file,
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pa lex.yy.c ,
|
1993-03-21 12:45:37 +03:00
|
|
|
which defines a routine
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yylex .
|
1993-03-21 12:45:37 +03:00
|
|
|
This file is compiled and linked with the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl lfl
|
1993-03-21 12:45:37 +03:00
|
|
|
library to produce an executable. When the executable is run,
|
|
|
|
it analyzes its input for occurrences
|
|
|
|
of the regular expressions. Whenever it finds one, it executes
|
|
|
|
the corresponding C code.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
For full documentation, see
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em Lexdoc .
|
1993-03-21 12:45:37 +03:00
|
|
|
This manual entry is intended for use as a quick reference.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Sh OPTIONS
|
|
|
|
.Nm Lex
|
1993-03-21 12:45:37 +03:00
|
|
|
has the following options:
|
1993-08-06 23:34:17 +04:00
|
|
|
.Bl -tag -width Ds
|
|
|
|
.It Fl b
|
1993-03-21 12:45:37 +03:00
|
|
|
Generate backtracking information to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va lex.backtrack .
|
1993-03-21 12:45:37 +03:00
|
|
|
This is a list of scanner states which require backtracking
|
|
|
|
and the input characters on which they do so. By adding rules one
|
|
|
|
can remove backtracking states. If all backtracking states
|
|
|
|
are eliminated and
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl f
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl F
|
1993-03-21 12:45:37 +03:00
|
|
|
is used, the generated scanner will run faster.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl c
|
|
|
|
is a do-nothing, deprecated option included for
|
|
|
|
.Tn POSIX
|
|
|
|
compliance.
|
|
|
|
.Pp
|
|
|
|
.Ar NOTE :
|
1993-03-21 12:45:37 +03:00
|
|
|
in previous releases of
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm Lex
|
|
|
|
.Op Fl c
|
1993-03-21 12:45:37 +03:00
|
|
|
specified table-compression options. This functionality is
|
|
|
|
now given by the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl C
|
1993-03-21 12:45:37 +03:00
|
|
|
flag. To ease the the impact of this change, when
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
encounters
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl c,
|
1993-03-21 12:45:37 +03:00
|
|
|
it currently issues a warning message and assumes that
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl C
|
1993-03-21 12:45:37 +03:00
|
|
|
was desired instead. In the future this "promotion" of
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl c
|
1993-03-21 12:45:37 +03:00
|
|
|
to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl C
|
|
|
|
will go away in the name of full
|
|
|
|
.Tn POSIX
|
|
|
|
compliance (unless
|
|
|
|
the
|
|
|
|
.Tn POSIX
|
|
|
|
meaning is removed first).
|
|
|
|
.It Fl d
|
|
|
|
Makes the generated scanner run in
|
|
|
|
.Ar debug
|
1993-03-21 12:45:37 +03:00
|
|
|
mode. Whenever a pattern is recognized and the global
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yy_Lex_debug
|
1993-03-21 12:45:37 +03:00
|
|
|
is non-zero (which is the default), the scanner will
|
|
|
|
write to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Li stderr
|
1993-03-21 12:45:37 +03:00
|
|
|
a line of the form:
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
|
|
|
.Dl --accepting rule at line 53 ("the matched text")
|
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
The line number refers to the location of the rule in the file
|
1993-08-06 23:34:17 +04:00
|
|
|
defining the scanner (i.e., the file that was fed to lex). Messages
|
1993-03-21 12:45:37 +03:00
|
|
|
are also generated when the scanner backtracks, accepts the
|
|
|
|
default rule, reaches the end of its input buffer (or encounters
|
1993-08-06 23:34:17 +04:00
|
|
|
a
|
|
|
|
.Tn NUL ;
|
|
|
|
the two look the same as far as the scanner's concerned),
|
1993-03-21 12:45:37 +03:00
|
|
|
or reaches an end-of-file.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl f
|
|
|
|
Specifies (take your pick)
|
|
|
|
.Em full table
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em fast scanner .
|
1993-03-21 12:45:37 +03:00
|
|
|
No table compression is done. The result is large but fast.
|
|
|
|
This option is equivalent to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl Cf
|
1993-03-21 12:45:37 +03:00
|
|
|
(see below).
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl i
|
|
|
|
Instructs
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
to generate a
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em case-insensitive
|
1993-03-21 12:45:37 +03:00
|
|
|
scanner. The case of letters given in the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
input patterns will
|
|
|
|
be ignored, and tokens in the input will be matched regardless of case. The
|
|
|
|
matched text given in
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yytext
|
1993-03-21 12:45:37 +03:00
|
|
|
will have the preserved case (i.e., it will not be folded).
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl n
|
|
|
|
Is another do-nothing, deprecated option included only for
|
|
|
|
.Tn POSIX
|
|
|
|
compliance.
|
|
|
|
.It Fl p
|
|
|
|
Generates a performance report to stderr. The report
|
1993-03-21 12:45:37 +03:00
|
|
|
consists of comments regarding features of the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
input file which will cause a loss of performance in the resulting scanner.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl s
|
|
|
|
Causes the
|
|
|
|
.Ar default rule
|
1993-03-21 12:45:37 +03:00
|
|
|
(that unmatched scanner input is echoed to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar stdout )
|
1993-03-21 12:45:37 +03:00
|
|
|
to be suppressed. If the scanner encounters input that does not
|
|
|
|
match any of its rules, it aborts with an error.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl t
|
|
|
|
Instructs
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
to write the scanner it generates to standard output instead
|
|
|
|
of
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pa lex.yy.c .
|
|
|
|
.It Fl v
|
|
|
|
Specifies that
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
should write to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Li stderr
|
1993-03-21 12:45:37 +03:00
|
|
|
a summary of statistics regarding the scanner it generates.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl F
|
|
|
|
Specifies that the
|
|
|
|
.Em fast
|
1993-03-21 12:45:37 +03:00
|
|
|
scanner table representation should be used. This representation is
|
|
|
|
about as fast as the full table representation
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pq Fl f ,
|
1993-03-21 12:45:37 +03:00
|
|
|
and for some sets of patterns will be considerably smaller (and for
|
|
|
|
others, larger). See
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em Lexdoc
|
1993-03-21 12:45:37 +03:00
|
|
|
for details.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
This option is equivalent to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl CF
|
1993-03-21 12:45:37 +03:00
|
|
|
(see below).
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl I
|
|
|
|
Instructs
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
to generate an
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em interactive
|
1993-03-21 12:45:37 +03:00
|
|
|
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
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em Lexdoc
|
1993-03-21 12:45:37 +03:00
|
|
|
for details.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
Note,
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl I
|
1993-03-21 12:45:37 +03:00
|
|
|
cannot be used in conjunction with
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em full
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em fast tables ,
|
1993-03-21 12:45:37 +03:00
|
|
|
i.e., the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl f , F , Cf ,
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl CF
|
1993-03-21 12:45:37 +03:00
|
|
|
flags.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl L
|
|
|
|
Instructs
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
not to generate
|
1993-08-06 23:34:17 +04:00
|
|
|
.Li #line
|
1993-03-21 12:45:37 +03:00
|
|
|
directives in
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pa lex.yy.c .
|
1993-03-21 12:45:37 +03:00
|
|
|
The default is to generate such directives so error
|
|
|
|
messages in the actions will be correctly
|
|
|
|
located with respect to the original
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
input file, and not to
|
|
|
|
the fairly meaningless line numbers of
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pa lex.yy.c .
|
|
|
|
.It Fl T
|
|
|
|
Makes
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
run in
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em trace
|
1993-03-21 12:45:37 +03:00
|
|
|
mode. It will generate a lot of messages to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Li stdout
|
1993-03-21 12:45:37 +03:00
|
|
|
concerning
|
|
|
|
the form of the input and the resultant non-deterministic and deterministic
|
|
|
|
finite automata. This option is mostly for use in maintaining
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex .
|
|
|
|
.It Fl 8
|
|
|
|
Instructs
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
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
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pq Fl v
|
1993-03-21 12:45:37 +03:00
|
|
|
output for "equivalence classes created". If the denominator of
|
|
|
|
the number shown is 128, then by default
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
is generating 7-bit characters. If it is 256, then the default is
|
|
|
|
8-bit characters.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl C Ns Op Cm efmF
|
|
|
|
Controls the degree of table compression. The default setting is
|
|
|
|
.Fl Cem .
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width Ds
|
|
|
|
.It Fl C
|
|
|
|
A lone
|
|
|
|
.Fl C
|
|
|
|
specifies that the scanner tables should be compressed but neither
|
|
|
|
equivalence classes nor meta-equivalence classes should be used.
|
|
|
|
.It Fl \&Ce
|
|
|
|
Directs
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
to construct
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em equivalence classes ,
|
1993-03-21 12:45:37 +03:00
|
|
|
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).
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl \&Cf
|
|
|
|
Specifies that the
|
|
|
|
.Em full
|
1993-03-21 12:45:37 +03:00
|
|
|
scanner tables should be generated -
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
should not compress the
|
|
|
|
tables by taking advantages of similar transition functions for
|
|
|
|
different states.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl \&CF
|
|
|
|
Specifies that the alternate fast scanner representation (described in
|
|
|
|
.Em Lexdoc )
|
1993-03-21 12:45:37 +03:00
|
|
|
should be used.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl \&Cm
|
|
|
|
Directs
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
to construct
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em meta-equivalence classes ,
|
1993-03-21 12:45:37 +03:00
|
|
|
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 impact (one or two "if" tests and one
|
|
|
|
array look-up per character scanned).
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl Cem
|
|
|
|
(Default)
|
|
|
|
Generate both equivalence classes
|
|
|
|
and meta-equivalence classes. This setting provides the highest
|
|
|
|
degree of table compression.
|
|
|
|
.El
|
|
|
|
.Pp
|
|
|
|
Faster-executing scanners can be traded off at the
|
|
|
|
cost of larger tables with
|
|
|
|
the following generally being true:
|
|
|
|
.Bd -ragged -offset center
|
|
|
|
slowest & smallest
|
|
|
|
-Cem
|
|
|
|
-Cm
|
|
|
|
-Ce
|
|
|
|
-C
|
|
|
|
-C{f,F}e
|
|
|
|
-C{f,F}
|
|
|
|
fastest & largest
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Fl C
|
|
|
|
options are not cumulative; whenever the flag is encountered, the
|
|
|
|
previous -C settings are forgotten.
|
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
The options
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl \&Cf
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl \&CF
|
1993-03-21 12:45:37 +03:00
|
|
|
and
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl \&Cm
|
1993-03-21 12:45:37 +03:00
|
|
|
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.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fl S Ns Ar skeleton_file
|
|
|
|
Overrides the default skeleton file from which
|
|
|
|
.Nm lex
|
|
|
|
constructs its scanners. Useful for
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
maintenance or development.
|
1993-08-06 23:34:17 +04:00
|
|
|
.El
|
|
|
|
.Sh SUMMARY OF LEX REGULAR EXPRESSIONS
|
1993-03-21 12:45:37 +03:00
|
|
|
The patterns in the input are written using an extended set of regular
|
|
|
|
expressions. These are:
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
|
|
|
.Bl -tag -width 10n -compact
|
|
|
|
.It Li x
|
|
|
|
Match the character 'x'.
|
|
|
|
.It Li \&.
|
|
|
|
Any character except newline.
|
|
|
|
.It Op Li xyz
|
|
|
|
A "character class"; in this case, the pattern
|
|
|
|
matches either an 'x', a 'y', or a 'z'.
|
|
|
|
.It Op Li abj-oZ
|
|
|
|
A "character class" with a range in it; matches
|
|
|
|
an 'a', a 'b', any letter from 'j' through 'o',
|
|
|
|
or a 'Z'.
|
|
|
|
.It Op Li ^A-Z
|
|
|
|
A "negated character class", i.e., any character
|
|
|
|
but those in the class. In this case, any
|
|
|
|
character
|
|
|
|
.Em except
|
|
|
|
an uppercase letter.
|
|
|
|
.It Op Li ^A-Z\en
|
|
|
|
Any character
|
|
|
|
.Em except
|
|
|
|
an uppercase letter or
|
|
|
|
a newline.
|
|
|
|
.It Li r*
|
|
|
|
Zero or more r's, where r is any regular expression.
|
|
|
|
.It Li r+
|
|
|
|
One or more r's.
|
|
|
|
.It Li r?
|
|
|
|
Zero or one r's (that is, "an optional r").
|
|
|
|
.It Li r{2,5}
|
|
|
|
Anywhere from two to five r's.
|
|
|
|
.It Li r{2,}
|
|
|
|
Two or more r's.
|
|
|
|
.It Li r{4}
|
|
|
|
Exactly 4 r's.
|
|
|
|
.It Li {name}
|
|
|
|
The expansion of the "name" definition
|
|
|
|
(see above).
|
|
|
|
.It Xo
|
|
|
|
.Oo Li xyz Oc Ns Li "\e\&\*qfoo"
|
|
|
|
.Xc
|
|
|
|
The literal string:
|
|
|
|
[xyz]\*qfoo.
|
|
|
|
.It Li \&\eX
|
|
|
|
If X is an 'a', 'b', 'f', 'n', 'r', 't', or 'v',
|
|
|
|
then the
|
|
|
|
.Tn ANSI-C
|
|
|
|
interpretation of \ex.
|
|
|
|
Otherwise, a literal 'X' (used to escape
|
|
|
|
operators such as '*').
|
|
|
|
.It Li \&\e123
|
|
|
|
The character with octal value 123.
|
|
|
|
.It Li \&\ex2a
|
|
|
|
The character with hexadecimal value 2a.
|
|
|
|
.It Li (r)
|
|
|
|
Match an r; parentheses are used to override
|
|
|
|
precedence (see below).
|
|
|
|
.It Li rs
|
|
|
|
The regular expression r followed by the
|
|
|
|
regular expression s; called "concatenation".
|
|
|
|
.It Li rs
|
|
|
|
Either an r or an s.
|
|
|
|
.It Li 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".
|
|
|
|
.It Li \&^r
|
|
|
|
An r, but only at the beginning of a line.
|
|
|
|
.It Li r$
|
|
|
|
An r, but only at the end of a line. Equivalent
|
|
|
|
to "r/\en".
|
|
|
|
.It Li <s>r
|
|
|
|
An r, but only in start condition s (see
|
|
|
|
below for discussion of start conditions).
|
|
|
|
.It Li <s1,s2,s3>r
|
|
|
|
Same, but in any of start conditions s1,
|
|
|
|
s2, or s3.
|
|
|
|
.It Li <<EOF>>
|
|
|
|
An end-of-file.
|
|
|
|
.It Li <s1,s2><<EOF>>
|
|
|
|
An end-of-file when in start condition s1 or s2.
|
|
|
|
.El
|
1993-03-21 12:45:37 +03:00
|
|
|
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.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
Some notes on patterns:
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
Negated character classes
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar match newlines
|
|
|
|
unless "\en" (or an equivalent escape sequence) is one of the
|
1993-03-21 12:45:37 +03:00
|
|
|
characters explicitly present in the negated character class
|
1993-08-06 23:34:17 +04:00
|
|
|
(e.g., " [^A-Z\en] ").
|
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
A rule can have at most one instance of trailing context (the '/' operator
|
|
|
|
or the '$' operator). The start condition, '^', and "<<EOF>>" patterns
|
|
|
|
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:
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
foo/bar$
|
|
|
|
foo(bar$)
|
|
|
|
foo^bar
|
|
|
|
<sc1>foo<sc2>bar
|
|
|
|
.Ed
|
|
|
|
.Sh SUMMARY OF SPECIAL ACTIONS
|
1993-03-21 12:45:37 +03:00
|
|
|
In addition to arbitrary C code, the following can appear in actions:
|
1993-08-06 23:34:17 +04:00
|
|
|
.Bl -tag -width Fl
|
|
|
|
.It Ic ECHO
|
|
|
|
Copies
|
|
|
|
.Va yytext
|
|
|
|
to the scanner's output.
|
|
|
|
.It Ic BEGIN
|
|
|
|
Followed by the name of a start condition places the scanner in the
|
1993-03-21 12:45:37 +03:00
|
|
|
corresponding start condition.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Ic REJECT
|
|
|
|
Directs the scanner to proceed on to the "second best" rule which matched the
|
1993-03-21 12:45:37 +03:00
|
|
|
input (or a prefix of the input).
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yytext
|
1993-03-21 12:45:37 +03:00
|
|
|
and
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yyleng
|
1993-03-21 12:45:37 +03:00
|
|
|
are set up appropriately. Note that
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ic REJECT
|
1993-03-21 12:45:37 +03:00
|
|
|
is a particularly expensive feature in terms scanner performance;
|
|
|
|
if it is used in
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em any
|
1993-03-21 12:45:37 +03:00
|
|
|
of the scanner's actions it will slow down
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em all
|
1993-03-21 12:45:37 +03:00
|
|
|
of the scanner's matching. Furthermore,
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ic REJECT
|
1993-03-21 12:45:37 +03:00
|
|
|
cannot be used with the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl f
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl F
|
1993-03-21 12:45:37 +03:00
|
|
|
options.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
Note also that unlike the other special actions,
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ic REJECT
|
1993-03-21 12:45:37 +03:00
|
|
|
is a
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em branch ;
|
1993-03-21 12:45:37 +03:00
|
|
|
code immediately following it in the action will
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em not
|
1993-03-21 12:45:37 +03:00
|
|
|
be executed.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fn yymore
|
1993-03-21 12:45:37 +03:00
|
|
|
tells the scanner that the next time it matches a rule, the corresponding
|
|
|
|
token should be
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em appended
|
1993-03-21 12:45:37 +03:00
|
|
|
onto the current value of
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yytext
|
1993-03-21 12:45:37 +03:00
|
|
|
rather than replacing it.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fn yyless \&n
|
1993-03-21 12:45:37 +03:00
|
|
|
returns all but the first
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar n
|
1993-03-21 12:45:37 +03:00
|
|
|
characters of the current token back to the input stream, where they
|
|
|
|
will be rescanned when the scanner looks for the next match.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yytext
|
1993-03-21 12:45:37 +03:00
|
|
|
and
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yyleng
|
1993-03-21 12:45:37 +03:00
|
|
|
are adjusted appropriately (e.g.,
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yyleng
|
1993-03-21 12:45:37 +03:00
|
|
|
will now be equal to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar n ) .
|
|
|
|
.It Fn unput c
|
1993-03-21 12:45:37 +03:00
|
|
|
puts the character
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar c
|
1993-03-21 12:45:37 +03:00
|
|
|
back onto the input stream. It will be the next character scanned.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fn input
|
1993-03-21 12:45:37 +03:00
|
|
|
reads the next character from the input stream (this routine is called
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yyinput
|
1993-03-21 12:45:37 +03:00
|
|
|
if the scanner is compiled using
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em C \&+\&+ ) .
|
|
|
|
.It Fn yyterminate
|
1993-03-21 12:45:37 +03:00
|
|
|
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".
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
By default,
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yyterminate
|
1993-03-21 12:45:37 +03:00
|
|
|
is also called when an end-of-file is encountered. It is a macro and
|
|
|
|
may be redefined.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Ic YY_NEW_FILE
|
1993-03-21 12:45:37 +03:00
|
|
|
is an action available only in <<EOF>> rules. It means "Okay, I've
|
|
|
|
set up a new input file, continue scanning".
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fn yy_create_buffer file size
|
1993-03-21 12:45:37 +03:00
|
|
|
takes a
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ic FILE
|
1993-03-21 12:45:37 +03:00
|
|
|
pointer and an integer
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar size .
|
1993-03-21 12:45:37 +03:00
|
|
|
It returns a YY_BUFFER_STATE
|
|
|
|
handle to a new input buffer large enough to accomodate
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar size
|
1993-03-21 12:45:37 +03:00
|
|
|
characters and associated with the given file. When in doubt, use
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar YY_BUF_SIZE
|
1993-03-21 12:45:37 +03:00
|
|
|
for the size.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fn yy_switch_to_buffer new_buffer
|
1993-03-21 12:45:37 +03:00
|
|
|
switches the scanner's processing to scan for tokens from
|
|
|
|
the given buffer, which must be a YY_BUFFER_STATE.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Fn yy_delete_buffer buffer
|
1993-03-21 12:45:37 +03:00
|
|
|
deletes the given buffer.
|
1993-08-06 23:34:17 +04:00
|
|
|
.El
|
|
|
|
.Sh VALUES AVAILABLE TO THE USER
|
|
|
|
.Bl -tag -width Fl
|
|
|
|
.It Va char \&*yytext
|
1993-03-21 12:45:37 +03:00
|
|
|
holds the text of the current token. It may not be modified.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va int yyleng
|
1993-03-21 12:45:37 +03:00
|
|
|
holds the length of the current token. It may not be modified.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va FILE \&*yyin
|
1993-03-21 12:45:37 +03:00
|
|
|
is the file which by default
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
reads from. It may be redefined but doing so only makes sense before
|
|
|
|
scanning begins. Changing it in the middle of scanning will have
|
|
|
|
unexpected results since
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
buffers its input. Once scanning terminates because an end-of-file
|
|
|
|
has been seen,
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn "void yyrestart" "FILE *new_file"
|
1993-03-21 12:45:37 +03:00
|
|
|
may be called to point
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yyin
|
1993-03-21 12:45:37 +03:00
|
|
|
at the new input file.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va FILE \&*yyout
|
1993-03-21 12:45:37 +03:00
|
|
|
is the file to which
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar ECHO
|
1993-03-21 12:45:37 +03:00
|
|
|
actions are done. It can be reassigned by the user.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va YY_CURRENT_BUFFER
|
1993-03-21 12:45:37 +03:00
|
|
|
returns a
|
1993-08-06 23:34:17 +04:00
|
|
|
YY_BUFFER_STATE
|
1993-03-21 12:45:37 +03:00
|
|
|
handle to the current buffer.
|
1993-08-06 23:34:17 +04:00
|
|
|
.El
|
|
|
|
.Sh MACROS THE USER CAN REDEFINE
|
|
|
|
.Bl -tag -width Fl
|
|
|
|
.It Va YY_DECL
|
1993-03-21 12:45:37 +03:00
|
|
|
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 scanning routine using a
|
|
|
|
K&R-style/non-prototyped function declaration, you must terminate
|
|
|
|
the definition with a semi-colon (;).
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va YY_INPUT
|
1993-03-21 12:45:37 +03:00
|
|
|
The nature of how the scanner
|
|
|
|
gets its input can be controlled by redefining the
|
1993-08-06 23:34:17 +04:00
|
|
|
YY_INPUT
|
1993-03-21 12:45:37 +03:00
|
|
|
macro.
|
|
|
|
YY_INPUT's calling sequence is "YY_INPUT(buf,result,max_size)". Its
|
|
|
|
action is to place up to
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar max _size
|
1993-03-21 12:45:37 +03:00
|
|
|
characters in the character array
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar buf
|
1993-03-21 12:45:37 +03:00
|
|
|
and return in the integer variable
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ar result
|
1993-03-21 12:45:37 +03:00
|
|
|
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):
|
1993-08-06 23:34:17 +04:00
|
|
|
.Bd -literal -offset indent
|
|
|
|
%{
|
|
|
|
#undef YY_INPUT
|
|
|
|
#define YY_INPUT(buf,result,max_size) \e
|
|
|
|
result = ((buf[0] = getchar()) == EOF) ? YY_NULL : 1;
|
|
|
|
%}
|
|
|
|
.Ed
|
|
|
|
.It Va YY_INPUT
|
1993-03-21 12:45:37 +03:00
|
|
|
When the scanner receives an end-of-file indication from YY_INPUT,
|
|
|
|
it then checks the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yywrap
|
1993-03-21 12:45:37 +03:00
|
|
|
function. If
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yywrap
|
1993-03-21 12:45:37 +03:00
|
|
|
returns false (zero), then it is assumed that the
|
|
|
|
function has gone ahead and set up
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va yyin
|
1993-03-21 12:45:37 +03:00
|
|
|
to point to another input file, and scanning continues. If it returns
|
|
|
|
true (non-zero), then the scanner terminates, returning 0 to its
|
|
|
|
caller.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va yywrap
|
1993-03-21 12:45:37 +03:00
|
|
|
The default
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yywrap
|
1993-03-21 12:45:37 +03:00
|
|
|
always returns 1. Presently, to redefine it you must first
|
|
|
|
"#undef yywrap", as it is currently implemented as a macro. It is
|
|
|
|
likely that
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yywrap
|
1993-03-21 12:45:37 +03:00
|
|
|
will soon be defined to be a function rather than a macro.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va YY_USER_ACTION
|
1993-03-21 12:45:37 +03:00
|
|
|
can be redefined to provide an action
|
|
|
|
which is always executed prior to the matched rule's action.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va YY_USER_INIT
|
1993-03-21 12:45:37 +03:00
|
|
|
The macro
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va YY _USER_INIT
|
1993-03-21 12:45:37 +03:00
|
|
|
may be redefined to provide an action which is always executed before
|
|
|
|
the first scan.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Va YY_BREAK
|
1993-03-21 12:45:37 +03:00
|
|
|
In the generated scanner, the actions are all gathered in one large
|
|
|
|
switch statement and separated using
|
1993-08-06 23:34:17 +04:00
|
|
|
.Va YY _BREAK ,
|
1993-03-21 12:45:37 +03:00
|
|
|
which may be redefined. By default, it is simply a "break", to separate
|
|
|
|
each rule's action from the following rule's.
|
1993-08-06 23:34:17 +04:00
|
|
|
.El
|
|
|
|
.Sh FILES
|
|
|
|
.Bl -tag -width lex.backtrack -compact
|
|
|
|
.It Pa lex.skel
|
1993-03-21 12:45:37 +03:00
|
|
|
skeleton scanner.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Pa lex.yy.c
|
|
|
|
generated scanner
|
|
|
|
(called
|
|
|
|
.Pa lexyy.c
|
1993-03-21 12:45:37 +03:00
|
|
|
on some systems).
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Pa lex.backtrack
|
1993-03-21 12:45:37 +03:00
|
|
|
backtracking information for
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl b
|
|
|
|
.It Pa flag
|
|
|
|
(called
|
|
|
|
.Pa lex.bck
|
1993-03-21 12:45:37 +03:00
|
|
|
on some systems).
|
1993-08-06 23:34:17 +04:00
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr lex 1 ,
|
|
|
|
.Xr yacc 1 ,
|
|
|
|
.Xr sed 1 ,
|
|
|
|
.Xr awk 1 .
|
|
|
|
.Rs
|
|
|
|
.%T "lexdoc"
|
|
|
|
.Re
|
|
|
|
.Rs
|
|
|
|
.%A M. E. Lesk
|
|
|
|
.%A E. Schmidt
|
|
|
|
.%T "LEX \- Lexical Analyzer Generator"
|
|
|
|
.Re
|
|
|
|
.Sh DIAGNOSTICS
|
|
|
|
.Bl -tag -width Fl
|
|
|
|
.It Li reject_used_but_not_detected undefined
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Li yymore_used_but_not_detected undefined
|
|
|
|
These errors can occur at compile time.
|
|
|
|
They indicate that the
|
1993-03-21 12:45:37 +03:00
|
|
|
scanner uses
|
1993-08-06 23:34:17 +04:00
|
|
|
.Ic REJECT
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yymore
|
1993-03-21 12:45:37 +03:00
|
|
|
but that
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
|
|
|
failed to notice the fact,
|
|
|
|
meaning that
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
scanned the first two sections looking for occurrences of these actions
|
1993-08-06 23:34:17 +04:00
|
|
|
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
|
|
|
|
.Nm lex
|
|
|
|
input file.
|
|
|
|
Note that previously
|
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
supported a
|
1993-08-06 23:34:17 +04:00
|
|
|
.Li %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.
|
|
|
|
.It Li lex scanner jammed
|
1993-03-21 12:45:37 +03:00
|
|
|
a scanner compiled with
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl s
|
1993-03-21 12:45:37 +03:00
|
|
|
has encountered an input string which wasn't matched by
|
|
|
|
any of its rules.
|
1993-08-06 23:34:17 +04:00
|
|
|
.It Li lex input buffer overflowed
|
1993-03-21 12:45:37 +03:00
|
|
|
a scanner rule matched a string long enough to overflow the
|
1993-08-06 23:34:17 +04:00
|
|
|
scanner's internal input buffer 16K bytes - controlled by
|
|
|
|
.Va YY_BUF_MAX
|
|
|
|
in
|
|
|
|
.Pa lex.skel .
|
|
|
|
.It Li scanner requires \&\-8 flag
|
1993-03-21 12:45:37 +03:00
|
|
|
Your scanner specification includes recognizing 8-bit characters and
|
1993-08-06 23:34:17 +04:00
|
|
|
you did not specify the -8 flag and your site has not installed lex
|
|
|
|
with -8 as the default .
|
|
|
|
.It Li too many \&%t classes!
|
1993-03-21 12:45:37 +03:00
|
|
|
You managed to put every single character into its own %t class.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm Lex
|
1993-03-21 12:45:37 +03:00
|
|
|
requires that at least one of the classes share characters.
|
1993-08-06 23:34:17 +04:00
|
|
|
.El
|
|
|
|
.Sh HISTORY
|
|
|
|
A
|
|
|
|
.Nm lex
|
|
|
|
appeared in
|
|
|
|
.At v6 .
|
|
|
|
The version this man page describes is
|
|
|
|
derived from code contributed by Vern Paxson.
|
|
|
|
.Sh AUTHOR
|
1993-03-21 12:45:37 +03:00
|
|
|
Vern Paxson, with the help of many ideas and much inspiration from
|
|
|
|
Van Jacobson. Original version by Jef Poskanzer.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
|
|
|
See
|
|
|
|
.%T "Lexdoc"
|
|
|
|
for additional credits and the address to send comments to.
|
|
|
|
.Sh BUGS
|
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
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
|
1993-08-06 23:34:17 +04:00
|
|
|
the beginning of the trailing context. (Note that the
|
|
|
|
.Tn POSIX
|
|
|
|
draft
|
1993-03-21 12:45:37 +03:00
|
|
|
states that the text matched by such patterns is undefined.)
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
For some trailing context rules, parts which are actually fixed-length are
|
|
|
|
not recognized as such, leading to the abovementioned performance loss.
|
1993-08-06 23:34:17 +04:00
|
|
|
In particular, parts using '\&|' or {n} (such as "foo{3}") are always
|
1993-03-21 12:45:37 +03:00
|
|
|
considered variable-length.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
|
|
|
Combining trailing context with the special '\&|' action can result in
|
|
|
|
.Em fixed
|
1993-03-21 12:45:37 +03:00
|
|
|
trailing context being turned into the more expensive
|
1993-08-06 23:34:17 +04:00
|
|
|
.Em variable
|
|
|
|
trailing context. This happens in the following example:
|
|
|
|
.Bd -literal -offset indent
|
|
|
|
%%
|
|
|
|
abc \&|
|
|
|
|
xyz/def
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
Use of
|
|
|
|
.Fn unput
|
|
|
|
invalidates yytext and yyleng.
|
|
|
|
.Pp
|
|
|
|
Use of
|
|
|
|
.Fn unput
|
|
|
|
to push back more text than was matched can
|
1993-03-21 12:45:37 +03:00
|
|
|
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!).
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
|
|
|
Pattern-matching of
|
|
|
|
.Tn NUL Ns 's
|
|
|
|
is substantially slower than matching other
|
1993-03-21 12:45:37 +03:00
|
|
|
characters.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
|
|
|
.Nm Lex
|
1993-03-21 12:45:37 +03:00
|
|
|
does not generate correct #line directives for code internal
|
|
|
|
to the scanner; thus, bugs in
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pa lex.skel
|
1993-03-21 12:45:37 +03:00
|
|
|
yield bogus line numbers.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
Due to both buffering of input and read-ahead, you cannot intermix
|
1993-08-06 23:34:17 +04:00
|
|
|
calls to
|
|
|
|
.Aq Pa stdio.h
|
|
|
|
routines, such as, for example,
|
|
|
|
.Fn getchar ,
|
1993-03-21 12:45:37 +03:00
|
|
|
with
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
rules and expect it to work. Call
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn input
|
1993-03-21 12:45:37 +03:00
|
|
|
instead.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
The total table entries listed by the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl v
|
1993-03-21 12:45:37 +03:00
|
|
|
flag excludes the number of table entries needed to determine
|
|
|
|
what rule has been matched. The number of entries is equal
|
1993-08-06 23:34:17 +04:00
|
|
|
to the number of
|
|
|
|
.Tn DFA
|
|
|
|
states if the scanner does not use
|
|
|
|
.Ic REJECT ,
|
1993-03-21 12:45:37 +03:00
|
|
|
and somewhat greater than the number of states if it does.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
|
|
|
.Ic REJECT
|
1993-03-21 12:45:37 +03:00
|
|
|
cannot be used with the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl f
|
1993-03-21 12:45:37 +03:00
|
|
|
or
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl F
|
1993-03-21 12:45:37 +03:00
|
|
|
options.
|
1993-08-06 23:34:17 +04:00
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
Some of the macros, such as
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fn yywrap ,
|
1993-03-21 12:45:37 +03:00
|
|
|
may in the future become functions which live in the
|
1993-08-06 23:34:17 +04:00
|
|
|
.Fl lfl
|
1993-03-21 12:45:37 +03:00
|
|
|
library. This will doubtless break a lot of code, but may be
|
1993-08-06 23:34:17 +04:00
|
|
|
required for
|
|
|
|
.Tn POSIX Ns \-compliance .
|
|
|
|
.Pp
|
1993-03-21 12:45:37 +03:00
|
|
|
The
|
1993-08-06 23:34:17 +04:00
|
|
|
.Nm lex
|
1993-03-21 12:45:37 +03:00
|
|
|
internal algorithms need documentation.
|