Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Flex (lexical analyser generator)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Issues == === Time complexity === A Flex lexical analyzer usually has time complexity <math>O(n)</math> in the length of the input. That is, it performs a constant number of operations for each input symbol. This constant is quite low: [[GNU Compiler Collection|GCC]] generates 12 instructions for the DFA match loop.{{citation needed|date=November 2015}} Note that the constant is independent of the length of the token, the length of the regular expression and the size of the DFA. However, using the REJECT macro in a scanner with the potential to match extremely long tokens can cause Flex to generate a scanner with non-linear performance. This feature is optional. In this case, the programmer has explicitly told Flex to "go back and try again" after it has already matched some input. This will cause the DFA to backtrack to find other accept states. The REJECT feature is not enabled by default, and because of its performance implications its use is discouraged in the Flex manual.<ref name=performance>{{cite web |title=Performance - Lexical Analysis With Flex, for Flex 2.5.37 |publisher=Flex.sourceforge.net |date= |url=https://westes.github.io/flex/manual/Performance.html |access-date=2013-02-25}}</ref> === Reentrancy === By default the scanner generated by Flex is not [[Reentrant (subroutine)|reentrant]]. This can cause serious problems for programs that use the generated scanner from different threads. To overcome this issue there are options that Flex provides in order to achieve reentrancy. A detailed description of these options can be found in the Flex manual.<ref>{{cite web |url=https://westes.github.io/flex/manual/Reentrant.html |title=Reentrant - Lexical Analysis With Flex, for Flex 2.5.37 |publisher=Flex.sourceforge.net |date= |access-date=2013-02-25}}</ref> === Usage under non-Unix environments === Normally the generated scanner contains references to the ''unistd.h'' header file, which is [[Unix-like|Unix]] specific. To avoid generating code that includes ''[[unistd.h]]'', ''%option nounistd'' should be used. Another issue is the call to ''[[Not a typewriter|isatty]]'' (a Unix library function), which can be found in the generated code. The ''%option never-interactive'' forces flex to generate code that does not use ''isatty''.<ref>{{cite web |title=Code-Level And API Options - Lexical Analysis With Flex, for Flex 2.5.37 |publisher=Flex.sourceforge.net |date= |url=https://westes.github.io/flex/manual/Code_002dLevel-And-API-Options.html |access-date=2013-02-25}}</ref> ===Using flex from other languages=== Flex can only generate code for [[C (programming language)|C]] and [[C++]]. To use the scanner code generated by flex from other languages a [[language binding]] tool such as [[SWIG]] can be used. === Unicode support === Flex is limited to matching 1-byte (8-bit) binary values and therefore does not support [[Unicode]].<ref>{{Cite web |last=Tomassetti |first=Gabriele |date=2020-03-04 |title=Why you should not use (f)lex, yacc and bison |url=https://tomassetti.me/why-you-should-not-use-flex-yacc-and-bison/ |access-date=2022-10-26 |website=Strumenta |language=en-US}}</ref> RE/flex and other alternatives do support Unicode matching.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)