SCCS-vsn: old/lex/PSD.doc/lex.ms 6.1
-.\" @(#)lex.ms 5.1 (Berkeley) %G%
+.\" @(#)lex.ms 6.1 (Berkeley) %G%
+.EH 'PS1:16-%''Lex \- A Lexical Analyzer Generator'
+.OH 'Lex \- A Lexical Analyzer Generator''PS1:16-%'
-.de PT
-.if \\n%>1 'tl ''\s7LEX\s0\s9\(mi%\s0''
-.if \\n%>1 'sp
-..
+.\".de PT
+.\".if \\n%>1 'tl ''\s7LEX\s0\s9\(mi%\s0''
+.\".if \\n%>1 'sp
+.\"..
-.RP
-.TM 75-1274-15 39199 39199-11
+.\".RP
+.\".TM 75-1274-15 39199 39199-11
.TL
Lex \- A Lexical Analyzer ~Generator~
.AU ``MH 2C-569'' 6377
.TL
Lex \- A Lexical Analyzer ~Generator~
.AU ``MH 2C-569'' 6377
-.nr PS 8
-.nr VS 9
-.ps 8
-.vs 9p
+.\".nr PS 8
+.\".nr VS 9
+.\".ps 8
+.\".vs 9p
Lex helps write programs whose control flow
is directed by instances of regular
expressions in the input stream.
Lex helps write programs whose control flow
is directed by instances of regular
expressions in the input stream.
interfacing with Yacc, for those
with access to this compiler-compiler system.
..
interfacing with Yacc, for those
with access to this compiler-compiler system.
..
+.\".nr PS 9
+.\".nr VS 11
-.SH
-.ce 1
-Table of Contents
-.LP
-.ce 100
-.TS
-r 1l 2r .
-1. Introduction. 1
-2. Lex Source. 3
-3. Lex Regular Expressions. 3
-4. Lex Actions. 5
-5. Ambiguous Source Rules. 7
-6. Lex Source Definitions. 8
-7. Usage. 8
-8. Lex and Yacc. 9
-9. Examples. 10
-10. Left Context Sensitivity. 11
-11. Character Set. 12
-12. Summary of Source Format. 12
-13. Caveats and Bugs. 13
-14. Acknowledgments. 13
-15. References. 13
-.TE
-.ce 0
or by hand, can
be added easily to programs written by Lex.
.BS 2
or by hand, can
be added easily to programs written by Lex.
.BS 2
.BE
Yacc users
will realize that the name
.BE
Yacc users
will realize that the name
the ambiguity of ``=\(mia''.
Suppose it is desired to treat this as ``=\(mi a''
but print a message. A rule might be
the ambiguity of ``=\(mia''.
Suppose it is desired to treat this as ``=\(mi a''
but print a message. A rule might be
.TS
center;
l l.
=\(mi[a\-zA\-Z] {
.TS
center;
l l.
=\(mi[a\-zA\-Z] {
- printf("Operator (=\(mi) ambiguous\en");
+ printf("Op (=\(mi) ambiguous\en");
yyless(yyleng\-1);
... action for =\(mi ...
}
.TE
yyless(yyleng\-1);
... action for =\(mi ...
}
.TE
which prints a message, returns the letter after the
operator to the input stream, and treats the operator as ``=\(mi''.
Alternatively it might be desired to treat this as ``= \(mia''.
To do this, just return the minus
sign as well as the letter to the input:
which prints a message, returns the letter after the
operator to the input stream, and treats the operator as ``=\(mi''.
Alternatively it might be desired to treat this as ``= \(mia''.
To do this, just return the minus
sign as well as the letter to the input:
.TS
center;
l l.
=\(mi[a\-zA\-Z] {
.TS
center;
l l.
=\(mi[a\-zA\-Z] {
- printf("Operator (=\(mi) ambiguous\en");
+ printf("Op (=\(mi) ambiguous\en");
yyless(yyleng\-2);
... action for = ...
}
.TE
yyless(yyleng\-2);
... action for = ...
}
.TE
will perform the other interpretation.
Note that the expressions for the two cases might more easily
be written
will perform the other interpretation.
Note that the expressions for the two cases might more easily
be written
-[a\-z][a\-z] {digram[yytext[0]][yytext[1]]++; REJECT;}
-. ;
+[a\-z][a\-z] {
+ digram[yytext[0]][yytext[1]]++;
+ REJECT;
+ }
+\. ;
\en ;
.TE
where the REJECT is necessary to pick up
\en ;
.TE
where the REJECT is necessary to pick up
int k;
\-?[0\-9]+ {
k = atoi(yytext);
int k;
\-?[0\-9]+ {
k = atoi(yytext);
- printf("%d", k%7 == 0 ? k+3 : k);
+ printf("%d",
+ k%7 == 0 ? k+3 : k);
}
\-?[0\-9.]+ ECHO;
[A-Za-z][A-Za-z0-9]+ ECHO;
}
\-?[0\-9.]+ ECHO;
[A-Za-z][A-Za-z0-9]+ ECHO;
x|y an x or a y.
(x) an x.
x/y an x but only if followed by y.
x|y an x or a y.
(x) an x.
x/y an x but only if followed by y.
-{xx} the translation of xx from the definitions section.
+{xx} the translation of xx from the
+ definitions section.
x{m,n} \fIm\fR through \fIn\fR occurrences of x
.TE
.NH
x{m,n} \fIm\fR through \fIn\fR occurrences of x
.TE
.NH