⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flexdoc.1

📁 生成C++的词法/语法分析的Flex语法分析器
💻 1
📖 第 1 页 / 共 5 页
字号:
    volatile\\n |    while\\n  /* it's a keyword */    [a-z]+\\n |    .|\\n     /* it's not a keyword */.fiOne has to be careful here, as we have now reintroduced backtrackinginto the scanner.  In particular, while.I weknow that there will never be any characters in the input streamother than letters or newlines,.I flexcan't figure this out, and it will plan for possibly needing backtrackingwhen it has scanned a token like "auto" and then the next characteris something other than a newline or a letter.  Previously it wouldthen just match the "auto" rule and be done, but now it has no "auto"rule, only a "auto\\n" rule.  To eliminate the possibility of backtracking,we could either duplicate all rules but without final newlines, or,since we never expect to encounter such an input and therefore don'thow it's classified, we can introduce one more catch-all rule, thisone which doesn't include a newline:.nf    %%    asm\\n    |    auto\\n   |    break\\n  |    ... etc ...    volatile\\n |    while\\n  /* it's a keyword */    [a-z]+\\n |    [a-z]+   |    .|\\n     /* it's not a keyword */.fiCompiled with.B -Cf,this is about as fast as one can get a.I flex scanner to go for this particular problem..LPA final note:.I flexis slow when matching NUL's, particularly when a token containsmultiple NUL's.It's best to write rules which match.I shortamounts of text if it's anticipated that the text will often include NUL's..SH INCOMPATIBILITIES WITH LEX AND POSIX.I flexis a rewrite of the Unix.I lextool (the two implementations do not share any code, though),with some extensions and incompatibilities, both of whichare of concern to those who wish to write scanners acceptableto either implementation.  At present, the POSIX.I lexdraft isvery close to the original.I leximplementation, so some of theseincompatibilities are also in conflict with the POSIX draft.  Butthe intent is that except as noted below,.I flexas it presently stands willultimately be POSIX conformant (i.e., that those areas of conflict withthe POSIX draft will be resolved in.I flex'sfavor).  Please bear inmind that all the comments which follow are with regard to the POSIX.I draftstandard of Summer 1989, and not the final document (or subsequentdrafts); they are included so.I flexusers can be aware of the standardization issues and those areas where.I flexmay in the near future undergo changes incompatible withits current definition..LP.I flexis fully compatible with.I lexwith the following exceptions:.IP -The undocumented.I lexscanner internal variable.B yylinenois not supported.  It is difficult to support this option efficiently,since it requires examining every character scanned and reexaminingthe characters when the scanner backs up.Things get more complicated when the end of buffer or file is reached or aNUL is scanned (since the scan must then be restarted with the proper linenumber count), or the user uses the yyless(), unput(), or REJECT actions,or the multiple input buffer functions..IPThe fix is to add rules which, upon seeing a newline, incrementyylineno.  This is usually an easy process, though it can be a drag if someof the patterns can match multiple newlines along with other characters..IPyylineno is not part of the POSIX draft..IP -The.B input()routine is not redefinable, though it may be called to read charactersfollowing whatever has been matched by a rule.  If.B input()encounters an end-of-file the normal.B yywrap()processing is done.  A ``real'' end-of-file is returned by.B input()as.I EOF..IPInput is instead controlled by redefining the.B YY_INPUTmacro..IPThe.I flexrestriction that.B input()cannot be redefined is in accordance with the POSIX draft, but.B YY_INPUThas not yet been accepted into the draft (and probably won't; it lookslike the draft will simply not specify any way of controlling thescanner's input other than by making an initial assignment to.I yyin)..IP -.I flexscanners do not use stdio for input.  Because of this, when writing aninteractive scanner one must explicitly call fflush() on thestream associated with the terminal after writing out a prompt.With.I lexsuch writes are automatically flushed since.I lexscanners use.B getchar()for their input.  Also, when writing interactive scanners with.I flex,the.B -Iflag must be used..IP -.I flexscanners are not as reentrant as.I lexscanners.  In particular, if you have an interactive scanner andan interrupt handler which long-jumps out of the scanner, andthe scanner is subsequently called again, you may get the followingmessage:.nf    fatal flex scanner internal error--end of buffer missed.fiTo reenter the scanner, first use.nf    yyrestart( yyin );.fi.IP -.B output()is not supported.Output from the.B ECHOmacro is done to the file-pointer.I yyout(default.I stdout)..IPThe POSIX draft mentions that an.B output()routine exists but currently gives no details as to what it does..IP -.I lexdoes not support exclusive start conditions (%x), though theyare in the current POSIX draft..IP -When definitions are expanded,.I flexencloses them in parentheses.With lex, the following:.nf    NAME    [A-Z][A-Z0-9]*    %%    foo{NAME}?      printf( "Found it\\n" );    %%.fiwill not match the string "foo" because when the macrois expanded the rule is equivalent to "foo[A-Z][A-Z0-9]*?"and the precedence is such that the '?' is associated with"[A-Z0-9]*".  With.I flex,the rule will be expanded to"foo([A-Z][A-Z0-9]*)?" and so the string "foo" will match.Note that because of this, the.B ^, $, <s>, /,and.B <<EOF>>operators cannot be used in a.I flexdefinition..IPThe POSIX draft interpretation is the same as.I flex's..IP -To specify a character class which matches anything but a left bracket (']'),in.I lexone can use "[^]]" but with.I flexone must use "[^\\]]".  The latter works with.I lex,too..IP -The.I lex.B %r(generate a Ratfor scanner) option is not supported.  It is not partof the POSIX draft..IP -If you are providing your own yywrap() routine, you must include a"#undef yywrap" in the definitions section (section 1).  Note thatthe "#undef" will have to be enclosed in %{}'s..IPThe POSIX draftspecifies that yywrap() is a function and this is very unlikely to change; so.I flex users are warnedthat.B yywrap()is likely to be changed to a function in the near future..IP -After a call to.B unput(),.I yytextand.I yylengare undefined until the next token is matched.  This is not the case with.I lexor the present POSIX draft..IP -The precedence of the.B {}(numeric range) operator is different..I lexinterprets "abc{1,3}" as "match one, two, orthree occurrences of 'abc'", whereas.I flexinterprets it as "match 'ab'followed by one, two, or three occurrences of 'c'".  The latter isin agreement with the current POSIX draft..IP -The precedence of the.B ^operator is different..I lexinterprets "^foo|bar" as "match either 'foo' at the beginning of a line,or 'bar' anywhere", whereas.I flexinterprets it as "match either 'foo' or 'bar' if they come at the beginningof a line".  The latter is in agreement with the current POSIX draft..IP -To refer to yytext outside of the scanner source file,the correct definition with.I flexis "extern char *yytext" rather than "extern char yytext[]".This is contrary to the current POSIX draft but a point on which.I flexwill not be changing, as the array representation entails aserious performance penalty.  It is hoped that the POSIX draft willbe emended to support the.I flexvariety of declaration (as this is a fairly painless change torequire of.I lexusers)..IP -.I yyinis.I initializedby.I lexto be.I stdin;.I flex,on the other hand,initializes.I yyinto NULLand then.I assignsit to.I stdinthe first time the scanner is called, providing.I yyinhas not already been assigned to a non-NULL value.  The difference issubtle, but the net effect is that with.I flexscanners,.I yyindoes not have a valid value until the scanner has been called..IP -The special table-size declarations such as.B %asupported by.I lexare not required by.I flexscanners;.I flexignores them..IP -The name.bdFLEX_SCANNERis #define'd so scanners may be written for use with either.I flexor.I lex..LPThe following.I flexfeatures are not included in.I lexor the POSIX draft standard:.nf    yyterminate()    <<EOF>>    YY_DECL    #line directives    %{}'s around actions    yyrestart()    comments beginning with '#' (deprecated)    multiple actions on a line.fiThis last feature refers to the fact that with.I flexyou can put multiple actions on the same line, separated withsemi-colons, while with.I lex,the following.nf    foo    handle_foo(); ++num_foos_seen;.fiis (rather surprisingly) truncated to.nf    foo    handle_foo();.fi.I flexdoes not truncate the action.  Actions that are not enclosed inbraces are simply terminated at the end of the line..SH DIAGNOSTICS.I reject_used_but_not_detected undefinedor.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 by default - controlled by.B YY_BUF_SIZEin "flex.skel".  Note that to redefine this macro, you must first.B #undefineit)..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 DEFICIENCIES / BUGSSee flex(1)..SH "SEE ALSO".LPflex(1), lex(1), yacc(1), sed(1), awk(1)..LPM. E. Lesk and E. Schmidt,.I LEX - Lexical Analyzer Generator.SH AUTHORVern Paxson, with the help of many ideas and much inspiration fromVan Jacobson.  Original version by Jef Poskanzer.  The fast tablerepresentation is a partial implementation of a design done by VanJacobson.  The implementation was done by Kevin Gong and Vern Paxson..LPThanks to the many.I flexbeta-testers, feedbackers, and contributors, especially CaseyLeedom, benson@odi.com, Keith Bostic,Frederic Brehm, Nick Christopher, Jason Coughlin,Scott David Daniels, Leo Eskin,Chris Faylor, Eric Goldman, EricHughes, Jeffrey R. Jones, Kevin B. Kenny, Ronald Lamprecht,Greg Lee, Craig Leres, Mohamed el Lozy, Jim Meyering, Marc Nozell, Esmond Pitt,Jef Poskanzer, Jim Roskind,Dave Tallman, Frank Whaley, Ken Yap, and those whose nameshave slipped my marginal mail-archiving skills but whose contributionsare appreciated all the same..LPThanks to Keith Bostic, John Gilmore, Craig Leres, BobMulcahy, Rich Salz, and Richard Stallman for help with various distributionheadaches..LPThanks to Esmond Pitt and Earle Horton for 8-bit character support;to Benson Margulies and FredBurke for C++ support; to Ove Ewerlid for the basics of support forNUL's; and to Eric Hughes for the basics of support for multiple buffers..LPWork is being done on extending.I flexto generate scanners in which thestate machine is directly represented in C code rather than tables.These scanners may well be substantially faster than those generatedusing -f or -F.  If you are working in this area and are interestedin comparing notes and seeing whether redundant work can be avoided,contact Ove Ewerlid (ewerlid@mizar.DoCS.UU.SE)..LPThis work was primarily done when I was at the Real Time Systems Groupat the Lawrence Berkeley Laboratory in Berkeley, CA.  Many thanks to all therefor the support I received..LPSend comments to:.nf     Vern Paxson      Computer Systems Engineering      Bldg. 46A, Room 1123      Lawrence Berkeley Laboratory      University of California      Berkeley, CA 94720      vern@ee.lbl.gov      ucbvax!ee.lbl.gov!vern.fi

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -