📄 flex.1
字号:
.IP -A rule can have at most one instance of trailing context (the '/' operatoror the '$' operator). The start condition, '^', and "<<EOF>>" patternscan only occur at the beginning of a pattern, and, as well as with '/' and '$',cannot be grouped inside parentheses. The following are all illegal:.nf foo/bar$ foo|(bar$) foo|^bar <sc1>foo<sc2>bar.fi.SH SUMMARY OF SPECIAL ACTIONSIn addition to arbitrary C code, the following can appear in actions:.IP -.B ECHOcopies yytext to the scanner's output..IP -.B BEGINfollowed by the name of a start condition places the scanner in thecorresponding start condition..IP -.B REJECTdirects the scanner to proceed on to the "second best" rule which matched theinput (or a prefix of the input)..B yytextand.B yylengare set up appropriately. Note that.B REJECTis a particularly expensive feature in terms scanner performance;if it is used in.I anyof the scanner's actions it will slow down.I allof the scanner's matching. Furthermore,.B REJECTcannot be used with the.I -for.I -Foptions..IPNote also that unlike the other special actions,.B REJECTis a.I branch;code immediately following it in the action will.I notbe executed..IP -.B yymore()tells the scanner that the next time it matches a rule, the correspondingtoken should be.I appendedonto the current value of.B yytextrather than replacing it..IP -.B yyless(n)returns all but the first.I ncharacters of the current token back to the input stream, where theywill be rescanned when the scanner looks for the next match..B yytextand.B yylengare adjusted appropriately (e.g.,.B yylengwill now be equal to.I n)..IP -.B unput(c)puts the character.I cback onto the input stream. It will be the next character scanned..IP -.B input()reads the next character from the input stream (this routine is called.B yyinput()if the scanner is compiled using.B C++)..IP -.B yyterminate()can be used in lieu of a return statement in an action. It terminatesthe scanner and returns a 0 to the scanner's caller, indicating "all done"..IPBy default,.B yyterminate()is also called when an end-of-file is encountered. It is a macro andmay be redefined..IP -.B YY_NEW_FILEis an action available only in <<EOF>> rules. It means "Okay, I'veset up a new input file, continue scanning"..IP -.B yy_create_buffer( file, size )takes a.I FILEpointer and an integer.I size.It returns a YY_BUFFER_STATEhandle to a new input buffer large enough to accomodate.I sizecharacters and associated with the given file. When in doubt, use.B YY_BUF_SIZEfor the size..IP -.B yy_switch_to_buffer( new_buffer )switches the scanner's processing to scan for tokens fromthe given buffer, which must be a YY_BUFFER_STATE..IP -.B yy_delete_buffer( buffer )deletes the given buffer..SH VALUES AVAILABLE TO THE USER.IP -.B char *yytextholds the text of the current token. It may not be modified..IP -.B int yylengholds the length of the current token. It may not be modified..IP -.B FILE *yyinis the file which by default.I flexreads from. It may be redefined but doing so only makes sense beforescanning begins. Changing it in the middle of scanning will haveunexpected results since.I flexbuffers its input. Once scanning terminates because an end-of-filehas been seen,.Bvoid yyrestart( FILE *new_file )may be called to point.I yyinat the new input file..IP -.B FILE *yyoutis the file to which.B ECHOactions are done. It can be reassigned by the user..IP -.B YY_CURRENT_BUFFERreturns a.B YY_BUFFER_STATEhandle to the current buffer..SH MACROS THE USER CAN REDEFINE.IP -.B YY_DECLcontrols how the scanning routine is declared.By default, it is "int yylex()", or, if prototypes are beingused, "int yylex(void)". This definition may be changed by redefiningthe "YY_DECL" macro. Note thatif you give arguments to the scanning routine using aK&R-style/non-prototyped function declaration, you must terminatethe definition with a semi-colon (;)..IP -The nature of how the scannergets its input can be controlled by redefining the.B YY_INPUTmacro.YY_INPUT's calling sequence is "YY_INPUT(buf,result,max_size)". Itsaction is to place up to.I max_sizecharacters in the character array.I bufand return in the integer variable.I resulteither thenumber of characters read or the constant YY_NULL (0 on Unix systems)to indicate EOF. The default YY_INPUT reads from theglobal file-pointer "yyin".A sample redefinition of YY_INPUT (in the definitionssection of the input file):.nf %{ #undef YY_INPUT #define YY_INPUT(buf,result,max_size) \\ { \\ int c = getchar(); \\ result = (c == EOF) ? YY_NULL : (buf[0] = c, 1); \\ } %}.fi.IP -When the scanner receives an end-of-file indication from YY_INPUT,it then checks the.B yywrap()function. If.B yywrap()returns false (zero), then it is assumed that thefunction has gone ahead and set up.I yyinto point to another input file, and scanning continues. If it returnstrue (non-zero), then the scanner terminates, returning 0 to itscaller..IPThe default.B yywrap()always returns 1. Presently, to redefine it you must first"#undef yywrap", as it is currently implemented as a macro. It islikely that.B yywrap()will soon be defined to be a function rather than a macro..IP -YY_USER_ACTIONcan be redefined to provide an actionwhich is always executed prior to the matched rule's action..IP -The macro.B YY_USER_INITmay be redefined to provide an action which is always executed beforethe first scan..IP -In the generated scanner, the actions are all gathered in one largeswitch statement and separated using.B YY_BREAK,which may be redefined. By default, it is simply a "break", to separateeach rule's action from the following rule's..SH FILES.TP.I flex.skelskeleton scanner..TP.I lex.yy.cgenerated scanner (called.I lexyy.con some systems)..TP.I lex.backtrackbacktracking information for.B -bflag (called.I lex.bckon some systems)..TP.B -lfllibrary with which to link the scanners..SH "SEE ALSO".LPflexdoc(1), lex(1), yacc(1), sed(1), awk(1)..LPM. E. Lesk and E. Schmidt,.I LEX - Lexical Analyzer Generator.SH DIAGNOSTICS.I reject_used_but_not_detected undefinedor.LP.I yymore_used_but_not_detected undefined -These errors can occur at compile time. They indicate that thescanner uses.B REJECTor.B yymore()but that.I flexfailed to notice the fact, meaning that.I flexscanned the first two sections looking for occurrences of these actionsand failed to find any, but somehow you snuck some in (via a #includefile, for example). Make an explicit reference to the action in your.I flexinput file. (Note that previously.I flexsupported a.B %used/%unusedmechanism for dealing with this problem; this feature is still supportedbut now deprecated, and will go away soon unless the author hears frompeople who can argue compellingly that they need it.).LP.I flex scanner jammed -a scanner compiled with.B -shas encountered an input string which wasn't matched byany of its rules..LP.I flex input buffer overflowed -a scanner rule matched a string long enough to overflow thescanner's internal input buffer (16K bytes - controlled by.B YY_BUF_MAXin "flex.skel")..LP.I scanner requires -8 flag -Your scanner specification includes recognizing 8-bit characters andyou did not specify the -8 flag (and your site has not installed flexwith -8 as the default)..LP.Ifatal flex scanner internal error--end of buffer missed -This can occur in an scanner which is reentered after a long-jumphas jumped out (or over) the scanner's activation frame. Beforereentering the scanner, use:.nf yyrestart( yyin );.fi.LP.I too many %t classes! -You managed to put every single character into its own %t class..I flexrequires that at least one of the classes share characters..SH AUTHORVern Paxson, with the help of many ideas and much inspiration fromVan Jacobson. Original version by Jef Poskanzer..LPSee flexdoc(1) for additional credits and the address to send comments to..SH DEFICIENCIES / BUGS.LPSome trailing contextpatterns cannot be properly matched and generatewarning messages ("Dangerous trailing context"). These arepatterns where the ending of thefirst part of the rule matches the beginning of the secondpart, such as "zx*/xy*", where the 'x*' matches the 'x' atthe beginning of the trailing context. (Note that the POSIX draftstates that the text matched by such patterns is undefined.).LPFor some trailing context rules, parts which are actually fixed-length arenot recognized as such, leading to the abovementioned performance loss.In particular, parts using '|' or {n} (such as "foo{3}") are alwaysconsidered variable-length..LPCombining trailing context with the special '|' action can result in.I fixedtrailing context being turned into the more expensive.I variabletrailing context. For example, this happens in the following example:.nf %% abc | xyz/def.fi.LPUse of unput() invalidates yytext and yyleng..LPUse of unput() to push back more text than was matched canresult 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!)..LPPattern-matching of NUL's is substantially slower than matching othercharacters..LP.I flexdoes not generate correct #line directives for code internalto the scanner; thus, bugs in.I flex.skelyield bogus line numbers..LPDue to both buffering of input and read-ahead, you cannot intermixcalls to <stdio.h> routines, such as, for example,.B getchar(),with.I flexrules and expect it to work. Call.B input()instead..LPThe total table entries listed by the.B -vflag excludes the number of table entries needed to determinewhat rule has been matched. The number of entries is equalto the number of DFA states if the scanner does not use.B REJECT,and somewhat greater than the number of states if it does..LP.B REJECTcannot be used with the.I -for.I -Foptions..LPSome of the macros, such as.B yywrap(),may in the future become functions which live in the.B -lfllibrary. This will doubtless break a lot of code, but may berequired for POSIX-compliance..LPThe.I flexinternal algorithms need documentation.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -