Intel XENIX 286 Programmers Guide (86) - Tenox.tc
Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc
XENIX Programming lex: Lexical Analyzer Generator The library is accessed by the linker flag -11. So an appropriate set of commands is lex source cc lex.yy.c -II The resulting program is placed in the usual file a.out for later execution. To use lex with yacc see the section "lex and yacc" later in this chapter and also Chapter 10, "yacc: Compiler-Compiler." Although the default lex I/0 routines use the C standard library, the lex automata themselves do not do so. If private versions of input, output, and unput are given, the standard C library can be avoided. Specifying Character Classes Classes of characters can be specified using brackets: [ and ]. The construction [abc] matches a single character, which may be a, b, or c. Within square brackets, most operator meanings are ignored. Only three characters are special: the backslash (\}, the hyphen (-), and the caret ("). The hyphen indicates ranges. For example [a-z0-9< > ] indicates the character class containing all the lowercase letters, the digits, the angle brackets, and underscore. Ranges may be given in either ascending or descending order. Using the hyphen between any pair of characters that are not both uppercase letters, both lowercase letters, or both digits is implementation dependent and causes a warning message. If you want the hyphen in a character class, it should be first or last; thus [- + 0-9] matches all the digits and the plus and min us signs. In character classes, the caret (") operator must appear as the first character after the left bracket; it indicates that the resulting string is to be complemented with respect to the computer character set. Thus ["'abc] matches all characters except a, b, or c, including all special or control characters; or ["' a-zA-Z] is any character that is not a letter. The backslash (\) provides an escape mechanism within character class brackets, so that characters can be entered literally by preceding them with this character. Escaping into octal is possible although nonportable. For example [ \40-\ 1 76] matches all printable characters in the ASCII character set, from octal 40 (blank) to octal 176 (tilde). 9-5
lex: Lexical Analyzer Generator XENIX Programming Specifying an Arbitrary Character To match almost any character, the period (.) designates the class of all characters except a newline. Specifying Optional Expressions The question mark (?) operator indicates an optional element of an expression. Thus ab?c matches either ac or abc. Note that the meaning of the question mark here differs from its meaning in the shell. Specifying Repeated Expressions Repetitions of classes are indicated by the asterisk (*) and plus (+) operators. For example a* matches any nu mber of consecutive a characters, including zero, while a+ matches one or more instances of a. For example [a-z] + matches all strings of lowercase letters, and [A-Za-z][A-Za-z0-9]* matches all alphanumeric strings with a leading alphabetic character; this is a typical expression for recognizing identifiers in computer languages. 9-6
- Page 131 and 132: as: A sse m bier XENIX Programming
- Page 133 and 134: as: Assembler XENIX Programming The
- Page 135 and 136: as: Assembler XENIX Programming Key
- Page 137 and 138: as: Assembler The combination rules
- Page 139 and 140: as: Assembler XENIX Programming Ins
- Page 141 and 142: as: Assembler Initial Value Directi
- Page 143 and 144: as: Assembler XENIX Programming int
- Page 145 and 146: as: A sse m bier sub subb test test
- Page 147 and 148: as: Assembler XENIX Programming lnt
- Page 149 and 150: as: Assembler XENIX Programming lnt
- Page 151 and 152: as: Assembler XENIX Programming Imm
- Page 153 and 154: as: A sse m bier XENIX Programming
- Page 156 and 157: CHAPTER 8 csh : C SHEll The C shell
- Page 158 and 159: XENIX Programming csh: C Shell Some
- Page 160 and 161: XENIX Programm ing *w 32 * q % !c -
- Page 162 and 163: XENIX Programming csh: C Shell the
- Page 164 and 165: XENIX Programming csh: C Shell Usin
- Page 166 and 167: XENIX Programming csh: C Shell Usin
- Page 168 and 169: XENIX Programming csh: C Shell The
- Page 170 and 171: XENIX Programming csh: C Shell Note
- Page 172 and 173: XENIX Programming switch ( string c
- Page 174 and 175: XENIX Programming csh: C Shell Star
- Page 176 and 177: XENIX Programming csh: C Shell Spec
- Page 178 and 179: CHAPTER 9 lex : LEXICAL ANA LYZER G
- Page 180 and 181: XENIX Programming lex: Lexical Anal
- Page 184 and 185: XENIX Programming lex: Lexical Anal
- Page 186 and 187: XENIX Programming lex: Lexical Anal
- Page 188 and 189: XENIX Programming lex: Lexical Anal
- Page 190 and 191: XENIX Programming lex: Lexical Anal
- Page 192 and 193: XENIX Programm ing lex: Lexical Ana
- Page 194 and 195: XENIX Programming Specifying Source
- Page 196 and 197: XENIX Programming lex: Lexical Anal
- Page 198 and 199: XENIX Programming lex: Lexical Anal
- Page 200 and 201: XENIX Programming The definitions s
- Page 202 and 203: CHAPTER 10 yacc: COMPILER-COMPILER
- Page 204 and 205: XENIX Programming yacc: Compiler-Co
- Page 206 and 207: XENIX Programming yacc: Compiler-Co
- Page 208 and 209: XENIX Programming yacc: Compiler-Co
- Page 210 and 211: XENIX Programming yacc: Compiler-Co
- Page 212 and 213: XENIX Programming yacc: Compiler-Co
- Page 214 and 215: XENIX Programming yacc: Compiler-Co
- Page 216 and 217: XENIX Programming yacc: Compiler-Co
- Page 218 and 219: XENIX Programming yacc: Compiler-Co
- Page 220 and 221: XENIX Programming yacc: Compiler-Co
- Page 222 and 223: XENIX Programming yacc: Compiler-Co
- Page 224 and 225: XENIX Programming yacc: Compiler-Co
- Page 226 and 227: XENIX Programming yacc: Compiler-Co
- Page 228 and 229: XENIX Programming yacc: Compiler-Co
- Page 230 and 231: XENIX Programming yacc: Compiler-Co
<strong>XENIX</strong> Programming lex: Lexical Analyzer Generator<br />
The library is accessed by the linker flag -11. So an appropriate set of commands is<br />
lex source<br />
cc lex.yy.c -II<br />
The resulting program is placed in the usual file a.out for later execution. To use lex<br />
with yacc see the section "lex and yacc" later in this chapter and also Chapter 10,<br />
"yacc: Compiler-Compiler." Although the default lex I/0 routines use the C standard<br />
library, the lex automata themselves do not do so. If private versions of input, output,<br />
and unput are given, the standard C library can be avoided.<br />
Specifying Character Classes<br />
Classes of characters can be specified using brackets: [ and ]. The construction<br />
[abc]<br />
ma<strong>tc</strong>hes a single character, which may be a, b, or c. Within square brackets, most<br />
operator meanings are ignored. Only three characters are special: the backslash (\}, the<br />
hyphen (-), and the caret ("). The hyphen indicates ranges. For example<br />
[a-z0-9< > ]<br />
indicates the character class containing all the lowercase letters, the digits, the angle<br />
brackets, and underscore. Ranges may be given in either ascending or descending order.<br />
Using the hyphen between any pair of characters that are not both uppercase letters,<br />
both lowercase letters, or both digits is implementation dependent and causes a warning<br />
message. If you want the hyphen in a character class, it should be first or last; thus<br />
[- + 0-9]<br />
ma<strong>tc</strong>hes all the digits and the plus and min us signs.<br />
In character classes, the caret (") operator must appear as the first character after the<br />
left bracket; it indicates that the resulting string is to be complemented with respect to<br />
the computer character set. Thus<br />
["'abc]<br />
ma<strong>tc</strong>hes all characters except a, b, or c, including all special or control characters; or<br />
["' a-zA-Z]<br />
is any character that is not a letter. The backslash (\) provides an escape mechanism<br />
within character class brackets, so that characters can be entered literally by preceding<br />
them with this character. Escaping into octal is possible although nonportable. For<br />
example<br />
[ \40-\ 1 76]<br />
ma<strong>tc</strong>hes all printable characters in the ASCII character set, from octal 40 (blank) to<br />
octal 176 (tilde).<br />
9-5