Next: , Previous: , Up: Retargeting Flex   [Contents][Index]


A.5.2 Getting Started

To get started on writing a new back end, browse src/skeletons,c to get some idea of how skeleton files are queried, then read a skeleton file. If no sketon exists of a language that is closer to your target, the C99 back end is specifically intended to be cloned and used as a launch pont for new back ends.

This file you are looking at is processed through GNU m4 during the pre-compilation stage of Flex. At this time only macros starting with ‘m4preproc_’ are processed, and quoting is normal (that is, the quote opener is a back-tick (ASCII 96) and the quote closer is a tick or single quote (ASCII 39) 9. The main purpose of this expansion phase is to set Flex version symbols.

At Flex compilation time, the preprocessed skeleton is translated into a comma-separated list of doublequoted strings which is stuffed into a language- specific method block compiled into the flex binary.

At scanner generation time, , the skeleton is generated and filtered (again) through m4. Macros beginning with ‘m4_’ will be processed. The quoting is “[[“ and “]]” so we don’t interfere with user code.

A line beginning with “%#” is a comment. These comments are omitted from the generated scanner.

A line beginning with “%%” is a stop-point, where code is inserted by Flex. Each stop-point is numbered here and also in the code generator. Stop points will be inserted into the generated scanner as a comment. This is to aid those who edit skeletons.

You’ll want to start by studying the M4_PROPERTY_* macros near the top of the skeleton file. They declare properties of the back end like its name and normal source-code suffix. These aren’t used for code generation; they’re for Flex to read and key on.

Following those are the M4_HOOK_* macros. Rather than emit literal language syntax, Flex ships calls to these macros which are expected to be expanded to to the correct language syntax within the skeleton. The other things flex ships which appear in the output code are mostly bodies for table initializers, with associated macros for typenames and table dimensions. The names of all such macros have the prefix “M4_HOOK_”; you can study them in the Flex code by grepping for that prefix.

Flex ships another fairly large set of macros that are guard conditions for conditional macroexpanion. The values of these symbols don’t directly appear in the output, but they control the shape of the generated code. The names of such macros have the prefixes “M4_MODE_” or “M4_YY_”; you can study them in the Flex code by grepping for these prefixes. Many of these symbols correspond to Flex command-line options.


Footnotes

(9)

See chapter 3.2 of the m4 manual, “Quoting input to m4”, for more information.


Next: Development Steps, Previous: Overview, Up: Retargeting Flex   [Contents][Index]