xref: /original-bsd/old/lex/lex.1 (revision ea3a8ee8)
1.\" Copyright 1991 The Regents of the University of California.
2.\" All rights reserved.
3.\"
4.\" %sccs.include.proprietary.roff%
5.\"
6.\"	@(#)lex.1	6.3 (Berkeley) 08/09/91
7.\"
8.Dd
9.Dt LEX 1
10.Os ATT 7th
11.Sh NAME
12.Nm lex
13.Nd generator of lexical analysis programs
14.Sh SYNOPSIS
15.Nm lex
16.Op Fl tvfn
17.Op Ar file
18.Ar ...
19.Sh DESCRIPTION
20The
21.Nm lex
22command
23generates programs to be used in simple lexical analyis of text.
24The input
25.Em files
26(standard input default) contain regular expressions
27to be searched for, and actions written in C to be executed when
28expressions are found.
29.Pp
30A C source program, 'lex.yy.c' is generated, to be compiled thus:
31.Bd -literal -offset indent
32cc lex.yy.c.Fl ll
33.Ed
34.Pp
35This program, when run, copies unrecognized portions of
36the input to the output, and executes the associated
37C action for each regular expression that is recognized.
38.Pp
39The options have the following meanings.
40.Bl -tag -width indent
41.It Fl t
42Place the result on the standard output instead of in file
43.Pa lex.yy.c .
44.It Fl v
45Print a one-line
46summary of statistics of the generated analyzer.
47.It Fl n
48Opposite of
49.Fl v ;
50.Fl n
51is default.
52.It Fl f
53"Faster" compilation: don't bother to pack
54the resulting tables; limited to small programs.
55.Sh EXAMPLE
56.Bd -literal -offset indent
57lex lexcommands
58.Ed
59.Pp
60would draw
61.Nm lex
62instructions from the file
63.Pa lexcommands ,
64and place the output in
65.Pa lex.yy.c
66.Bd -literal -offset indent
67%%
68[A.Em \-Z] putchar(yytext[0]+\&'a\&'\-\&'A\&');
69[ ]+$	;
70[ ]+	putchar(\&' \&');
71.Ed
72.Pp
73is an example of a
74.Nm lex
75program that would be put into a
76.Nm lex
77command file.  This program converts upper case to lower,
78removes blanks at the end of lines,
79and replaces multiple blanks by single blanks.
80.Sh SEE ALSO
81.Xr yacc 1 ,
82.Xr sed 1
83.Rs
84.%A M. E. Lesk
85.%A E. Schmidt
86.%T "The LEX \- Lexical Analyzer Generator"
87.Re
88