manpagez: man pages & more
info flex
Home | html | info | man

File: flex.info,  Node: Deprecated Interfaces,  Prev: Retargeting Flex,  Up: Appendices

A.6 Deprecated interfaces, , Retargeting Flex
=============================================

Long-time users of Flex and its predecessor, Lex, may notice that the
examples in this manual look a little different than they used to.  They
have changed because of the support for targeting languages other than
C/C++.

   All the old interfaces are still in place for legacy C code to use.
But some are now deprecated and should not be used in new code.  Doing
so will hinder forward portability someday.

   These changes are necessary because the documented Flex interface can
no longer rely on controlling scanner generation by defining
preprocessor macros.  Most languages other than C/C++ don't have text
macros, and none of those that do emulate C #define closely enough to
preserve the behavior dependent on it.  Thus interface calls in
multi-language Flex need to be functions, at least syntactically (though
many are still implemented as macros for C/C++).

   A list of deprecated interfaces and their replacements follows.
Again, all are still available in the default C/C++ back end, but not in
any other.

   In the default back end, flex recognizes yybegin(), yyecho(),
yystart(), yyunput(), yyatbol() and yysetbol() only inside rule actions,
where it rewrites each to the old interface.  They are not macros, so a
program can have its own functions with those names.  Outside an action,
use the old interface.

   * BEGIN: Replaced by yybegin()

   * ECHO: Replaced by yyecho()

   * REJECT: Replaced by yyreject()

   * #define YY_DECL: Replaced by the 'yydecl' option.

   * #define YYLMAX: Replaced by the 'yylmax' option.

   * #define YY_INPUT: Replaced by the 'noyyread' option.

   * YYSTART: Replaced by yystart().

   * YY_AT_BOL(): Replaced by yyatbol().

   * yy_set_bol(): Replaced by yysetbol()

   * input(): May be written yyinput() in an action.  The default C back
     end still names the function input(), as flex 2.6.4 did, and the
     C++ back end names it yyinput().

   * : unput(): Replaced by yyunput().

   * #define YY_EXTRA_TYPE: Replaced by the 'extra-type' option.

   * #define YY_USER_INIT: Replaced by the 'user-init' option.

   * #define YY_USER_ACTION replaced by 'pre-action' option.

   * #define YY_BREAK: Still used by the default back end.  The
     'post-action' option does the same in every back end.

   * YYSTATE: is accepted as an alias for 'yystart()' (since that is
     what's used by AT&T 'lex').

   * YY_FLUSH_BUFFER: replaced by yy_flush_current_buffer().

   * YY_CURRENT_BUFFER: replaced by yy_current_buffer().

   * YY_BUFFER_STATE: replaced by yybuffer.

   * YY_FATAL_ERROR: replaced by yypanic().  To supply your own handler,
     simply use '%option noyypanic' so the default handler is not
     generated, then write your own handler with the same prototype.

   * YY_NEW_FILE: In previous versions of 'flex', when assigning 'yyin'
     to a new input file, after doing the assignment you had to call the
     special action 'YY_NEW_FILE'.  This is no longer necessary.

   * FLEX_SCANNER: Not meaningful outside of the C back end, and not
     defined.

   * FLEX_DEBUG: Outside the default C back end, this is a constant of
     type bool rather rthan a preprocessor symbol.

   * FLEX_BETA: Its behavior can't be replicated without the C
     preprocessor.  Test for YY_FLEX_SUBMINOR_VERSION instead.

   * YY_BUF_SIZE: replaced by '%option bufsize'.

   * : yyterminate(): Backends that don't use the C preprocessor cannot
     support redefining this hook with #define.  Instead, set it with
     the 'yyterminate' option.

   Where entry point names have been downcased and had underscores
removed, it's because some languages in the expected target set for Flex
- notably Go and Python - have validator/linter tools that would
complain about uppercase or underscores or both.  It would obviously be
best if the parts of the public API that have to change to conform to
local conventions are small and not commonly used.

   This is also why the functions 'yy_current_buffer()',
'yy_flush_current_buffer()', and 'yy_set_interactive()' do not have
rewrite rules (see *Note option-rewrite::); simply removing the
underscores would have produced names that are uncomfortably long and
hard on the eyeballs.  We leave it to the API binding for each
individual target language to choose whether they should be left as is,
camel-cased, or otherwise adapted to local conventions.

© manpagez.com 2000-2026
Individual documents may contain additional copyright information.