HiveBrain v1.2.0
Get Started
← Back to all entries
snippetbashTip

lex — Lexical analyzer generator. Given the specification for a lexical analyzer, generates C code impleme

Submitted by: @import:tldr-pages··
0
Viewed 0 times
thegivencommandgeneratorlexlexicalclianalyzer

Problem

How to use the lex command: Lexical analyzer generator. Given the specification for a lexical analyzer, generates C code implementing it. Note: On most major OSes, this command is an alias for flex. More information: <https://manned.org/lex>.

Solution

lex — Lexical analyzer generator. Given the specification for a lexical analyzer, generates C code implementing it. Note: On most major OSes, this command is an alias for flex. More information: <https://manned.org/lex>.

Generate an analyzer from a Lex file, storing it to the file lex.yy.c:
lex {{analyzer.l}}


Specify the output file:
lex -t {{analyzer.l}} > {{analyzer.c}}


Compile a C file generated by Lex:
c99 {{path/to/lex.yy.c}} -o {{executable}}

Code Snippets

Generate an analyzer from a Lex file, storing it to the file `lex.yy.c`

lex {{analyzer.l}}

Specify the output file

lex -t {{analyzer.l}} > {{analyzer.c}}

Compile a C file generated by Lex

c99 {{path/to/lex.yy.c}} -o {{executable}}

Context

tldr-pages: common/lex

Revisions (0)

No revisions yet.