main( ) { -- statements -- } newfunc(arg1, arg2) { -- statements -- } fun3(arg) { -- more statements -- }
(a) SYSTEM? filsys cf bsource,b/1,100/ (b) SYSTEM? filsys cf bhs,b/6,6/,m/r/ (c) SYSTEM? [create source program with any text editor] (d) SYSTEM? ./bj (w) bsource bhs (e) SYSTEM? /bhs
ee n ee name n
main( ) { auto a, b, c, sum; a = 1; b = 2; c = 3; sum = a+b+c; putnumb(sum); }
x = a%b
main( ) { auto a; a= 'hi!'; putchar(a); putchar('*n' ); }
c = c+'A'-'a';
main( ) { extrn a, b, c; putchar(a); putchar(b); putchar(c); putchar('!*n'); } a 'hell'; b 'o, w'; c 'orld';
main( ) { extrn a,b,c,d; put2char(a,b) ; put2char(c,d) ; } put2char(x,y) { putchar(x); putchar(y); } a 'hell'; b 'o, w'; c 'orld'; d '!*n';
put2char( 'hell','o, w'); etc.
main( ) { auto c; c= getchar(); putchar(c); }
== equal to (".EQ." to Fortraners) != not equal to > greater than < less than >= greater than or equal to <= less than or equal to
main( ) { auto c; read: c= getchar(); putchar(c); if(c != '*n') goto read; } /* loop if not a newline */
if (expression) statement
if(a<b) { t = a; a = b; b = t; }
read: c = putchar(getchar()); if (c != '*n') goto read;
read: if (putchar(getchar()) != '*n') goto read;
while ((c=getchar()) != '*n') putchar(c);
while (expression) statement
(a) evaluate the expression (b) if its value is true (i. e., not zero), do the statement and return to (a)
x = y = f(a)+g(b)
c = getchar() != '*n'
main( ) { auto c; while (1) { while ( (c=getchar()) != ' ') if (putchar(c) == '*n') exit(); putchar( '*n' ); while ( (c=getchar()) == ' '); /* skip blanks */ if (putchar(c)=='*n') exit(); /* done when newline */ } }
while(1){ --- }
if (expression) statement else statement2
if (a<b) x=a; else x=b;
if(---) { ----- ----- } else if(---) { ----- ----- } else if(----) { ----- ----- }
x = a<b ? a : b;
auto k; k = 0; while (getchar() != '*n') ++k;
k++
x = ++k
x = k++
c = o; i = 36; while ((i = i-9) >= 0) c = c | getchar()<<i;
x = ~y&0777
x = x&077
x =- 10
x = -10
x =- 10
x=-10
x = x<<y|z
x =<< y|z
c= 0; i = 36; while ((i =- 9) >= 0) c =| getchar()<<i;
auto v[10];
sum = o; i = 0; while (i<=n) sum =+ V[i++];
i = -1; while (v[++i]);
extrn v;
v[10];
v[10] 'hi!', 1, 2, 3, 0777;
auto u[10], v[10]; --- u = v; v[0] = ... v[1] = ... ---
x[0] is equivalent to *x x[1] is equivalent to *(x+1) &x[0] is equivalent to x
"this is a string"
"hello"
"He said, *"Let's go.*""
a "hello"; b "world'*; v[2] "now is the time", "for all good men", "to come to the aid of the party";
strcopy(sl ,s2){ auto i; i = 0; while (lchar(sl,i,char(s2,i)) != '*e') i++; }
char(s, n){ auto y,sh,cpos; y = s[n/4]; /* word containing n-th char */ cpos = n%4; /* position of char in word */ sh = 27-9*cpos; /* bit positions to shift */ y = (y>>sh)&0777; /* shift and mask all but 9 bits */ return(y); /* return character to caller */ }
char(s,n) return((s[n/4]>>(27-9*(n%4)))&0777);
getstr(s){ auto c,i; while ((c=getchar()) != '*n') lchar(s,i++,c); lchar(s,i,'*e'); return(s) ; }
auto s[20] ; putstr(getstr(s)); putchar('*n');
loop: switch (c=getchar()){ pr: case 'p': /* print */ case 'P': print(); goto loop; case 's': /* subs */ case 'S': subs() ; goto pr; case 'd': /* delete */ case 'D': delete(); goto loop; case '*n': /* quit on newline */ break; default: error(); /* error if fall out */ goto loop; }
switch (expression) statement
case constant:
openr(5, "cat/file")
openw(u,s)
putstr("old or new?"); flush(); getstr(s);
old or new?
reread(); getstr(s);
system("./rj (w) ident;file");
./rj (w) ident;file
extrn wr.unit; --- wr.unit = -1; opts = "(w)"; fname = "file"; printf("./rj %s ident;%s*n", opts,fname');
putnumb(n) { auto a; if(a=n/10) /* assignment, not equality test */ putnumb(a); /* recursive */ putchar(n%10 + '0'); }
flip(x,y){ auto t; t = x; x = y; y = t; }
flip(&a,&b);
flip(x,y){ auto t; t = *y; *x = *y; *y = t; }
callf(name, a1,a2, . . .,a10)
tod = callf(itimez,&0)
t=0; tod = callf(itimez,&t) ;
s = callf(sin,&x)
callf(sin2,&x,&s)
subroutine sin2(x,y) y = sin(x) return end
$) - { } imbalance () - ( ) imbalance */ - /**/ imbalance [] - [] imbalance >c - case table overflow (fatal) >e - expression stack overflow (fatal) >i - label table overflow (fatal) >s - symbol table overflow (fatal) ex - expression syntax error lv - address expected rd name name redeclaration - multiple definition sx keyword statement syntax error un name undefined name - line number is last line of function where definition is missing xx - syntax error in external definition
*0 null (ascii NUL = 000) *e end of string (ascii EOT = 004) *( { *) } *t tab ** * *' ' *" " *n newline
c -- character data (ascii) d -- decimal number o -- octal number s -- 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);
++ -- * & - ! ~ (unary) [RL] * / % (binary) [LR] + - [LR] >> << [LR] > < <= >= == != & [LR] ^ [LR] | [LR] ?: [RL] = =+ =- etc. (all assignment operators) [RL]