Lex (software) - Structure of A Lex File

Structure of A Lex File

The structure of a Lex file is intentionally similar to that of a yacc file; files are divided into three sections, separated by lines that contain only two percent signs, as follows:

Definition section %% Rules section %% C code section
  • The definition section defines macros and imports header files written in C. It is also possible to write any C code here, which will be copied verbatim into the generated source file.
  • The rules section associates regular expression patterns with C statements. When the lexer sees text in the input matching a given pattern, it will execute the associated C code.
  • The C code section contains C statements and functions that are copied verbatim to the generated source file. These statements presumably contain code called by the rules in the rules section. In large programs it is more convenient to place this code in a separate file linked in at compile time.

Read more about this topic:  Lex (software)

Famous quotes containing the words structure of, structure and/or file:

    A special feature of the structure of our book is the monstrous but perfectly organic part that eavesdropping plays in it.
    Vladimir Nabokov (1899–1977)

    For the structure that we raise,
    Time is with materials filled;
    Our to-days and yesterdays
    Are the blocks with which we build.
    Henry Wadsworth Longfellow (1809–1882)

    I have been a soreheaded occupant of a file drawer labeled “Science Fiction” ... and I would like out, particularly since so many serious critics regularly mistake the drawer for a urinal.
    Kurt Vonnegut, Jr. (b. 1922)