📄 flex.1
字号:
.TH FLEX 1 "26 May 1990" "Version 2.3".SH NAMEflex - fast lexical analyzer generator.SH SYNOPSIS.B flex.B [-bcdfinpstvFILT8 -C[efmF] -Sskeleton].I [filename ...].SH DESCRIPTION.I flexis a tool for generating.I scanners:programs which recognized lexical patterns in text..I flexreadsthe 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. flexgenerates 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 -lfllibrary 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..LPFor full documentation, see.B flexdoc(1).This manual entry is intended for use as a quick reference..SH OPTIONS.I flexhas the following options:.TP.B -bGenerate backtracking information to.I lex.backtrack.This is a list of scanner states which require backtrackingand the input characters on which they do so. By adding rules onecan remove backtracking states. If all backtracking statesare eliminated and.B -for.B -Fis 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 flex.B -cspecified table-compression options. This functionality isnow given by the.B -Cflag. To ease the the impact of this change, when.I flexencounters.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 flex). Messagesare also generated when the scanner backtracks, 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 (take your pick).I full tableor.I fast scanner.No table compression is done. The result is large but fast.This option is equivalent to.B -Cf(see below)..TP.B -iinstructs.I flexto generate a.I case-insensitivescanner. The case of letters given in the.I flexinput 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 -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 flexinput file which will cause a loss of performance in the resulting scanner..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 flexto write the scanner it generates to standard output insteadof.B lex.yy.c..TP.B -vspecifies that.I flexshould write to.I stderra summary of statistics regarding the scanner it generates..TP.B -Fspecifies that the.ulfastscanner table representation should be used. This representation isabout as fast as the full table representation.ul(-f),and for some sets of patterns will be considerably smaller (and forothers, larger). See.B flexdoc(1)for details..IPThis option is equivalent to.B -CF(see below)..TP.B -Iinstructs.I flexto 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.Again, see.B flexdoc(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..TP.B -Linstructs.I flexnot 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 flexinput file, and not tothe fairly meaningless line numbers of.B lex.yy.c..TP.B -Tmakes.I flexrun in.I tracemode. It will generate a lot of messages to.I stdoutconcerningthe form of the input and the resultant non-deterministic and deterministicfinite automata. This option is mostly for use in maintaining.I flex..TP.B -8instructs.I flexto generate an 8-bit scanner.On some sites, this is the default. On others, the defaultis 7-bit characters. To see which is the case, check the verbose.B (-v)output for "equivalence classes created". If the denominator ofthe number shown is 128, then by default.I flexis generating 7-bit characters. If it is 256, then the default is8-bit characters..TP .B -C[efmF]controls the degree of table compression..IP.B -Cedirects.I flexto 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 flexshould not compress thetables by taking advantages of similar transition functions fordifferent states..IP.B -CFspecifies that the alternate fast scanner representation (described in.B flexdoc(1))should be used..IP.B -Cmdirects.I flexto 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)..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 flexshould 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} fastest & largest.fi.IP.B -Coptions are not cumulative; whenever the flag is encountered, theprevious -C settings are forgotten..TP.B -Sskeleton_fileoverrides the default skeleton file from which.I flexconstructs its scanners. You'll never need this option unless you are doing.I flexmaintenance or development..SH SUMMARY OF FLEX 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 <<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..LPSome 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]").
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -