%term LETTER DIGIT SQRT _IF FFF EQ
%term _WHILE _FOR NE LE GE INCR DECR
%term _RETURN _BREAK _DEFINE BASE OBASE SCALE
%term EQPL EQMI EQMUL EQDIV EQREM EQEXP
char cary[1000], *cp { cary };
char string[1000], *str {string};
int rcrs '0'; /* reset crs */
" 0", " 1", " 2", " 3", " 4", " 5",
" 6", " 7", " 8", " 9", " 10", " 11",
| start def dargs ')' '{' dlist slist '}'
={ bundle( pre, $7, post );
={ bundle( $1, "ps." ); }
={ bundle( $3, "s", $1 ); }
={ bundle( $6, $3, ":", geta($1)); }
={ bundle( "l", $1, $3, $2, "s", $1 ); }
| LETTER '[' e ']' EQOP e
={ bundle($3, ";", geta($1), $6, $5, $3, ":", geta($1));}
={ bundle( numb[lev-bstack[bindx-1]], "Q" ); }
= bundle( $3, post, numb[lev], "Q" );
= bundle( "0", post, numb[lev], "Q" );
| _IF CRS BLEV '(' re ')' stat
| _WHILE CRS '(' re ')' stat BLEV
| fprefix CRS re ';' e ')' stat BLEV
={ bundle( $7, $5, "s.", $3, $2 );
bundle( $1, "s.", $3, $2, " " );
= bundle( $1, $3, "!=" );
= bundle( $1, $3, "!>" );
= bundle( $1, $3, "!<" );
= bundle( " 0", $2, "-" );
= bundle( $1, $3, "%%" );
={ bundle($3, ";", geta($1)); }
= bundle( "l", $1, "d1+s", $1 );
= bundle( "l", $2, "1+ds", $2 );
= bundle( "l", $2, "1-ds", $2 );
= bundle( "l", $1, "d1-s", $1 );
= bundle($3,";",geta($1),"d1+",$3,":",geta($1));
= bundle($4,";",geta($2),"1+d",$4,":",geta($2));
= bundle($3,";",geta($1),"d1-",$3,":",geta($1));
= bundle($4,";",geta($2),"1-d",$4,":",geta($2));
= bundle( $3, "l", getf($1), "x" );
= bundle( "l", getf($1), "x" );
={ bundle( " ", $1, ".", $3 ); }
={ bundle( " ", $1, "." ); }
={ bundle( $3, "ds", $1 ); }
| LETTER EQOP e %prec '='
={ bundle( "l", $1, $3, $2, "ds", $1 ); }
= bundle("K",$3,$2,"dk");
= bundle("I",$3,$2,"di");
= bundle("O",$3,$2,"do");
={ $$ = cp; *cp++ = '_'; }
={ $$ = cp; *cp++ = $1; }
={ $$ = cp; *cp++ = crs++; *cp++ = '\0'; bstack[bindx++] = lev++; }
01,02,03,04,05,06,07,010,011,012,013,014,015,016,017,
020,021,022,023,024,025,026,027,030,031,032 };
0241,0242,0243,0244,0245,0246,0247,0250,0251,0252,0253,
0254,0255,0256,0257,0260,0261,0262,0263,0264,0265,0266,
"a","b","c","d","e","f","g","h","i","j",
"k","l","m","n","o","p","q","r","s","t",
"u","v","w","x","y","z" } ;
while( c == ' ' || c == '\t' ) c = getc();
if( c<= 'z' && c >= 'a' ) {
/* look ahead to look for reserved words */
if( peekc >= 'a' && peekc <= 'z' ){ /* must be reserved word */
if( c=='i' && peekc=='f' ){ c=_IF; goto skip; }
if( c=='w' && peekc=='h' ){ c=_WHILE; goto skip; }
if( c=='f' && peekc=='o' ){ c=_FOR; goto skip; }
if( c=='s' && peekc=='q' ){ c=SQRT; goto skip; }
if( c=='r' && peekc=='e' ){ c=_RETURN; goto skip; }
if( c=='b' && peekc=='r' ){ c=_BREAK; goto skip; }
if( c=='d' && peekc=='e' ){ c=_DEFINE; goto skip; }
if( c=='s' && peekc=='c' ){ c= SCALE; goto skip; }
if( c=='b' && peekc=='a' ){ c=BASE; goto skip; }
if( c=='o' && peekc=='b' ){ c=OBASE; goto skip; }
if( c=='d' && peekc=='i' ){ c=FFF; goto skip; }
if( c=='a' && peekc=='u' ){ c=_AUTO; goto skip; }
if( c == 'q' && peekc == 'u')getout();
skip: /* skip over rest of word */
while( (ch = getc()) >= 'a' && ch <= 'z' );
/* usual case; just one single letter */
if( c>= '0' && c <= '9' || c>= 'A' && c<= 'F' ){
switch( peekc = getc() ){
case '=': c=EQ; goto gotit;
case '+': c=EQPL; goto gotit;
case '-': c=EQMI; goto gotit;
case '*': c=EQMUL; goto gotit;
case '/': c=EQDIV; goto gotit;
case '%': c=EQREM; goto gotit;
case '^': c=EQEXP; goto gotit;
gotit: peekc = -1; return(c);
case '+': return( cpeek( '+', INCR, '+' ) );
case '-': return( cpeek( '-', DECR, '-' ) );
case '<': return( cpeek( '=', LE, '<' ) );
case '>': return( cpeek( '=', GE, '>' ) );
case '!': return( cpeek( '=', NE, '!' ) );
if((peekc = getc()) == '*'){
while((getc() != '*') || ((peekc = getc()) != '/'));
while((c=getc()) != '"')*str++ = c;
if( (peekc=getc()) != c ) return( no );
ch = (peekc < 0) ? getchar() : peekc;
if(ch != '\0')return(ch);
if(ifile >= sargc+2)getout();
if((fin = open(sargv[ifile],0)) >= 0)goto loop;
yyerror("cannot open input file");
int b_space [ b_sp_max ];
int * b_sp_nxt { b_space };
if( bdebug ) printf("bundle %d elements at %o\n", i, q );
for( p = &a; i-->0; ++p ){
if( b_sp_nxt >= & b_space[b_sp_max] ) yyerror( "bundling space exceeded" );
if( bdebug ) printf("routput(%o)\n", p );
if( p >= &b_space[0] && p < &b_space[b_sp_max]){
while( *p != 0 ) routput( *p++ );
else printf( p ); /* character string */
conout( p, s ) int *p; char *s; {
/* puts the relevant stuff on pre and post for the letter s */
bundle( post, "L", s, "s." );
tp( s ) char *s; { /* same as pp, but for temps */
bundle( post, "L", s, "s." );
yyinit(argc,argv) int argc; char *argv[];{
signal( 2, getout ); /* ignore all interrupts */
if(sargc == 0)fin=dup(0);
else if((fin = open(sargv[1],0)) < 0)
yyerror("cannot open input file");
return(&funtab[*p -0141]);
return(&atab[*p - 0141]);
if (argc > 1 && *argv[1] == '-') {
printf("unrecognizable argument\n");
argv[1] = "/usr/lib/lib.b";
execl("/bin/dc", "dc", "-", 0);