It's certainly possible to recognize the literals without use of a temporary buffer, but it is not possible to process them, for the simple reason that flex
owns the input buffer and the string pointed to by yytext
(which happens to be a pointer into the input buffer, but that isn't guaranteed either).
But it doesn't really matter. As you will soon discover, in the normal usage of the lexer in combination with yacc
/bison
, you need to copy any lexical string into a temporary buffer anyway, because yacc
/bison
needs to read one token ahead in the input, and -- as above -- lex
/flex
doesn't guarantee to preserve the string pointed to by yytext
once it starts recognizing the next token. (That's not theoretical: it really doesn't preserve the string's value, and "Why do my strings keep changing?" is probably the most frequently asked yacc/lex question (and according to the bison manual, the most common invalid bug report).
There are workarounds -- including writing your own lexer -- but they require an awful lot of bookkeeping and for very little value, because copying a token string is actually not a very expensive operation. So my advice is: copy your strings and stop worrying. :)