Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sed(1)

yacc(1)

lex(1)

Name

lex − generate lexical analyzer

Syntax

lex [−tvfn] file...

Description

The lex command generates programs to be used in simple lexical analysis of text. The input files (standard input default) contain regular expressions to be searched for, and actions written in C to be executed when expressions are found. 

A C source program, ’lex.yy.c’, is generated.  It is compiled using the following command line:

cc lex.yy.c −ll

This program copies unrecognized portions of the input to the output, and executes the associated C action for each regular expression that is recognized.

Options

−fRuns a faster compilation (does not pack resulting tables).  This is limited to small programs. 

−nPrints no summary information (default option). 

−tWrites to standard output instead of to file lex.yy.c.

−vPrints one-line summary of generated statistics. 

Examples

In the following example, the command

lex lexcommands

draws lex instructions from the file lexcommands, and places the output in lex.yy.c. The command

%%
[A−Z]putchar(yytext[0]+´a´−´A´);
[ ]+$
[ ]+putchar(´ ´);

is an example of a lex program that would be put into a lex command file.  This program converts upper case to lower, removes blanks at the end of lines, and replaces multiple blanks by single blanks.

See Also

sed(1), yacc(1)
"LEX − Lexical Analyzer Generator", Supplementary Documents, Volume 2: Programmer

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026