Using Flex at the Engineering Network Services
- user-setup command: Use the user-setup command to select misc/gnu/1.0.
- Flex input file: Create a Flex input file, e.g., rule.l, which consists of three parts: definitions, rules, and auxiliary routines.
- 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.
- 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
- 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