if ( rvalue ) statement1 else statement2 ;
*0 null *e end-of-file *( { *) } *t tab ** * *' ' *" " *n new line
a(b/c+d[3])
x = y
3 = x a+b = x f(3) = x
*3 = x
f(2) + g(3)
if ( rvalue ) statement1 else statement2 ;
if ( rvalue ) statement ;
if( a<b ) x=a; else x=b;
while ( rvalue ) statement1 ;
i = 10; while( i-- ) f();
while (v[++i]) ;
switch ( rvalue ) statement1
case constant :
switch(x) { case 'a': y = 1 ; case 'b': z = 2; }
default:
goto rvalue ;
break ;
while (i--) { j = f(i); switch (j) { case 1: x = 5; break; case 2: case 3: x = g(j); } labl: if( j < 0 ){ xy = 3; break; } xy = j/2; more: ...
return ;
return ( rvalue ) ;
extrn name1 , name2 ... ;
auto def1 , def2 ... ;
name
name [ constant ]
name ;
main(); exit();
name ;
name ival ;
name [ ] ; name [ constant ] ; name [ ] ival , ival . . . ; name [ constant ] ival , ival . . . ;
(name ( arguments ) statement
min(a,b) { if( a<b ) return(a); else return(b); }
while( putchar(getchar()) != '*n') ;
putstr(getstr(a)); putchar('*n' );
c -- character data (in ascii) d -- a decimal number o -- an octal number s -- a character string
printf("%d + %o is %s or %c*n", 1,-1,"zero",'0');
1 + 777777777777 is zero or 0
wr.unit = -1; printf("filsys cf %s,b/%d/,r*n", s, n);
ioerrors( n );
n = getarg(a1,b,O); n = getarg(a2,b,n); getarg(a3,b,n);
"well done"
/* The following complete B program, if compiled and put on your file "hstar", will act as an ascii file copy routine; the command at "SYSTEM?" level: /hstar file1 file2 will copy file1 to file2. */ main () { auto j,s[20],t[20]; reread(); /* get command line */ getstr(s); /* put into s */ j = getarg(t,s,0); /* skip H* name */ j = getarg(t,s,j); /* filel */ openr( 5,t ); getarg(t,s,j); /* file2 */ openw( 6,t ); while( putchar( getchar() ) != '*e' ) ; /* copy contents */ }
/* This function is called with a string s of the form nnn, nnn, nnn, . . . , where the nnn are integers. The values are placed in successive locations in a vector v. The number of integers converted is returned as a function value. This program provides a simple illustration of the switch and case state- ments. */ convert(s,v) { auto m,i,j,c,sign; i = O; /* vector index '/ j =-1; /* character index */ init: /* initialize to convert an integer */ m = 0; /* the integer value '/ sign = 0; /* sign = 1 if the integer is negative */ loop: /* convert an integer */ switch (C = char(s,++j)){ case '-': if(sign) goto syntax; s = 1; case ' ': goto loop; case '*e': case ',': /* delimiter . . . store converted value */ v[i++] = sign?(-m):m; if( c == '*e' ) return(i); goto init; } /* none of the above cases . . . if a digit, add to m */ if ( '0' <= c & c <= '9' ){ m = 10*m + c- '0'; goto loop; } /* syntax error . . . print message and return -1 */ syntax: printf("bad syntax*n"); return(-1 ); }
/* This function replaces each upper case character in the input string s by its lower case equivalent. It uses the fact that the ascii alphabetic characters are contiguous. */ lower(s) { auto c,i; i = -1 ; while( (c=char(s,++i)) != '*e' ) if( c >= 'A' & c <= 'Z' ) lchar(s~i~c-'A'+'a'); }
/* This function prints out an unsympathetic error message on the terminal for each integer value of errno from O to 5 */ snide(errno) { extrn wr.unit, mess; auto u; /* temporary storage for the unit number */ u = wr.unit ; wr.unit = 1; printf("error number %d, %s*n'*,errno,mess[errno]"); wr.unit = u; } mess [5] "too bad", "tough luck", "sorry, Charlie", "that's the breaks", "what a shame", "some days you can't win";
./bj [(options)] [source [hstar] ] [spec] [spec] [spec] . . .
h=cat/file r=cat/file l=cat/file s=nnn
./bj name hstar
./bj (w) name hstar
./bj name hstar r=abc/blib
./bj name hstar l=lib1 r=lib2 l=lib3
tsx1 sub,* zero s,n
sub zero *+1 pointer to code adx7 0,1 advance stack pointer stx1 0,7 store return address on stack
ldx1 0,7 restore return address sbx7 0,1 restore stack pointer tra 1,1 return
symref .10000 tra .10000
sta 1,7
staq 1,7
$ gmap symdef add2 add2 zero *+1 sta temp store first argument adq temp add to second tra 1,1 return with result in Q temp zero end
staq1,7
if( a&077 )goto label;
if( (a&077) != O )goto label;