xref: /csrg-svn/old/lex/lex.1 (revision 50835)
1*50835Scael.\" Copyright 1991 The Regents of the University of California.
2*50835Scael.\" All rights reserved.
319430Smckusick.\"
4*50835Scael.\" %sccs.include.proprietary.roff%
5*50835Scael.\"
6*50835Scael.\"	@(#)lex.1	6.3 (Berkeley) 08/09/91
7*50835Scael.\"
8*50835Scael.Dd
9*50835Scael.Dt LEX 1
10*50835Scael.Os ATT 7th
11*50835Scael.Sh NAME
12*50835Scael.Nm lex
13*50835Scael.Nd generator of lexical analysis programs
14*50835Scael.Sh SYNOPSIS
15*50835Scael.Nm lex
16*50835Scael.Op Fl tvfn
17*50835Scael.Op Ar file
18*50835Scael.Ar ...
19*50835Scael.Sh DESCRIPTION
20*50835ScaelThe
21*50835Scael.Nm lex
22*50835Scaelcommand
2319430Smckusickgenerates programs to be used in simple lexical analyis of text.
2419430SmckusickThe input
25*50835Scael.Em files
2619431Smckusick(standard input default) contain regular expressions
2719430Smckusickto be searched for, and actions written in C to be executed when
2819430Smckusickexpressions are found.
29*50835Scael.Pp
3019431SmckusickA C source program, 'lex.yy.c' is generated, to be compiled thus:
31*50835Scael.Bd -literal -offset indent
32*50835Scaelcc lex.yy.c.Fl ll
33*50835Scael.Ed
34*50835Scael.Pp
3519430SmckusickThis program, when run, copies unrecognized portions of
3619431Smckusickthe input to the output, and executes the associated
3719430SmckusickC action for each regular expression that is recognized.
38*50835Scael.Pp
3919430SmckusickThe options have the following meanings.
40*50835Scael.Bl -tag -width indent
41*50835Scael.It Fl t
42*50835ScaelPlace the result on the standard output instead of in file
43*50835Scael.Pa lex.yy.c .
44*50835Scael.It Fl v
45*50835ScaelPrint a one-line
46*50835Scaelsummary of statistics of the generated analyzer.
47*50835Scael.It Fl n
4819430SmckusickOpposite of
49*50835Scael.Fl v ;
50*50835Scael.Fl n
5119430Smckusickis default.
52*50835Scael.It Fl f
5319431Smckusick"Faster" compilation: don't bother to pack
5419430Smckusickthe resulting tables; limited to small programs.
55*50835Scael.Sh EXAMPLE
56*50835Scael.Bd -literal -offset indent
5719431Smckusicklex lexcommands
58*50835Scael.Ed
59*50835Scael.Pp
6019431Smckusickwould draw
61*50835Scael.Nm lex
6219431Smckusickinstructions from the file
63*50835Scael.Pa lexcommands ,
6419431Smckusickand place the output in
65*50835Scael.Pa lex.yy.c
66*50835Scael.Bd -literal -offset indent
6719431Smckusick%%
68*50835Scael[A.Em \-Z] putchar(yytext[0]+\&'a\&'\-\&'A\&');
6927078Skarels[ ]+$	;
70*50835Scael[ ]+	putchar(\&' \&');
71*50835Scael.Ed
72*50835Scael.Pp
7319431Smckusickis an example of a
74*50835Scael.Nm lex
7519431Smckusickprogram that would be put into a
76*50835Scael.Nm lex
7719431Smckusickcommand file.  This program converts upper case to lower,
7819431Smckusickremoves blanks at the end of lines,
7919431Smckusickand replaces multiple blanks by single blanks.
80*50835Scael.Sh SEE ALSO
81*50835Scael.Xr yacc 1 ,
82*50835Scael.Xr sed 1
83*50835Scael.Rs
84*50835Scael.%A M. E. Lesk
85*50835Scael.%A E. Schmidt
86*50835Scael.%T "The LEX \- Lexical Analyzer Generator"
87*50835Scael.Re
88