# man > flex(1)

---
type: CommandReference
command: flex
mode: man
section: 1
source: man-pages
---

## Quick Reference

- `flex {{analyzer.l}}` — Generate an analyzer from a Lex file, storing to `lex.yy.c`
- `flex -t {{analyzer.l}}` — Write analyzer to stdout
- `flex {{analyzer.l}} -o {{analyzer.c}}` — Specify output file
- `flex -B {{analyzer.l}}` — Generate a batch scanner (non-interactive)
- `cc {{lex.yy.c}} -o {{executable}}` — Compile a C file generated by Lex
- `flex -I {{analyzer.l}}` — Generate an interactive scanner
- `flex -d {{analyzer.l}}` — Enable debug mode in scanner
- `flex -v {{analyzer.l}}` — Verbose statistics on scanner

## Name

`flex` — the fast lexical analyser generator

## Synopsis

`flex` [_OPTIONS_] [_FILE_]...

## Options

### Table Compression

- `-Ca, --align` — Trade off larger tables for better memory alignment
- `-Ce, --ecs` — Construct equivalence classes
- `-Cf, -f` — Generate fast, large scanner (same as `-Cfr`)
- `-CF, -F` — Use alternate table representation (same as `-CFr`)
- `-Cm, --meta-ecs` — Construct meta-equivalence classes
- `-Cr, --read` — Use `read()` instead of stdio for scanner input
- `-Cem` — Equivalent to `--ecs --meta-ecs`

### Debugging

- `-d, --debug` — Enable debug mode in scanner
- `-b, --backup` — Write backing-up information to `lex.backup`
- `-p, --perf-report` — Write performance report to stderr
- `-s, --nodefault` — Suppress default rule to ECHO unmatched text
- `-T, --trace` — Run flex in trace mode
- `-w, --nowarn` — Do not generate warnings
- `-v, --verbose` — Write summary of scanner statistics to stdout
- `--hex` — Use hexadecimal numbers instead of octal in debug outputs

### Files

- `-o, --outfile` — Specify output filename
- `-S, --skel` — Specify skeleton file
- `-t, --stdout` — Write scanner on stdout instead of `lex.yy.c`
- `--yyclass=_NAME_` — Name of C++ class
- `--header-file=_FILE_` — Create a C header file in addition to the scanner
- `--tables-file[=_FILE_]` — Write tables to FILE
- `--backup-file=_FILE_` — Write backing-up information to FILE

### Scanner Behavior

- `-7, --7bit` — Generate 7-bit scanner
- `-8, --8bit` — Generate 8-bit scanner
- `-B, --batch` — Generate batch scanner (opposite of `-I`)
- `-i, --case-insensitive` — Ignore case in patterns
- `-l, --lex-compat` — Maximal compatibility with original lex
- `-X, --posix-compat` — Maximal compatibility with POSIX lex
- `-I, --interactive` — Generate interactive scanner (opposite of `-B`)
- `--yylineno` — Track line count in `yylineno`

### Generated Code

- `-+, --c++` — Generate C++ scanner class
- `-Dmacro` — `#define` macro definition (default definition is '1')
- `-L, --noline` — Suppress `#line` directives in scanner
- `-P, --prefix` — Use STRING as prefix instead of "yy"
- `-R, --reentrant` — Generate a reentrant C scanner
- `--bison-bridge` — Scanner for bison pure parser
- `--bison-locations` — Include `yylloc` support
- `--stdinit` — Initialize `yyin`/`yyout` to stdin/stdout
- `--nounistd` — Do not include `<unistd.h>`
- `--noFUNCTION` — Do not generate a particular FUNCTION

### Miscellaneous

- `-c` — (obsolete) No effect
- `-n` — (obsolete) No effect
- `-?, -h, --help` — Produce this help message
- `-V, --version` — Report flex version

## Examples

Generate an analyzer and store to `lex.yy.c`:
shell
flex analyzer.l
Write analyzer to stdout:
shell
flex -t analyzer.l
Specify output file:
shell
flex analyzer.l -o analyzer.c
Generate a batch scanner (non-interactive):
shell
flex -B analyzer.l
Compile a C file generated by Lex:
shell
cc lex.yy.c -o executable
## See Also

Full documentation available via `info flex` (Texinfo manual).