Using Flex at the Engineering Network Services

  1. user-setup command: Use the user-setup command to select misc/gnu/1.0.

  2. Flex input file: Create a Flex input file, e.g., rule.l, which consists of three parts: definitions, rules, and auxiliary routines.

  3. A scanner creation: Call the Flex with the following syntax:
    > flex [-bcdfhilnpstvwBFILTV78+? -C[aefFmr] -ooutput - Pprefix -Sskeleton] [--help --version] [filename ...]
    For example, the input file name is rule.l:
    > flex rule.l
    Some useful Flex command-line options are
    • -d: Makes the generated scanner run in debug mode.
    • -s: Causes the default rule (the unmatched scanner input is echoed to stdout) to be suppressed.
    • -i: Instructs Flex to generate a case-insensitive scanner.

  4. An executable creation: The Flex generates as output a C source file, lex.yy.c, which is used to produce an executable by gcc, a GNU project C compiler:
    > gcc [ option | filename ] ...
    For example, the executable name is scanner:
    > gcc -o scanner lex.yy.c
  5. The scanner application: Apply the executable scanner to a file, e.g., test, and send the results to a file, e.g., result:
    > scanner < test > result