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:

    I really do inhabit a system in which words are capable of shaking the entire structure of government, where words can prove mightier than ten military divisions.
    Václav Havel (b. 1936)

    The question is still asked of women: “How do you propose to answer the need for child care?” That is an obvious attempt to structure conflict in the old terms. The questions are rather: “If we as a human community want children, how does the total society propose to provide for them?”
    Jean Baker Miller (20th century)

    A common and natural result of an undue respect for law is, that you may see a file of soldiers, colonel, captain, corporal, privates, powder-monkeys, and all, marching in admirable order over hill and dale to the wars, against their wills, ay, against their common sense and consciences, which makes it very steep marching indeed, and produces a palpitation of the heart.
    Henry David Thoreau (1817–1862)