Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

XENIX Programming I* lexical analysis *I yylex(){ register c; {I* skip over blanks *I } while( ( c = getchar( )) = = ' ' ) if ( isupper(c) ){ yylval.ival = c-'A'; return( VREG ); } if ( islower(c) ){ yylval.ival = c -'a'; return( DREG ); } if( isdigit( c) II c = = '.' ){ I* gobble up digits, points, exponents *I char buf[BSZ + 1], * cp = buf; int dot = 0, exp = 0; for( ; (cp-buf) < BSZ ; + + cp,c = getchar() ){ *cp = c; if ( isdigit(c) ) continue; if(c =='.' ){ if( dot + + ll exp ) return( '.' ); I* above causes syntax error *I continue; } if (c = = 'e' ) { if ( exp + + ) return( ' e' ); I* above causes syntax error *I continue; } I* end of number *I break; } *cp = '\eO'; if( (cp-buf) > = BSZ ) printf( "constant too long: truncated\n"); else ungetc( c, stdin ); I* above pushes back last char read *I yylval.dval = atof { buf ); return{ CONST ); } return{ c); } yacc: Compiler-Compiler 10-37

yacc: Compiler-Compiler 10-38 INTERVAL hilo( a, b, c, d ) double a, b, c, d; { I* returns the smallest interval containing a, b, c, and d *I I* used by *, I routines *I INTERVAL v; if( a>b) { v.hi = a; v.lo = b; } else { v.hi = b; v.lo = a; } if( c>d ) { if ( c>v.hi ) v.hi = c; if ( d v.hi ) v.hi = d; if ( c = 0. && v.lo < = 0. ){ printf( "divisor interval contains 0.\n" ); return( 1); } return(O); } INTERVAL vdiv( a, b, v) double a, b; INTERVAL v; { return( hilo( alv.hi, alv.lo, blv.hi, blv.lo) ); } XENIX Programming

yacc: Compiler-Compiler<br />

10-38<br />

INTERVAL hilo( a, b, c, d ) double a, b, c, d; {<br />

I* returns the smallest interval containing a, b, c, and d *I<br />

I* used by *, I routines *I<br />

INTERVAL v;<br />

if( a>b) { v.hi = a; v.lo = b; }<br />

else { v.hi = b; v.lo = a; }<br />

if( c>d ) {<br />

if ( c>v.hi ) v.hi = c;<br />

if ( d v.hi ) v.hi = d;<br />

if ( c = 0. && v.lo < = 0. ){<br />

printf( "divisor interval contains 0.\n" );<br />

return( 1);<br />

}<br />

return(O);<br />

}<br />

INTERVAL vdiv( a, b, v) double a, b; INTERVAL v; {<br />

return( hilo( alv.hi, alv.lo, blv.hi, blv.lo) );<br />

}<br />

<strong>XENIX</strong> Programming

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!