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 After the floating-point constant is recognized, it is scanned by the for loop to find the letter "d" or "D". The program then adds 'e'-'d', which converts it to the next letter of the alphabet. The modified constant, now single precision, is written out again. A series of names follows that must be respelled to remove their initial d. By using the array yytext, the same action suffices for all the names (only a sample of a rather long list is given here). {d} {s} {i} {n} {d} {c} {o} {s} {d} {s} {q} {r} {t} {d} {a} {t} {a} {n} {d} {f} {I} {o} {a} {t} printf(" %s" ,yytext + 1 ); Another list of names must have initial d changed to initial a: {d} {I} {o} {g} I {d} {l} {o} {g} 10 I {d} {m }{i} {n} 1 I {d} {m} {a} {x} 1 { yytext[O] + = 'a' -'d'; ECHO; } And one routine must have init ial d changed to initial r: {d} 1 {m} {a} {c} {h} { yytext[O] + = 'r' - 'd'; ECHO; } To avoid such names as dsinx being detected as instances of dsin, some final rules pick up longer words as identifiers and copy some surviving characters: [A-Za-z] [A-Za-z0-9] * [0-9] + \n ECHO; Note that this program is not complete; it does not deal with the spacing problems in FORTRAN or with the use of keywords as identifiers. 9-21
lex: Lexical Analyzer Generator XENIX Programming Specifying Character Sets The programs generated by lex handle character 1/0 only through the routines input, output, and unput. Thus the character representation provided in these routines is accepted by lex and employed to return values in yytext. For internal use, a character is represented as a small integer that, if the standard library is used, has a value equal to the integer value of the bit pattern representing the character on the host computer. Normally, the letter a is represented as the same form as the character constant: 'a' If this interpretation is changed, by providing 1/0 routines that translate the characters, lex must be told about it, by giving a translation table. This table must be in the definitions section and must be bracketed by lines containing only %T. The table contains lines of the form { integer } { character-string} which indicate the value associated with each character. For example: %T 1 A a 2 Bb 26 Zz 27 \n 28 + 29 30 0 31 39 9 %T This table maps the lowercase and uppercase letters together into the integers 1 through 26, newline into 27, plus (+) and minus (-) into 28 and 29, and the digits into 30 through 39. Note the escape for newline. If a table is supplied, every character to appear either in the rules or in any valid input must be included in the table. No character may be assigned the number 0, and no character may be assigned a larger number than is supported by the hardware character set. Sou rce Format The general form of a lex source file is 9-22 { definitions } %% { rules } %% { user-subroutines }
- 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 182 and 183: 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 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
- Page 232 and 233: XENIX Programming yacc: Compiler-Co
- Page 234 and 235: XENIX Programming yacc: Compiler-Co
- Page 236 and 237: XENIX Programming %left %left %left
- Page 238 and 239: XENIX Programming I* lexical analys
- Page 240: XENIX Programming yacc: Compiler-Co
- Page 243 and 244: m4: Macro Processor XENIX Programmi
- Page 245 and 246: m4: Macro Processor XENIX Programmi
- Page 247 and 248: m4: Macro Processor XENIX Programm
<strong>XENIX</strong> Programming lex: Lexical Analyzer Generator<br />
After the floating-point constant is recognized, it is scanned by the for loop to find the<br />
letter "d" or "D". The program then adds 'e'-'d', which converts it to the next letter of<br />
the alphabet. The modified constant, now single precision, is written out again. A<br />
series of names follows that must be respelled to remove their initial d. By using the<br />
array yytext, the same action suffices for all the names (only a sample of a rather long<br />
list is given here).<br />
{d} {s} {i} {n}<br />
{d} {c} {o} {s}<br />
{d} {s} {q} {r} {t}<br />
{d} {a} {t} {a} {n}<br />
{d} {f} {I} {o} {a} {t} printf(" %s" ,yytext + 1 );<br />
Another list of names must have initial d changed to initial a:<br />
{d} {I} {o} {g} I<br />
{d} {l} {o} {g} 10 I<br />
{d} {m }{i} {n} 1 I<br />
{d} {m} {a} {x} 1 {<br />
yytext[O] + = 'a' -'d';<br />
ECHO;<br />
}<br />
And one routine must have init ial d changed to initial r:<br />
{d} 1 {m} {a} {c} {h} {<br />
yytext[O] + = 'r' - 'd';<br />
ECHO;<br />
}<br />
To avoid such names as dsinx being detected as instances of dsin, some final rules pick<br />
up longer words as identifiers and copy some surviving characters:<br />
[A-Za-z] [A-Za-z0-9] *<br />
[0-9] +<br />
\n<br />
ECHO;<br />
Note that this program is not complete; it does not deal with the spacing problems in<br />
FORTRAN or with the use of keywords as identifiers.<br />
9-21