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 Specifying Source Definitions Remember the format of the lex source: { definitions } %% { rules } %% { user-routines } lex: Lexical Analyzer Generator So far only the rules have been described. You will need additional options, though, to define variables for use in your program and for use by lex. These can go either in the definitions section or in the rules section. Remember that lex is turning the rules into a program. Any source not intercepted by lex is copied into the generated program. There are three types of copied source lines: • Any line not part of a lex rule or action that begins with a blank or tab is copied into the lex generated program. Such source input prior to the first %% delimiter will be external to any function in the code; if it appears immediately after the first %%, it appears in an appropriate place for declarations in the function written by lex that contains the actions. This material must look like program fragments and should precede the first lex rule. As a side effect of the above, lines that begin with a blank or tab, and that contain a comment, are passed through to the generated program. This can be used to include comments in either the lex source or the generated code. The comments should follow the conventions of the C language. • Anything included between lines containing only %{ and %} is copied out as above. The delimiters are discarded. This format permits entering text like preprocessor statements that must begin in column 1 or copying lines that do not look like programs. • Anything after the third %% delimiter, regardless of formats, is copied out after the lex output. Definitions intended for lex are given before the first %% delimiter. Any line in this section not contained between %{ and %}, and beginning in colu mn 1, is assumed to define lex substitution strings. The format of such lines is name translation and it causes the string given as a translation to be associated with the name. The name and translation must be separated by at least one blank or tab, and the name must begin with a letter. The translation can then be called out by the {name} syntax in a rule. Using {D} for the digits and {E} for an exponent field, for example, might abbreviate rules to recognize numbers: 9-17
lex: Lexical Analyzer Generator XENIX Programming D [0-9] E [DEde][- + ]?{D} + %% {D} + {D} + II . II {D}*( {E} )? {D}* II . " {D} + ( {E} )? {D} + {E} II) ; pri ntf(" integer I I printf(ll real "); Note the first two rules for real numbers; both require a decimal point and contain an optional exponent field, but the first requires at least one digit before the decimal point, and the second requires at least one digit after the decimal point. To correctly handle the problem posed by a FORTRAN expression such as 35.EQ.I, which does not contain a real number, a context-sensitive rule such as [0-9] +f".11 EQ pri ntf("integer"); could be used in addition to the normal rule for integers. The definitions section may also contain other commands, including a character set table, a list of start conditions, or adjustments to the default size of arrays within lex itself for larger source programs. These possibilities are discussed later in the section "Source Format." lex and yacc If you want to use lex with yacc, note that what lex writes is a program named yylex, the name required by yacc for its analyzer. Normally, the default main program in the lex library calls this routine, but if yacc is loaded, and its main program is used, yacc will call yylex. In this case, each lex rule should end with retu rn(token); where the appropriate token value is returned. An easy way to access yacc's names for tokens is to compile the lex output file as part of the yacc output file by placing the line # include "lex.yy.c" in the last section of yacc input. Suppose the grammar is to be named good and the lexical rules are to be named better; the XENIX command sequence can just be % yacc good % lex better % cc y.tab.c -ly -II The yacc library (-ly) should be loaded before the lex library to obtain a main program that invokes the yacc parser. The generation of lex and yacc programs can be done in either order. 9-18
- 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 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 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
- 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
<strong>XENIX</strong> Programming<br />
Specifying Source Definitions<br />
Remember the format of the lex source:<br />
{ definitions }<br />
%%<br />
{ rules }<br />
%%<br />
{ user-routines }<br />
lex: Lexical Analyzer Generator<br />
So far only the rules have been described. You will need additional options, though, to<br />
define variables for use in your program and for use by lex. These can go either in the<br />
definitions section or in the rules section.<br />
Remember that lex is turning the rules into a program. Any source not intercepted by<br />
lex is copied into the generated program. There are three types of copied source lines:<br />
• Any line not part of a lex rule or action that begins with a blank or tab is copied<br />
into the lex generated program. Such source input prior to the first %% delimiter<br />
will be external to any function in the code; if it appears immediately after the<br />
first %%, it appears in an appropriate place for declarations in the function<br />
written by lex that contains the actions. This material must look like program<br />
fragments and should precede the first lex rule.<br />
As a side effect of the above, lines that begin with a blank or tab, and that contain<br />
a comment, are passed through to the generated program. This can be used to<br />
include comments in either the lex source or the generated code. The comments<br />
should follow the conventions of the C language.<br />
• Anything included between lines containing only %{ and %} is copied out as above.<br />
The delimiters are discarded. This format permits entering text like preprocessor<br />
statements that must begin in column 1 or copying lines that do not look like<br />
programs.<br />
• Anything after the third %% delimiter, regardless of formats, is copied out after<br />
the lex output.<br />
Definitions intended for lex are given before the first %% delimiter. Any line in this<br />
section not contained between %{ and %}, and beginning in colu mn 1, is assumed to<br />
define lex substitution strings. The format of such lines is<br />
name translation<br />
and it causes the string given as a translation to be associated with the name. The name<br />
and translation must be separated by at least one blank or tab, and the name must begin<br />
with a letter. The translation can then be called out by the {name} syntax in a rule.<br />
Using {D} for the digits and {E} for an exponent field, for example, might abbreviate<br />
rules to recognize numbers:<br />
9-17