📄 flex.1
字号:
.TH LEX 1 "January 1994" "Version 2.4".SH NAMElex \- fast lexical analyzer generator.SH SYNOPSIS.B lex.B [\-bcdfhilnpstvwBFILTV78 \-C[aefFmr] \-Pprefix \-Sskeleton].I [filename ...].SH DESCRIPTION.I lexis a tool for generating.I scanners:programs which recognized lexical patterns in text..I lexreadsthe given input files, or its standard input if no file names are given,for a description of a scanner to generate. The description is inthe form of pairsof regular expressions and C code, called.I rules. lexgenerates as output a C source file,.B lex.yy.c,which defines a routine.B yylex().This file is compiled and linked with the.B \-lllibrary to produce an executable. When the executable is run,it analyzes its input for occurrencesof the regular expressions. Whenever it finds one, it executesthe corresponding C code..PPFor full documentation, see.B lexdoc(1).This manual entry is intended for use as a quick reference..SH OPTIONS.I lexhas the following options:.TP.B \-bgenerate backing-up information to.I lex.backup.This is a list of scanner states which require backing up and the inputcharacters on which they do so. By adding rules one can removebacking-up states. If all backing-up states are eliminated and.B \-Cfor.B \-CFis used, the generated scanner will run faster..TP.B \-cis a do-nothing, deprecated option included for POSIX compliance..IP.B NOTE:in previous releases of.I lex.B \-cspecified table-compression options. This functionality isnow given by the.B \-Cflag. To ease the the impact of this change, when.I lexencounters.B \-c,it currently issues a warning message and assumes that.B \-Cwas desired instead. In the future this "promotion" of.B \-cto.B \-Cwill go away in the name of full POSIX compliance (unlessthe POSIX meaning is removed first)..TP.B \-dmakes the generated scanner run in.I debugmode. Whenever a pattern is recognized and the global.B yy_flex_debugis non-zero (which is the default), the scanner willwrite to.I stderra line of the form:.nf --accepting rule at line 53 ("the matched text").fiThe line number refers to the location of the rule in the filedefining the scanner (i.e., the file that was fed to lex). Messagesare also generated when the scanner backs up, accepts thedefault rule, reaches the end of its input buffer (or encountersa NUL; the two look the same as far as the scanner's concerned),or reaches an end-of-file..TP.B \-fspecifies.I fast scanner.No table compression is done and stdio is bypassed.The result is large but fast. This option is equivalent to.B \-Cfr(see below)..TP.B \-hgenerates a "help" summary of.I lex'soptions to.I stderr and then exits..TP.B \-iinstructs.I lexto generate a.I case-insensitivescanner. The case of letters given in the.I lexinput patterns willbe ignored, and tokens in the input will be matched regardless of case. Thematched text given in.I yytextwill have the preserved case (i.e., it will not be folded)..TP.B \-lturns on maximum compatibility with the original AT&T lex implementation,at a considerable performance cost. This option is incompatible with.B \-f, \-F, \-Cf,or.B \-CF.See.I lexdoc(1)for details..TP.B \-nis another do-nothing, deprecated option included only forPOSIX compliance..TP.B \-pgenerates a performance report to stderr. The reportconsists of comments regarding features of the.I lexinput file which will cause a loss of performance in the resulting scanner.If you give the flag twice, you will also get comments regardingfeatures that lead to minor performance losses..TP.B \-scauses the.I default rule(that unmatched scanner input is echoed to.I stdout)to be suppressed. If the scanner encounters input that does notmatch any of its rules, it aborts with an error..TP.B \-tinstructs.I lexto write the scanner it generates to standard output insteadof.B lex.yy.c..TP.B \-vspecifies that.I lexshould write to.I stderra summary of statistics regarding the scanner it generates..TP.B \-wsuppresses warning messages..TP.B \-Binstructs.I lexto generate a.I batchscanner instead of an.I interactivescanner (see.B \-Ibelow). See.I lexdoc(1)for details. Scanners using.B \-Cfor.B \-CFcompression options automatically specify this option, too..TP.B \-Fspecifies that the.ulfastscanner table representation should be used (and stdio bypassed).This representation is about as fast as the full table representation.B (-f),and for some sets of patterns will be considerably smaller (and forothers, larger). See.B lexdoc(1)for more details..IPThis option is equivalent to.B \-CFr(see below)..TP.B \-Iinstructs.I lexto generate an.I interactivescanner, that is, a scanner which stops immediately rather thanlooking ahead if it knowsthat the currently scanned text cannot be part of a longer rule's match.This is the opposite of.I batchscanners (see.B \-Babove). See.B lexdoc(1)for details..IPNote,.B \-Icannot be used in conjunction with.I fullor.I fast tables,i.e., the.B \-f, \-F, \-Cf,or.B \-CFflags. For other table compression options,.B \-Iis the default..TP.B \-Linstructs.I lexnot to generate.B #linedirectives in.B lex.yy.c.The default is to generate such directives so errormessages in the actions will be correctlylocated with respect to the original.I lexinput file, and not tothe fairly meaningless line numbers of.B lex.yy.c..TP.B \-Tmakes.I lexrun in.I tracemode. It will generate a lot of messages to.I stderrconcerningthe form of the input and the resultant non-deterministic and deterministicfinite automata. This option is mostly for use in maintaining.I lex..TP.B \-Vprints the version number to.I stderrand exits..TP.B \-7instructs.I lexto generate a 7-bit scanner, which can save considerable table space,especially when using.B \-Cfor.B \-CF(and, at most sites,.B \-7is on by default for these options. To see if this is the case, use the.B -vverbose flag and check the flag summary it reports)..TP.B \-8instructs.I lexto generate an 8-bit scanner. This is the default except for the.B \-Cfand.B \-CFcompression options, for which the default is site-dependent, andcan be checked by inspecting the flag summary generated by the.B \-voption..TP .B \-C[aefFmr]controls the degree of table compression and scanner optimization..IP.B \-Catrade off larger tables in the generated scanner for faster performancebecause the elements of the tables are better aligned for memory accessand computation. This option can double the size of the tables used byyour scanner..IP.B \-Cedirects.I lexto construct.I equivalence classes,i.e., sets of characterswhich have identical lexical properties.Equivalence classes usually givedramatic reductions in the final table/object file sizes (typicallya factor of 2-5) and are pretty cheap performance-wise (one arraylook-up per character scanned)..IP.B \-Cfspecifies that the.I fullscanner tables should be generated -.I lexshould not compress thetables by taking advantages of similar transition functions fordifferent states..IP.B \-CFspecifies that the alternate fast scanner representation (described in.B lexdoc(1))should be used..IP.B \-Cmdirects.I lexto construct.I meta-equivalence classes,which are sets of equivalence classes (or characters, if equivalenceclasses are not being used) that are commonly used together. Meta-equivalenceclasses are often a big win when using compressed tables, but theyhave a moderate performance impact (one or two "if" tests and onearray look-up per character scanned)..IP.B \-Crcauses the generated scanner to.I bypassusing stdio for input. In general this option results in a minorperformance gain only worthwhile if used in conjunction with.B \-Cfor.B \-CF.It can cause surprising behavior if you use stdio yourself toread from.I yyinprior to calling the scanner..IPA lone.B \-Cspecifies that the scanner tables should be compressed but neitherequivalence classes nor meta-equivalence classes should be used..IPThe options.B \-Cfor.B \-CFand.B \-Cmdo not make sense together - there is no opportunity for meta-equivalenceclasses if the table is not being compressed. Otherwise the optionsmay be freely mixed..IPThe default setting is.B \-Cem,which specifies that.I lexshould generate equivalence classesand meta-equivalence classes. This setting provides the highestdegree of table compression. You can trade offfaster-executing scanners at the cost of larger tables withthe following generally being true:.nf slowest & smallest -Cem -Cm -Ce -C -C{f,F}e -C{f,F} -C{f,F}a fastest & largest.fi.IP.B \-Coptions are cumulative..TP.B \-Pprefixchanges the default.I "yy"prefix used by.I lexto be.I prefixinstead. See.I lexdoc(1)for a description of all the global variables and file names thatthis affects..TP.B \-Sskeleton_fileoverrides the default skeleton file from which.I lexconstructs its scanners. You'll never need this option unless you are doing.I lexmaintenance or development..SH SUMMARY OF LEX REGULAR EXPRESSIONSThe patterns in the input are written using an extended set of regularexpressions. These are:.nf 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' [^A-Z] a "negated character class", i.e., any character but those in the class. In this case, any character EXCEPT an uppercase letter. [^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" r|s 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 <*>r an r in any start condition, even an exclusive one. <<EOF>> an end-of-file <s1,s2><<EOF>> an end-of-file when in start condition s1 or s2.fiThe regular expressions listed above are grouped according toprecedence, from highest precedence at the top to lowest at the bottom.Those grouped together have equal precedence..PPSome notes on patterns:.IP -Negated character classes.I match newlinesunless "\\n" (or an equivalent escape sequence) is one of thecharacters explicitly present in the negated character class(e.g., "[^A-Z\\n]")..IP -A rule can have at most one instance of trailing context (the '/' operator
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -