You certainly don't need to use those options. You should use them if you don't use the corresponding functions, in order to avoid the compiler warnings. (If you don't care about compiler warnings, you don't need the options either. But you should care about compiler warnings :) )
The functions are rarely used; they are mostly needed if you want to bypass lexical analysis in some context, and directly read input (input
), or if you want to fabricate input text to be scanned (unput
).
input()
can be used in an action to return the next character from the input stream. (The character read is removed from the input stream, so it will not be scanned when the action finishes.) Since input()
only returns a single character, it is not very efficient but there are times when it is unavoidable. One example is tokens preceded by explicit lengths. (On the whole, flex is not the ideal tool to lexically scan an input stream where all tokens have explicit lengths.)
unput(c)
can be used to insert a character into the input stream, so that the character will be scanned when the action finishes. The Flex manual contains a rather contrived example where the token just read is reinserted into the input stream surrounded by parentheses.
You should not use unput
to simply rescan all or part of a token; the yyless
macro is much more efficient for that purpose.
Most lexical scanners do not require either input
or unput
, and so it is common to use %option
to avoid generating code for them.
If you are just learning flex, I recommend that you start with the normal flex idioms, leaving things like input
and unput
aside until you have a clear need for them (if ever). Also, you should read the Flex manual, which will answer many of your questions.