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 yacc: Compiler-Compiler yacc Input Syntax if( islower( c)) { yylval = c -'a'; return ( LETTER); } if( isdigit( c)) { yylval = c -'0'; return( DIGIT ); } return( c); } This section has a description of the yacc input syntax, as a yacc specification. Context dependencies are not considered. Ironically, the yacc input specification language is most naturally specified as an LR(2) grammar; the difficult part comes when an identifier is seen in a rule, immediately following an action. If this identifier is followed by a colon, it is the start of the next rule; otherwise it is a continuation of the current rule, which just happens to have an action embedded in it. As implemented, the lexical analyzer looks ahead after seeing an identifier and decides whether the next token (skipping blanks, newlines, comments, etc.) is a colon. If so, it returns the token C_IDENTIFIER. Otherwise, it returns IDENTIFIER. Literals (quoted strings) are also returned as IDENTIFIER, but never as part of C_IDENTIFIER. I* grammar for the input to yacc *I I* basic entities *I %token IDENTIFIER /* includes identifiers and literals */ %token C IDENTIFIER /* identifier followed by colon *I %token NUMBER/* [0-9] + *I !* reserved words: %type = > TYPE, %left = > LEFT, etc. *I %token LEFT RIGHT NONASSOC TOKEN PREC TYPE START UNION %token MARK /* the %% mark *I %token LCURL /* the % {mark */ %token RCURL /* the %} mark */ %start spec %% I* ascii character literals stand for themselves */ spec : defs MARK rules tail tail : MARK { Eat up the rest of the file } I /* empty: the second MARK is optional */ 10-3 1
yacc: Compiler-Compiler 10-32 defs :/* empty */ I defs def def :START IDENTIFIER I UNION { Copy union definition to output } I LCURL {Copy C code to output file } RCURL I ndefs rword tag nlist rword : TOKEN I LEFT I RIGHT I NONASSOC I TYPE tag :/* empty: union tag is optional */ I'< ' IDENTIFIER '>' nlist : nmno I nlist nmno I nlist ',' nmno nmno : IDENTIFIER /* Literal illegal with %type */ I IDENTIFIER NUMBER /* Illegal with %type */ !* rules section */ rules : C IDENTIFIER rbody prec I rUles rule rule : C IDENTIFIER rbody prec I 'l'i-body prec rbody :/* empty *I I rbody IDENTIFIER I rbody act act : '{' {Copy action, translate $$, etc. } '}' prec :/* empty *I I PREC IDENTIFIER I PREC IDENTIFIER act I prec ';' XENIX Programming
- 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 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 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
- Page 249 and 250: m4: Macro Processor XENIX Programmi
- Page 251 and 252: m4: Macro Processor XENIX Programmi
- Page 253 and 254: C Language Portability XENIX Progra
- Page 255 and 256: C Language Portability XENIX Progra
- Page 257 and 258: C Language Portability XENIX Progra
- Page 259 and 260: C Language Portability XENIX Progra
- Page 261 and 262: C Language Portability XENIX Progra
- Page 263 and 264: C Language Portability XENIX Progra
- Page 266 and 267: APPENDIX B PROG RAMMING COMMANDS Th
- Page 268 and 269: XENIX Programming ad b (continued)
- Page 270 and 271: XENIX Programming Programming Comma
- Page 272 and 273: XENIX Programming Programming Comma
- Page 274 and 275: XENIX Programming Programming Comma
- Page 276 and 277: XENIX Programming Programming Comma
- Page 278 and 279: XENIX Programming Programming Comma
- Page 280 and 281: XENIX Programming Programming Comma
<strong>XENIX</strong> Programming yacc: Compiler-Compiler<br />
yacc Input Syntax<br />
if( islower( c)) {<br />
yylval = c -'a';<br />
return ( LETTER);<br />
}<br />
if( isdigit( c)) {<br />
yylval = c -'0';<br />
return( DIGIT );<br />
}<br />
return( c);<br />
}<br />
This section has a description of the yacc input syntax, as a yacc specification. Context<br />
dependencies are not considered. Ironically, the yacc input specification language is<br />
most naturally specified as an LR(2) grammar; the difficult part comes when an<br />
identifier is seen in a rule, immediately following an action. If this identifier is<br />
followed by a colon, it is the start of the next rule; otherwise it is a continuation of the<br />
current rule, which just happens to have an action embedded in it. As implemented, the<br />
lexical analyzer looks ahead after seeing an identifier and decides whether the next<br />
token (skipping blanks, newlines, comments, e<strong>tc</strong>.) is a colon. If so, it returns the token<br />
C_IDENTIFIER. Otherwise, it returns IDENTIFIER. Literals (quoted strings) are also<br />
returned as IDENTIFIER, but never as part of C_IDENTIFIER.<br />
I* grammar for the input to yacc *I<br />
I* basic entities *I<br />
%token IDENTIFIER /* includes identifiers and literals */<br />
%token C IDENTIFIER /* identifier followed by colon *I<br />
%token NUMBER/* [0-9] + *I<br />
!* reserved words: %type = > TYPE, %left = > LEFT, e<strong>tc</strong>. *I<br />
%token LEFT RIGHT NONASSOC TOKEN PREC TYPE START UNION<br />
%token MARK /* the %% mark *I<br />
%token LCURL /* the % {mark */<br />
%token RCURL /* the %} mark */<br />
%start spec<br />
%%<br />
I* ascii character literals stand for themselves */<br />
spec : defs MARK rules tail<br />
tail : MARK { Eat up the rest of the file }<br />
I /* empty: the second MARK is optional */<br />
10-3 1