The Quake III Arena sources as originally released under the GPL license on August 20, 2005.
This commit is contained in:
commit
dbe4ddb103
1409 changed files with 806066 additions and 0 deletions
0
lcc/tst/8q.0
Normal file
0
lcc/tst/8q.0
Normal file
39
lcc/tst/8q.c
Normal file
39
lcc/tst/8q.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
int up[15], down[15], rows[8], x[8];
|
||||
int queens(), print();
|
||||
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 15; i++)
|
||||
up[i] = down[i] = 1;
|
||||
for (i = 0; i < 8; i++)
|
||||
rows[i] = 1;
|
||||
queens(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
queens(c)
|
||||
{
|
||||
int r;
|
||||
|
||||
for (r = 0; r < 8; r++)
|
||||
if (rows[r] && up[r-c+7] && down[r+c]) {
|
||||
rows[r] = up[r-c+7] = down[r+c] = 0;
|
||||
x[c] = r;
|
||||
if (c == 7)
|
||||
print();
|
||||
else
|
||||
queens(c + 1);
|
||||
rows[r] = up[r-c+7] = down[r+c] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
print()
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; k < 8; k++)
|
||||
printf("%c ", x[k]+'1');
|
||||
printf("\n");
|
||||
}
|
0
lcc/tst/array.0
Normal file
0
lcc/tst/array.0
Normal file
48
lcc/tst/array.c
Normal file
48
lcc/tst/array.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
int x[3][4], *y[3];
|
||||
|
||||
main() {
|
||||
int z[3][4];
|
||||
int i, j, *p;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 4; j++)
|
||||
x[i][j] = 1000*i + j;
|
||||
y[i] = x[i];
|
||||
}
|
||||
f();
|
||||
for (i = 0; i < 3; i++) {
|
||||
y[i] = p = &z[i][0];
|
||||
for (j = 0; j < 4; j++)
|
||||
p[j] = x[i][j];
|
||||
}
|
||||
g(z, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f() {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", x[i][j]);
|
||||
printf("\n");
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
g(x, y)
|
||||
int x[][4], *y[];
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", x[i][j]);
|
||||
printf("\n");
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
32
lcc/tst/cf.0
Normal file
32
lcc/tst/cf.0
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* cf - print character frequencies */
|
||||
float f[128];
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i, c, nc;
|
||||
float cutoff, atof();
|
||||
|
||||
if (argc <= 1)
|
||||
cutoff = 0.0;
|
||||
else
|
||||
cutoff = atof(argv[1])/100;
|
||||
for (i = 0; i <= 127; )
|
||||
f[i++] = 0.0;
|
||||
nc = 0;
|
||||
while ((c = getchar()) != -1) {
|
||||
f[c] += 1;
|
||||
nc++;
|
||||
}
|
||||
printf("char\tfreq\n");
|
||||
for (i = 0; i <= 127; ++i)
|
||||
if (f[i] && f[i]/nc >= cutoff) {
|
||||
if (i <= ' ')
|
||||
printf("%03o", i);
|
||||
else
|
||||
printf("%c", i);
|
||||
printf("\t%.1f\n", 100*f[i]/nc);
|
||||
}
|
||||
return 0;
|
||||
}
|
32
lcc/tst/cf.c
Normal file
32
lcc/tst/cf.c
Normal file
|
@ -0,0 +1,32 @@
|
|||
/* cf - print character frequencies */
|
||||
float f[128];
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i, c, nc;
|
||||
float cutoff, atof();
|
||||
|
||||
if (argc <= 1)
|
||||
cutoff = 0.0;
|
||||
else
|
||||
cutoff = atof(argv[1])/100;
|
||||
for (i = 0; i <= 127; )
|
||||
f[i++] = 0.0;
|
||||
nc = 0;
|
||||
while ((c = getchar()) != -1) {
|
||||
f[c] += 1;
|
||||
nc++;
|
||||
}
|
||||
printf("char\tfreq\n");
|
||||
for (i = 0; i <= 127; ++i)
|
||||
if (f[i] && f[i]/nc >= cutoff) {
|
||||
if (i <= ' ')
|
||||
printf("%03o", i);
|
||||
else
|
||||
printf("%c", i);
|
||||
printf("\t%.1f\n", 100*f[i]/nc);
|
||||
}
|
||||
return 0;
|
||||
}
|
0
lcc/tst/cq.0
Normal file
0
lcc/tst/cq.0
Normal file
5316
lcc/tst/cq.c
Normal file
5316
lcc/tst/cq.c
Normal file
File diff suppressed because it is too large
Load diff
0
lcc/tst/cvt.0
Normal file
0
lcc/tst/cvt.0
Normal file
35
lcc/tst/cvt.c
Normal file
35
lcc/tst/cvt.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
signed char c;
|
||||
signed short s;
|
||||
signed int i;
|
||||
signed long int l;
|
||||
unsigned char C;
|
||||
unsigned short S;
|
||||
unsigned int I;
|
||||
unsigned long int L;
|
||||
float f;
|
||||
double d;
|
||||
long double D;
|
||||
void *p;
|
||||
void (*P)(void);
|
||||
|
||||
void print(void) {
|
||||
printf("%d %d %d %ld %u %u %u %lu %f %f %lf\n",c,s,i,l,C,S,I,L,f,d,D);
|
||||
}
|
||||
|
||||
main() {
|
||||
c= 1; s=c;i=c;l=c;C=c;S=c;I=c;L=c;f=c;d=c;D=c; print();
|
||||
s= 2; c=s; i=s;l=s;C=s;S=s;I=s;L=s;f=s;d=s;D=s; print();
|
||||
i= 3; c=i;s=i; l=i;C=i;S=i;I=i;L=i;f=i;d=i;D=i; print();
|
||||
l= 4; c=l;s=l;i=l; C=l;S=l;I=l;L=l;f=l;d=l;D=l; print();
|
||||
C= 5; c=C;s=C;i=C;l=C; S=C;I=C;L=C;f=C;d=C;D=C; print();
|
||||
S= 6; c=S;s=S;i=S;l=S;C=S; I=S;L=S;f=S;d=S;D=S; print();
|
||||
I= 7; c=I;s=I;i=I;l=I;C=I;S=I; L=I;f=I;d=I;D=I; print();
|
||||
L= 8; c=L;s=L;i=L;l=L;C=L;S=L;I=S; f=L;d=L;D=L; print();
|
||||
f= 9; c=f;s=f;i=f;l=f;C=f;S=f;I=f;L=f; d=f;D=f; print();
|
||||
d=10; c=d;s=d;i=d;l=d;C=d;S=d;I=d;L=d;f=d; D=d; print();
|
||||
D=11; c=D;s=D;i=D;l=D;C=D;S=D;I=D;L=D;f=D;d=D; print();
|
||||
|
||||
p=0; p=0L; p=0U; p=0UL; p=P;
|
||||
P=0; P=0L; P=0U; P=0UL; P=p;
|
||||
return 0;
|
||||
}
|
0
lcc/tst/fields.0
Normal file
0
lcc/tst/fields.0
Normal file
34
lcc/tst/fields.c
Normal file
34
lcc/tst/fields.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
struct foo {
|
||||
int a;
|
||||
char b;
|
||||
int x : 12, y : 4, : 0, : 4, z : 3;
|
||||
char c;
|
||||
} x = { 1, 2, 3, 4, 5, 6 };
|
||||
int i = 16;
|
||||
struct baz { unsigned int a:2, b:4, c:32;} y = { 7, 8, 9};
|
||||
|
||||
main()
|
||||
{
|
||||
printf("x = %d %d %d %d %d %d\n", x.a, x.b, x.x, x.y, x.z, x.c);
|
||||
printf("y = %d %d %d\n", y.a, y.b, y.c);
|
||||
x.y = i;
|
||||
x.z = 070;
|
||||
printf("x = %d %d %d %d %d %d\n", x.a, x.b, x.x, x.y, x.z, x.c);
|
||||
y.a = 2;
|
||||
y.c = i;
|
||||
printf("y = %d %d %d\n", y.a, y.b, y.c);
|
||||
f2(&x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f1(struct baz *p) {
|
||||
p->a = p->b = 0;
|
||||
if (p->b)
|
||||
printf("p->b != 0!\n");
|
||||
p->a = 0x3; p->b = 0xf;
|
||||
printf("p->a = 0x%x, p->b = 0x%x\n", p->a, p->b);
|
||||
}
|
||||
f2(struct baz *p) {
|
||||
p->a = (i==0);
|
||||
p->b = (f1(p),0);
|
||||
}
|
0
lcc/tst/front.0
Normal file
0
lcc/tst/front.0
Normal file
120
lcc/tst/front.c
Normal file
120
lcc/tst/front.c
Normal file
|
@ -0,0 +1,120 @@
|
|||
main() {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
nested(a,b) {
|
||||
if ((a<4 && b == 'r')
|
||||
|| (a == 1 && (b == 'h' || b == 'i'))
|
||||
|| (a == 2 && (b == 'o' || b == 'y'))
|
||||
) a=b;
|
||||
}
|
||||
|
||||
/* type name scope */
|
||||
|
||||
void s(struct D *d) {} /* this struct D differs from the one below */
|
||||
typedef struct D D;
|
||||
struct D {int x, y;} Dy={0};
|
||||
D Dz={1};
|
||||
Dfunc(){
|
||||
D a; a.y=1;
|
||||
s(&Dy); /* error */
|
||||
}
|
||||
|
||||
/* qualifiers */
|
||||
|
||||
const a; int b;
|
||||
const int a, *x; int b, *y;
|
||||
volatile unsigned z;
|
||||
|
||||
f() {
|
||||
x = y;
|
||||
z = z + z; /* should be 2 references to z's r-value */
|
||||
}
|
||||
f1() {
|
||||
x = &a;
|
||||
x = &b;
|
||||
y = &a; /* error */
|
||||
y = &b;
|
||||
}
|
||||
f2(int **a, int **b) {
|
||||
f(&x, &y);
|
||||
**a = 0;
|
||||
return **b;
|
||||
}
|
||||
g(const int *p) {
|
||||
g(&a);
|
||||
g(&b);
|
||||
return *p;
|
||||
}
|
||||
h(int *p) {
|
||||
f(&a);
|
||||
f(&b);
|
||||
return *p;
|
||||
}
|
||||
h1(const int x, int y) {
|
||||
h1(a,b);
|
||||
h1(b,a);
|
||||
return x + y;
|
||||
}
|
||||
h2() {
|
||||
char *b; const void *p;
|
||||
p = b;
|
||||
b = p; /* error */
|
||||
}
|
||||
|
||||
|
||||
/* static naming */
|
||||
|
||||
extern int yy; set1() { { static yy=1; yy=2;} yy=4;}
|
||||
static int yy; set2() { yy=5; {static yy=2; yy=3; }}
|
||||
static void goo() {}
|
||||
sss() { int goo; { static int goo();} goo=1;}
|
||||
rrr(p) float *p; { extern int xr;
|
||||
{ static float xr;
|
||||
{ extern int *xr; } p=&xr; }}
|
||||
|
||||
/* local extern */
|
||||
|
||||
static int ss1;
|
||||
int ss3;
|
||||
extern int ss5;
|
||||
setstatic() { extern int ss1,ss2,ss3,ss4; ss1 = ss2; ss3 = ss4; ss5 = 0;}
|
||||
static int ss2;
|
||||
int ss4;
|
||||
static int ss5;
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int fx1(void);
|
||||
int fx1();
|
||||
|
||||
int gx1(double x);
|
||||
int gx1(x) double x; { gx1(&x); } /* error */
|
||||
|
||||
int hx1();
|
||||
int hx1(double x,...); /* error */
|
||||
|
||||
int ff1(double x, int *y);
|
||||
int ff1(x,y) float x; int y[]; {x=y[0];}
|
||||
|
||||
int gg1(int a);
|
||||
int gg1(a,b){a=b;}
|
||||
|
||||
int hh1(const int x);
|
||||
hh1(a) {return a;}
|
||||
|
||||
extern int strcmp(const char*, const char*);
|
||||
extern void qsort(void*, int, int, int (*)(const void*, const void*));
|
||||
extern int cmp(char**a, char**b) { return strcmp(*a,*b); }
|
||||
sort() {
|
||||
int n; char *a[100];
|
||||
qsort(a, n, sizeof(char*), (int (*)(const void*, const void*))cmp);
|
||||
qsort(a, n, sizeof(char*), cmp); /* error */
|
||||
}
|
||||
|
||||
/* nasty calls */
|
||||
|
||||
onearg(){
|
||||
int a,b,c,d;
|
||||
f( ( (a? (b = 1): (c = 2)), (d ? 3 : 4) ) ); /* 1 argument */
|
||||
}
|
0
lcc/tst/incr.0
Normal file
0
lcc/tst/incr.0
Normal file
39
lcc/tst/incr.c
Normal file
39
lcc/tst/incr.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
main() {}
|
||||
|
||||
memchar() {
|
||||
char x, *p;
|
||||
|
||||
&x, &p;
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
memint() {
|
||||
int x, *p;
|
||||
|
||||
&x, &p;
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
regchar() {
|
||||
register char x, *p;
|
||||
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
regint() {
|
||||
register int x, *p;
|
||||
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
0
lcc/tst/init.0
Normal file
0
lcc/tst/init.0
Normal file
59
lcc/tst/init.c
Normal file
59
lcc/tst/init.c
Normal file
|
@ -0,0 +1,59 @@
|
|||
|
||||
typedef struct { int codes[3]; char name[6]; } Word;
|
||||
|
||||
Word words[] = {
|
||||
1, 2, 3, "if",
|
||||
{ { 4, 5 }, { 'f', 'o', 'r' } },
|
||||
6, 7, 8, {"else"},
|
||||
{ { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', },
|
||||
{ 0 },
|
||||
}, *wordlist = words;
|
||||
|
||||
int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } };
|
||||
int *y[] = { x[0], x[1], x[2], 0 };
|
||||
|
||||
|
||||
main()
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; y[i]; i++) {
|
||||
for (j = 0; y[i][j]; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
f();
|
||||
g(wordlist);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f() {
|
||||
static char *keywords[] = {"if", "for", "else", "while", 0, };
|
||||
char **p;
|
||||
|
||||
for (p = keywords; *p; p++)
|
||||
printf("%s\n", *p);
|
||||
}
|
||||
|
||||
g(p)
|
||||
Word *p;
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( ; p->codes[0]; p++) {
|
||||
for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++)
|
||||
printf("%d ", p->codes[i]);
|
||||
printf("%s\n", p->name);
|
||||
}
|
||||
h();
|
||||
}
|
||||
|
||||
h()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(words)/sizeof(Word); i++)
|
||||
printf("%d %d %d %s\n", words[i].codes[0],
|
||||
words[i].codes[1], words[i].codes[2],
|
||||
&words[i].name[0]);
|
||||
}
|
0
lcc/tst/limits.0
Normal file
0
lcc/tst/limits.0
Normal file
19
lcc/tst/limits.c
Normal file
19
lcc/tst/limits.c
Normal file
|
@ -0,0 +1,19 @@
|
|||
#include <limits.h>
|
||||
|
||||
main() {
|
||||
printf("UCHAR_MAX: %08x=%d\n", UCHAR_MAX, UCHAR_MAX);
|
||||
printf("USHRT_MAX: %08x=%d\n", USHRT_MAX, USHRT_MAX);
|
||||
printf("UINT_MAX: %08x=%d\n", UINT_MAX, UINT_MAX);
|
||||
printf("ULONG_MAX: %08lx=%ld\n", ULONG_MAX, ULONG_MAX);
|
||||
printf("CHAR_MAX: %08x=%d\n", CHAR_MAX, CHAR_MAX);
|
||||
printf("SCHAR_MAX: %08x=%d\n", SCHAR_MAX, SCHAR_MAX);
|
||||
printf("SHRT_MAX: %08x=%d\n", SHRT_MAX, SHRT_MAX);
|
||||
printf("INT_MAX: %08x=%d\n", INT_MAX, INT_MAX);
|
||||
printf("LONG_MAX: %08lx=%ld\n", LONG_MAX, LONG_MAX);
|
||||
printf("CHAR_MIN: %08x=%d\n", CHAR_MIN, CHAR_MIN);
|
||||
printf("SCHAR_MIN: %08x=%d\n", SCHAR_MIN, SCHAR_MIN);
|
||||
printf("SHRT_MIN: %08x=%d\n", SHRT_MIN, SHRT_MIN);
|
||||
printf("INT_MIN: %08x=%d\n", INT_MIN, INT_MIN);
|
||||
printf("LONG_MIN: %08lx=%ld\n", LONG_MIN, LONG_MIN);
|
||||
return 0;
|
||||
}
|
0
lcc/tst/paranoia.0
Normal file
0
lcc/tst/paranoia.0
Normal file
2203
lcc/tst/paranoia.c
Normal file
2203
lcc/tst/paranoia.c
Normal file
File diff suppressed because it is too large
Load diff
0
lcc/tst/sort.0
Normal file
0
lcc/tst/sort.0
Normal file
65
lcc/tst/sort.c
Normal file
65
lcc/tst/sort.c
Normal file
|
@ -0,0 +1,65 @@
|
|||
int in[] = {10, 32, -1, 567, 3, 18, 1, -51, 789, 0};
|
||||
|
||||
main() {
|
||||
int i;
|
||||
|
||||
sort(in, (sizeof in)/(sizeof in[0]));
|
||||
for (i = 0; i < (sizeof in)/(sizeof in[0]); i++) {
|
||||
putd(in[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* putd - output decimal number */
|
||||
putd(n) {
|
||||
if (n < 0) {
|
||||
putchar('-');
|
||||
n = -n;
|
||||
}
|
||||
if (n/10)
|
||||
putd(n/10);
|
||||
putchar(n%10 + '0');
|
||||
}
|
||||
|
||||
int *xx;
|
||||
|
||||
/* sort - sort a[0..n-1] into increasing order */
|
||||
sort(a, n) int a[]; {
|
||||
quick(xx = a, 0, --n);
|
||||
}
|
||||
|
||||
/* quick - quicksort a[lb..ub] */
|
||||
quick(a, lb, ub) int a[]; {
|
||||
int k, partition();
|
||||
|
||||
if (lb >= ub)
|
||||
return;
|
||||
k = partition(a, lb, ub);
|
||||
quick(a, lb, k - 1);
|
||||
quick(a, k + 1, ub);
|
||||
}
|
||||
|
||||
/* partition - partition a[i..j] */
|
||||
int partition(a, i, j) int a[]; {
|
||||
int v, k;
|
||||
|
||||
j++;
|
||||
k = i;
|
||||
v = a[k];
|
||||
while (i < j) {
|
||||
i++; while (a[i] < v) i++;
|
||||
j--; while (a[j] > v) j--;
|
||||
if (i < j) exchange(&a[i], &a[j]);
|
||||
}
|
||||
exchange(&a[k], &a[j]);
|
||||
return j;
|
||||
}
|
||||
|
||||
/* exchange - exchange *x and *y */
|
||||
exchange(x, y) int *x, *y; {
|
||||
int t;
|
||||
|
||||
printf("exchange(%d,%d)\n", x - xx, y - xx);
|
||||
t = *x; *x = *y; *y = t;
|
||||
}
|
0
lcc/tst/spill.0
Normal file
0
lcc/tst/spill.0
Normal file
17
lcc/tst/spill.c
Normal file
17
lcc/tst/spill.c
Normal file
|
@ -0,0 +1,17 @@
|
|||
main(){}
|
||||
|
||||
f(i){i=f()+f();}
|
||||
|
||||
f2(i){i=f()+(i?f():1);}
|
||||
|
||||
f3(int i,int *p){register r1=0,r2=0,r3=0,r4=0,r5=0,r6=0,r7=0,r8=0,r9=0,r10=0;*p++=i?f():0;}
|
||||
|
||||
double a[10],b[10];int i;f4(){register r6=0,r7=0,r8=0,r9=0,r10=0,r11=0;i=a[i]+b[i] && i && a[i]-b[i];}
|
||||
/* f4 causes parent to spill child on vax when odd double regs are enabled */
|
||||
|
||||
int j, k, m, n;
|
||||
double *A, *B, x;
|
||||
f5(){
|
||||
x=A[k*m]*A[j*m]+B[k*n]*B[j*n];
|
||||
x=A[k*m]*B[j*n]-B[k*n]*A[j*m];
|
||||
}
|
0
lcc/tst/stdarg.0
Normal file
0
lcc/tst/stdarg.0
Normal file
51
lcc/tst/stdarg.c
Normal file
51
lcc/tst/stdarg.c
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
struct node { int a[4]; } x = {1,2,3,4};
|
||||
|
||||
print(char *fmt, ...);
|
||||
|
||||
main() {
|
||||
print("test 1\n");
|
||||
print("test %s\n", "2");
|
||||
print("test %d%c", 3, '\n');
|
||||
print("%s%s %w%c", "te", "st", 4, '\n');
|
||||
print("%s%s %f%c", "te", "st", 5.0, '\n');
|
||||
print("%b %b %b %b %b %b\n", x, x, x, x, x, x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
print(char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
for (; *fmt; fmt++)
|
||||
if (*fmt == '%')
|
||||
switch (*++fmt) {
|
||||
case 'b': {
|
||||
struct node x = va_arg(ap, struct node);
|
||||
printf("{%d %d %d %d}", x.a[0], x.a[1], x.a[2], x.a[3]);
|
||||
break;
|
||||
}
|
||||
case 'c':
|
||||
printf("%c", va_arg(ap, char));
|
||||
break;
|
||||
case 'd':
|
||||
printf("%d", va_arg(ap, int));
|
||||
break;
|
||||
case 'w':
|
||||
printf("%x", va_arg(ap, short));
|
||||
break;
|
||||
case 's':
|
||||
printf("%s", va_arg(ap, char *));
|
||||
break;
|
||||
case 'f':
|
||||
printf("%f", va_arg(ap, double));
|
||||
break;
|
||||
default:
|
||||
printf("%c", *fmt);
|
||||
break;
|
||||
}
|
||||
else
|
||||
printf("%c", *fmt);
|
||||
va_end(ap);
|
||||
}
|
0
lcc/tst/struct.0
Normal file
0
lcc/tst/struct.0
Normal file
69
lcc/tst/struct.c
Normal file
69
lcc/tst/struct.c
Normal file
|
@ -0,0 +1,69 @@
|
|||
typedef struct point { int x,y; } point;
|
||||
typedef struct rect { point pt1, pt2; } rect;
|
||||
|
||||
point addpoint(point p1, point p2) { /* add two points */
|
||||
p1.x += p2.x;
|
||||
p1.y += p2.y;
|
||||
return p1;
|
||||
}
|
||||
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
rect canonrect(rect r) { /* canonicalize rectangle coordinates */
|
||||
rect temp;
|
||||
|
||||
temp.pt1.x = min(r.pt1.x, r.pt2.x);
|
||||
temp.pt1.y = min(r.pt1.y, r.pt2.y);
|
||||
temp.pt2.x = max(r.pt1.x, r.pt2.x);
|
||||
temp.pt2.y = max(r.pt1.y, r.pt2.y);
|
||||
return temp;
|
||||
}
|
||||
|
||||
point makepoint(int x, int y) { /* make a point from x and y components */
|
||||
point p;
|
||||
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
return p;
|
||||
}
|
||||
|
||||
rect makerect(point p1, point p2) { /* make a rectangle from two points */
|
||||
rect r;
|
||||
|
||||
r.pt1 = p1;
|
||||
r.pt2 = p2;
|
||||
return canonrect(r);
|
||||
}
|
||||
|
||||
int ptinrect(point p, rect r) { /* is p in r? */
|
||||
return p.x >= r.pt1.x && p.x < r.pt2.x
|
||||
&& p.y >= r.pt1.y && p.y < r.pt2.y;
|
||||
}
|
||||
|
||||
struct odd {char a[3]; } y = {'a', 'b', 0};
|
||||
|
||||
odd(struct odd y) {
|
||||
struct odd x = y;
|
||||
printf("%s\n", x.a);
|
||||
}
|
||||
|
||||
main() {
|
||||
int i;
|
||||
point x, origin = { 0, 0 }, maxpt = { 320, 320 };
|
||||
point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
|
||||
rect screen = makerect(addpoint(maxpt, makepoint(-10, -10)),
|
||||
addpoint(origin, makepoint(10, 10)));
|
||||
|
||||
for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
|
||||
printf("(%d,%d) is ", pts[i].x,
|
||||
(x = makepoint(pts[i].x, pts[i].y)).y);
|
||||
if (ptinrect(x, screen) == 0)
|
||||
printf("not ");
|
||||
printf("within [%d,%d; %d,%d]\n", screen.pt1.x, screen.pt1.y,
|
||||
screen.pt2.x, screen.pt2.y);
|
||||
}
|
||||
odd(y);
|
||||
exit(0);
|
||||
}
|
||||
|
0
lcc/tst/switch.0
Normal file
0
lcc/tst/switch.0
Normal file
137
lcc/tst/switch.c
Normal file
137
lcc/tst/switch.c
Normal file
|
@ -0,0 +1,137 @@
|
|||
main()
|
||||
{
|
||||
int i; char *s;
|
||||
|
||||
for (s = "bfnrtvx"; *s; s++)
|
||||
printf("%c = 0x%x\n", *s, backslash(*s));
|
||||
f();
|
||||
g();
|
||||
h();
|
||||
for (i = 0x1000000; i&0x7000000; i += 0x1000000)
|
||||
big(i);
|
||||
limit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
backslash(c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'b':
|
||||
return '\b';
|
||||
case 'f':
|
||||
return '\f';
|
||||
case 'n':
|
||||
return '\n';
|
||||
case 'r':
|
||||
return '\r';
|
||||
case 't':
|
||||
return '\t';
|
||||
case 'v':
|
||||
return '\v';
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
f() {
|
||||
int i, x = 0, y;
|
||||
|
||||
printf("f:\n");
|
||||
for (i = 0; i <= 20; i++) {
|
||||
y = i;
|
||||
switch (i) {
|
||||
case 1: x = i; break;
|
||||
case 2: x = i; break;
|
||||
case 7: x = i; break;
|
||||
case 8: x = i; break;
|
||||
case 9: x = i; break;
|
||||
case 16: x = i; break;
|
||||
case 17: x = i; break;
|
||||
case 18: x = i; break;
|
||||
case 19: x = i; break;
|
||||
case 20: x = i; break;
|
||||
}
|
||||
printf("x = %d\n", x);
|
||||
}
|
||||
}
|
||||
|
||||
g() {
|
||||
int i;
|
||||
|
||||
printf("g:\n");
|
||||
for (i = 1; i <= 10; i++)
|
||||
switch (i) {
|
||||
case 1: case 2: printf("1 %d\n", i); break;
|
||||
case 3: case 4: case 5: printf("2 %d\n", i); break;
|
||||
case 6: case 7: case 8: printf("3 %d\n", i);
|
||||
default:
|
||||
printf("d %d\n", i); break;
|
||||
case 1001: case 1002: case 1003: case 1004:
|
||||
printf("5 %d\n", i); break;
|
||||
case 3001: case 3002: case 3003: case 3004:
|
||||
printf("6 %d\n", i); break;
|
||||
}
|
||||
}
|
||||
|
||||
h()
|
||||
{
|
||||
int i, n=0;
|
||||
|
||||
printf("h:\n");
|
||||
for (i = 1; i <= 500; i++)
|
||||
switch (i) {
|
||||
default: n++; continue;
|
||||
case 128: printf("i = %d\n", i); break;
|
||||
case 16: printf("i = %d\n", i); break;
|
||||
case 8: printf("i = %d\n", i); break;
|
||||
case 120: printf("i = %d\n", i); break;
|
||||
case 280: printf("i = %d\n", i); break;
|
||||
case 264: printf("i = %d\n", i); break;
|
||||
case 248: printf("i = %d\n", i); break;
|
||||
case 272: printf("i = %d\n", i); break;
|
||||
case 304: printf("i = %d\n", i); break;
|
||||
case 296: printf("i = %d\n", i); break;
|
||||
case 288: printf("i = %d\n", i); break;
|
||||
case 312: printf("i = %d\n", i); break;
|
||||
}
|
||||
printf("%d defaults\n", n);
|
||||
}
|
||||
|
||||
big(x) unsigned x; {
|
||||
switch(x&0x6000000){
|
||||
case -1:
|
||||
case -2:
|
||||
case 0x0000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
case 0x2000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
case 0x4000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
default:
|
||||
printf("x = 0x%x (default)\n", x); break;
|
||||
}
|
||||
}
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
limit() {
|
||||
int i;
|
||||
|
||||
for (i = INT_MIN; i <= INT_MIN+5; i++)
|
||||
switch (i) {
|
||||
case INT_MIN: printf("0\n"); break;
|
||||
case INT_MIN+1: printf("1\n"); break;
|
||||
case INT_MIN+2: printf("2\n"); break;
|
||||
case INT_MIN+3: printf("3\n"); break;
|
||||
case INT_MIN+4: printf("4\n"); break;
|
||||
default: printf("5\n"); break;
|
||||
}
|
||||
for (i = INT_MAX; i >= INT_MAX-5; i--)
|
||||
switch (i) {
|
||||
case INT_MAX: printf("0\n"); break;
|
||||
case INT_MAX-1: printf("1\n"); break;
|
||||
case INT_MAX-2: printf("2\n"); break;
|
||||
case INT_MAX-3: printf("3\n"); break;
|
||||
case INT_MAX-4: printf("4\n"); break;
|
||||
default: printf("5\n"); break;
|
||||
}
|
||||
}
|
115
lcc/tst/wf1.0
Normal file
115
lcc/tst/wf1.0
Normal file
|
@ -0,0 +1,115 @@
|
|||
/* wf1 - print word frequencies; uses structures */
|
||||
|
||||
struct node {
|
||||
int count; /* frequency count */
|
||||
struct node *left; /* left subtree */
|
||||
struct node *right; /* right subtree */
|
||||
char *word; /* word itself */
|
||||
} words[2000];
|
||||
int next; /* index of next free entry in words */
|
||||
|
||||
struct node *lookup();
|
||||
|
||||
main()
|
||||
{
|
||||
struct node *root;
|
||||
char word[20];
|
||||
|
||||
root = 0;
|
||||
next = 0;
|
||||
while (getword(word))
|
||||
lookup(word, &root)->count++;
|
||||
tprint(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* err - print error message s and die */
|
||||
err(s)
|
||||
char *s;
|
||||
{
|
||||
printf("? %s\n", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* getword - get next input word into buf, return 0 on EOF */
|
||||
int getword(buf)
|
||||
char *buf;
|
||||
{
|
||||
char *s;
|
||||
int c;
|
||||
|
||||
while ((c = getchar()) != -1 && isletter(c) == 0)
|
||||
;
|
||||
for (s = buf; c = isletter(c); c = getchar())
|
||||
*s++ = c;
|
||||
*s = 0;
|
||||
if (s > buf)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* isletter - return folded version of c if it is a letter, 0 otherwise */
|
||||
int isletter(c)
|
||||
int c;
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* lookup - lookup word in tree; install if necessary */
|
||||
struct node *lookup(word, p)
|
||||
char *word;
|
||||
struct node **p;
|
||||
{
|
||||
int cond;
|
||||
char *malloc();
|
||||
|
||||
if (*p) {
|
||||
cond = strcmp(word, (*p)->word);
|
||||
if (cond < 0)
|
||||
return lookup(word, &(*p)->left);
|
||||
else if (cond > 0)
|
||||
return lookup(word, &(*p)->right);
|
||||
else
|
||||
return *p;
|
||||
}
|
||||
if (next >= 2000)
|
||||
err("out of node storage");
|
||||
words[next].count = 0;
|
||||
words[next].left = words[next].right = 0;
|
||||
words[next].word = malloc(strlen(word) + 1);
|
||||
if (words[next].word == 0)
|
||||
err("out of word storage");
|
||||
strcpy(words[next].word, word);
|
||||
return *p = &words[next++];
|
||||
}
|
||||
|
||||
/* tprint - print tree */
|
||||
tprint(tree)
|
||||
struct node *tree;
|
||||
{
|
||||
if (tree) {
|
||||
tprint(tree->left);
|
||||
printf("%d\t%s\n", tree->count, tree->word);
|
||||
tprint(tree->right);
|
||||
}
|
||||
}
|
||||
|
||||
/* strcmp - compare s1 and s2, return <0, 0, or >0 */
|
||||
int strcmp(s1, s2)
|
||||
char *s1, *s2;
|
||||
{
|
||||
while (*s1 == *s2) {
|
||||
if (*s1++ == 0)
|
||||
return 0;
|
||||
++s2;
|
||||
}
|
||||
if (*s1 == 0)
|
||||
return -1;
|
||||
else if (*s2 == 0)
|
||||
return 1;
|
||||
return *s1 - *s2;
|
||||
}
|
101
lcc/tst/wf1.c
Normal file
101
lcc/tst/wf1.c
Normal file
|
@ -0,0 +1,101 @@
|
|||
/* wf1 - print word frequencies; uses structures */
|
||||
|
||||
struct node {
|
||||
int count; /* frequency count */
|
||||
struct node *left; /* left subtree */
|
||||
struct node *right; /* right subtree */
|
||||
char *word; /* word itself */
|
||||
} words[2000];
|
||||
int next; /* index of next free entry in words */
|
||||
|
||||
struct node *lookup();
|
||||
|
||||
main() {
|
||||
struct node *root;
|
||||
char word[20];
|
||||
|
||||
root = 0;
|
||||
next = 0;
|
||||
while (getword(word))
|
||||
lookup(word, &root)->count++;
|
||||
tprint(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* err - print error message s and die */
|
||||
err(s) char *s; {
|
||||
printf("? %s\n", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* getword - get next input word into buf, return 0 on EOF */
|
||||
int getword(buf) char *buf; {
|
||||
char *s;
|
||||
int c;
|
||||
|
||||
while ((c = getchar()) != -1 && isletter(c) == 0)
|
||||
;
|
||||
for (s = buf; c = isletter(c); c = getchar())
|
||||
*s++ = c;
|
||||
*s = 0;
|
||||
if (s > buf)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* isletter - return folded version of c if it is a letter, 0 otherwise */
|
||||
int isletter(c) {
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* lookup - lookup word in tree; install if necessary */
|
||||
struct node *lookup(word, p) char *word; struct node **p; {
|
||||
int cond;
|
||||
char *malloc();
|
||||
|
||||
if (*p) {
|
||||
cond = strcmp(word, (*p)->word);
|
||||
if (cond < 0)
|
||||
return lookup(word, &(*p)->left);
|
||||
else if (cond > 0)
|
||||
return lookup(word, &(*p)->right);
|
||||
else
|
||||
return *p;
|
||||
}
|
||||
if (next >= 2000)
|
||||
err("out of node storage");
|
||||
words[next].count = 0;
|
||||
words[next].left = words[next].right = 0;
|
||||
words[next].word = malloc(strlen(word) + 1);
|
||||
if (words[next].word == 0)
|
||||
err("out of word storage");
|
||||
strcpy(words[next].word, word);
|
||||
return *p = &words[next++];
|
||||
}
|
||||
|
||||
/* tprint - print tree */
|
||||
tprint(tree) struct node *tree; {
|
||||
if (tree) {
|
||||
tprint(tree->left);
|
||||
printf("%d\t%s\n", tree->count, tree->word);
|
||||
tprint(tree->right);
|
||||
}
|
||||
}
|
||||
|
||||
/* strcmp - compare s1 and s2, return <0, 0, or >0 */
|
||||
int strcmp(s1, s2) char *s1, *s2; {
|
||||
while (*s1 == *s2) {
|
||||
if (*s1++ == 0)
|
||||
return 0;
|
||||
++s2;
|
||||
}
|
||||
if (*s1 == 0)
|
||||
return -1;
|
||||
else if (*s2 == 0)
|
||||
return 1;
|
||||
return *s1 - *s2;
|
||||
}
|
1
lcc/tst/yacc.0
Normal file
1
lcc/tst/yacc.0
Normal file
|
@ -0,0 +1 @@
|
|||
a=-b+5*c
|
591
lcc/tst/yacc.c
Normal file
591
lcc/tst/yacc.c
Normal file
|
@ -0,0 +1,591 @@
|
|||
# define ID 257
|
||||
# define CON 258
|
||||
# define UNARYMINUS 259
|
||||
#define yyclearin yychar = -1
|
||||
#define yyerrok yyerrflag = 0
|
||||
extern int yychar;
|
||||
extern short yyerrflag;
|
||||
#ifndef YYMAXDEPTH
|
||||
#define YYMAXDEPTH 150
|
||||
#endif
|
||||
#ifndef YYSTYPE
|
||||
#define YYSTYPE int
|
||||
#endif
|
||||
YYSTYPE yylval, yyval;
|
||||
# define YYERRCODE 256
|
||||
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
# define U(x) x
|
||||
# define NLSTATE yyprevious=YYNEWLINE
|
||||
# define BEGIN yybgin = yysvec + 1 +
|
||||
# define INITIAL 0
|
||||
# define YYLERR yysvec
|
||||
# define YYSTATE (yyestate-yysvec-1)
|
||||
# define YYOPTIM 1
|
||||
# define YYLMAX 200
|
||||
# define output(c) (void)putc(c,yyout)
|
||||
# define input() (((yytchar=yysptr>yysbuf?U(*--yysptr):getc(yyin))==10?(yylineno++,yytchar):yytchar)==EOF?0:yytchar)
|
||||
# define unput(c) {yytchar= (c);if(yytchar=='\n')yylineno--;*yysptr++=yytchar;}
|
||||
# define yymore() (yymorfg=1)
|
||||
# define ECHO fprintf(yyout, "%s",yytext)
|
||||
# define REJECT { nstr = yyreject(); goto yyfussy;}
|
||||
int yyleng; extern char yytext[];
|
||||
int yymorfg;
|
||||
extern char *yysptr, yysbuf[];
|
||||
int yytchar;
|
||||
FILE *yyin ={stdin}, *yyout ={stdout};
|
||||
extern int yylineno;
|
||||
struct yysvf {
|
||||
struct yywork *yystoff;
|
||||
struct yysvf *yyother;
|
||||
int *yystops;};
|
||||
struct yysvf *yyestate;
|
||||
extern struct yysvf yysvec[], *yybgin;
|
||||
# define YYNEWLINE 10
|
||||
yylex(){
|
||||
int nstr; extern int yyprevious;
|
||||
while((nstr = yylook()) >= 0)
|
||||
yyfussy: switch(nstr){
|
||||
case 0:
|
||||
if(yywrap()) return(0); break;
|
||||
case 1:
|
||||
return ID;
|
||||
break;
|
||||
case 2:
|
||||
return CON;
|
||||
break;
|
||||
case 3:
|
||||
;
|
||||
break;
|
||||
case 4:
|
||||
return yytext[0];
|
||||
break;
|
||||
case -1:
|
||||
break;
|
||||
default:
|
||||
fprintf(yyout,"bad switch yylook %d",nstr);
|
||||
} return(0); }
|
||||
/* end of yylex */
|
||||
int yyvstop[] ={
|
||||
0,
|
||||
|
||||
4,
|
||||
0,
|
||||
|
||||
3,
|
||||
4,
|
||||
0,
|
||||
|
||||
2,
|
||||
4,
|
||||
0,
|
||||
|
||||
1,
|
||||
4,
|
||||
0,
|
||||
|
||||
2,
|
||||
0,
|
||||
|
||||
1,
|
||||
0,
|
||||
0};
|
||||
# define YYTYPE char
|
||||
struct yywork { YYTYPE verify, advance; } yycrank[] ={
|
||||
0,0, 0,0, 1,3, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 1,4, 1,3,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 1,5, 5,7, 5,7,
|
||||
5,7, 5,7, 5,7, 5,7,
|
||||
5,7, 5,7, 5,7, 5,7,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 1,6, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 0,0, 0,0, 0,0,
|
||||
0,0, 0,0, 0,0, 0,0,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 0,0, 0,0,
|
||||
0,0, 0,0, 6,8, 0,0,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 6,8, 6,8,
|
||||
6,8, 6,8, 0,0, 0,0,
|
||||
0,0};
|
||||
struct yysvf yysvec[] ={
|
||||
0, 0, 0,
|
||||
yycrank+-1, 0, 0,
|
||||
yycrank+0, yysvec+1, 0,
|
||||
yycrank+0, 0, yyvstop+1,
|
||||
yycrank+0, 0, yyvstop+3,
|
||||
yycrank+2, 0, yyvstop+6,
|
||||
yycrank+19, 0, yyvstop+9,
|
||||
yycrank+0, yysvec+5, yyvstop+12,
|
||||
yycrank+0, yysvec+6, yyvstop+14,
|
||||
0, 0, 0};
|
||||
struct yywork *yytop = yycrank+141;
|
||||
struct yysvf *yybgin = yysvec+1;
|
||||
char yymatch[] ={
|
||||
00 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
|
||||
01 ,011 ,012 ,01 ,01 ,01 ,01 ,01 ,
|
||||
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
|
||||
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
|
||||
011 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
|
||||
01 ,01 ,01 ,01 ,01 ,01 ,01 ,01 ,
|
||||
'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,'0' ,
|
||||
'0' ,'0' ,01 ,01 ,01 ,01 ,01 ,01 ,
|
||||
01 ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
|
||||
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
|
||||
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
|
||||
'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,'A' ,
|
||||
01 ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
|
||||
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
|
||||
'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,'A' ,
|
||||
'A' ,'A' ,'A' ,01 ,01 ,01 ,01 ,01 ,
|
||||
0};
|
||||
char yyextra[] ={
|
||||
0,0,0,0,0,0,0,0,
|
||||
0};
|
||||
/* ncform 4.1 83/08/11 */
|
||||
|
||||
int yylineno =1;
|
||||
# define YYU(x) x
|
||||
# define NLSTATE yyprevious=YYNEWLINE
|
||||
char yytext[YYLMAX];
|
||||
struct yysvf *yylstate [YYLMAX], **yylsp, **yyolsp;
|
||||
char yysbuf[YYLMAX];
|
||||
char *yysptr = yysbuf;
|
||||
int *yyfnd;
|
||||
extern struct yysvf *yyestate;
|
||||
int yyprevious = YYNEWLINE;
|
||||
yylook(){
|
||||
register struct yysvf *yystate, **lsp;
|
||||
register struct yywork *yyt;
|
||||
struct yysvf *yyz;
|
||||
int yych;
|
||||
struct yywork *yyr;
|
||||
# ifdef LEXDEBUG
|
||||
int debug;
|
||||
# endif
|
||||
char *yylastch;
|
||||
/* start off machines */
|
||||
# ifdef LEXDEBUG
|
||||
debug = 0;
|
||||
# endif
|
||||
if (!yymorfg)
|
||||
yylastch = yytext;
|
||||
else {
|
||||
yymorfg=0;
|
||||
yylastch = yytext+yyleng;
|
||||
}
|
||||
for(;;){
|
||||
lsp = yylstate;
|
||||
yyestate = yystate = yybgin;
|
||||
if (yyprevious==YYNEWLINE) yystate++;
|
||||
for (;;){
|
||||
# ifdef LEXDEBUG
|
||||
if(debug)fprintf(yyout,"state %d\n",yystate-yysvec-1);
|
||||
# endif
|
||||
yyt = yystate->yystoff;
|
||||
if(yyt == yycrank){ /* may not be any transitions */
|
||||
yyz = yystate->yyother;
|
||||
if(yyz == 0)break;
|
||||
if(yyz->yystoff == yycrank)break;
|
||||
}
|
||||
*yylastch++ = yych = input();
|
||||
tryagain:
|
||||
# ifdef LEXDEBUG
|
||||
if(debug){
|
||||
fprintf(yyout,"char ");
|
||||
allprint(yych);
|
||||
putchar('\n');
|
||||
}
|
||||
# endif
|
||||
yyr = yyt;
|
||||
if ( yyt > yycrank){
|
||||
yyt = yyr + yych;
|
||||
if (yyt <= yytop && yyt->verify+yysvec == yystate){
|
||||
if(yyt->advance+yysvec == YYLERR) /* error transitions */
|
||||
{unput(*--yylastch);break;}
|
||||
*lsp++ = yystate = yyt->advance+yysvec;
|
||||
goto contin;
|
||||
}
|
||||
}
|
||||
# ifdef YYOPTIM
|
||||
else if(yyt < yycrank) { /* r < yycrank */
|
||||
yyt = yyr = yycrank+(yycrank-yyt);
|
||||
# ifdef LEXDEBUG
|
||||
if(debug)fprintf(yyout,"compressed state\n");
|
||||
# endif
|
||||
yyt = yyt + yych;
|
||||
if(yyt <= yytop && yyt->verify+yysvec == yystate){
|
||||
if(yyt->advance+yysvec == YYLERR) /* error transitions */
|
||||
{unput(*--yylastch);break;}
|
||||
*lsp++ = yystate = yyt->advance+yysvec;
|
||||
goto contin;
|
||||
}
|
||||
yyt = yyr + YYU(yymatch[yych]);
|
||||
# ifdef LEXDEBUG
|
||||
if(debug){
|
||||
fprintf(yyout,"try fall back character ");
|
||||
allprint(YYU(yymatch[yych]));
|
||||
putchar('\n');
|
||||
}
|
||||
# endif
|
||||
if(yyt <= yytop && yyt->verify+yysvec == yystate){
|
||||
if(yyt->advance+yysvec == YYLERR) /* error transition */
|
||||
{unput(*--yylastch);break;}
|
||||
*lsp++ = yystate = yyt->advance+yysvec;
|
||||
goto contin;
|
||||
}
|
||||
}
|
||||
if ((yystate = yystate->yyother) && (yyt= yystate->yystoff) != yycrank){
|
||||
# ifdef LEXDEBUG
|
||||
if(debug)fprintf(yyout,"fall back to state %d\n",yystate-yysvec-1);
|
||||
# endif
|
||||
goto tryagain;
|
||||
}
|
||||
# endif
|
||||
else
|
||||
{unput(*--yylastch);break;}
|
||||
contin:
|
||||
# ifdef LEXDEBUG
|
||||
if(debug){
|
||||
fprintf(yyout,"state %d char ",yystate-yysvec-1);
|
||||
allprint(yych);
|
||||
putchar('\n');
|
||||
}
|
||||
# endif
|
||||
;
|
||||
}
|
||||
# ifdef LEXDEBUG
|
||||
if(debug){
|
||||
fprintf(yyout,"stopped at %d with ",*(lsp-1)-yysvec-1);
|
||||
allprint(yych);
|
||||
putchar('\n');
|
||||
}
|
||||
# endif
|
||||
while (lsp-- > yylstate){
|
||||
*yylastch-- = 0;
|
||||
if (*lsp != 0 && (yyfnd= (*lsp)->yystops) && *yyfnd > 0){
|
||||
yyolsp = lsp;
|
||||
if(yyextra[*yyfnd]){ /* must backup */
|
||||
while(yyback((*lsp)->yystops,-*yyfnd) != 1 && lsp > yylstate){
|
||||
lsp--;
|
||||
unput(*yylastch--);
|
||||
}
|
||||
}
|
||||
yyprevious = YYU(*yylastch);
|
||||
yylsp = lsp;
|
||||
yyleng = yylastch-yytext+1;
|
||||
yytext[yyleng] = 0;
|
||||
# ifdef LEXDEBUG
|
||||
if(debug){
|
||||
fprintf(yyout,"\nmatch ");
|
||||
sprint(yytext);
|
||||
fprintf(yyout," action %d\n",*yyfnd);
|
||||
}
|
||||
# endif
|
||||
return(*yyfnd++);
|
||||
}
|
||||
unput(*yylastch);
|
||||
}
|
||||
if (yytext[0] == 0 /* && feof(yyin) */)
|
||||
{
|
||||
yysptr=yysbuf;
|
||||
return(0);
|
||||
}
|
||||
yyprevious = yytext[0] = input();
|
||||
if (yyprevious>0)
|
||||
output(yyprevious);
|
||||
yylastch=yytext;
|
||||
# ifdef LEXDEBUG
|
||||
if(debug)putchar('\n');
|
||||
# endif
|
||||
}
|
||||
}
|
||||
yyback(p, m)
|
||||
int *p;
|
||||
{
|
||||
if (p==0) return(0);
|
||||
while (*p)
|
||||
{
|
||||
if (*p++ == m)
|
||||
return(1);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
/* the following are only used in the lex library */
|
||||
yyinput(){
|
||||
return(input());
|
||||
}
|
||||
yyoutput(c)
|
||||
int c; {
|
||||
output(c);
|
||||
}
|
||||
yyunput(c)
|
||||
int c; {
|
||||
unput(c);
|
||||
}
|
||||
|
||||
main() {
|
||||
yyparse();
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* yyerror - issue error message */
|
||||
yyerror(s) char *s; {
|
||||
printf("%s\n", s);
|
||||
}
|
||||
short yyexca[] ={
|
||||
-1, 1,
|
||||
0, -1,
|
||||
-2, 0,
|
||||
};
|
||||
# define YYNPROD 15
|
||||
# define YYLAST 249
|
||||
short yyact[]={
|
||||
|
||||
12, 2, 9, 8, 17, 11, 25, 17, 15, 18,
|
||||
16, 10, 18, 17, 15, 7, 16, 13, 18, 5,
|
||||
3, 1, 0, 19, 20, 0, 0, 21, 22, 23,
|
||||
24, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 6, 14, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 4, 6 };
|
||||
short yypact[]={
|
||||
|
||||
-1000, -9,-1000, 5, -7, -59,-1000,-1000,-1000, -40,
|
||||
-29, -40, -40,-1000,-1000, -40, -40, -40, -40, -38,
|
||||
-35, -38, -38,-1000,-1000,-1000 };
|
||||
short yypgo[]={
|
||||
|
||||
0, 21, 20, 17, 11 };
|
||||
short yyr1[]={
|
||||
|
||||
0, 1, 1, 1, 1, 2, 4, 4, 4, 4,
|
||||
4, 4, 4, 4, 3 };
|
||||
short yyr2[]={
|
||||
|
||||
0, 0, 2, 3, 3, 3, 3, 3, 3, 3,
|
||||
2, 3, 1, 1, 1 };
|
||||
short yychk[]={
|
||||
|
||||
-1000, -1, 10, -2, 256, -3, 257, 10, 10, 61,
|
||||
-4, 45, 40, -3, 258, 43, 45, 42, 47, -4,
|
||||
-4, -4, -4, -4, -4, 41 };
|
||||
short yydef[]={
|
||||
|
||||
1, -2, 2, 0, 0, 0, 14, 3, 4, 0,
|
||||
5, 0, 0, 12, 13, 0, 0, 0, 0, 10,
|
||||
0, 6, 7, 8, 9, 11 };
|
||||
#ifndef lint
|
||||
#endif
|
||||
|
||||
# define YYFLAG -1000
|
||||
# define YYERROR goto yyerrlab
|
||||
# define YYACCEPT return(0)
|
||||
# define YYABORT return(1)
|
||||
|
||||
/* parser for yacc output */
|
||||
|
||||
#ifdef YYDEBUG
|
||||
int yydebug = 0; /* 1 for debugging */
|
||||
#endif
|
||||
YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
|
||||
int yychar = -1; /* current input token number */
|
||||
int yynerrs = 0; /* number of errors */
|
||||
short yyerrflag = 0; /* error recovery flag */
|
||||
|
||||
yyparse() {
|
||||
|
||||
short yys[YYMAXDEPTH];
|
||||
short yyj, yym;
|
||||
register YYSTYPE *yypvt;
|
||||
register short yystate, *yyps, yyn;
|
||||
register YYSTYPE *yypv;
|
||||
register short *yyxi;
|
||||
|
||||
yystate = 0;
|
||||
yychar = -1;
|
||||
yynerrs = 0;
|
||||
yyerrflag = 0;
|
||||
yyps= &yys[-1];
|
||||
yypv= &yyv[-1];
|
||||
|
||||
yystack: /* put a state and value onto the stack */
|
||||
|
||||
#ifdef YYDEBUG
|
||||
if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar );
|
||||
#endif
|
||||
if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
|
||||
*yyps = yystate;
|
||||
++yypv;
|
||||
*yypv = yyval;
|
||||
|
||||
yynewstate:
|
||||
|
||||
yyn = yypact[yystate];
|
||||
|
||||
if( yyn<= YYFLAG ) goto yydefault; /* simple state */
|
||||
|
||||
if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
|
||||
if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
|
||||
|
||||
if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
|
||||
yychar = -1;
|
||||
yyval = yylval;
|
||||
yystate = yyn;
|
||||
if( yyerrflag > 0 ) --yyerrflag;
|
||||
goto yystack;
|
||||
}
|
||||
|
||||
yydefault:
|
||||
/* default state action */
|
||||
|
||||
if( (yyn=yydef[yystate]) == -2 ) {
|
||||
if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
|
||||
/* look through exception table */
|
||||
|
||||
for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
|
||||
|
||||
while( *(yyxi+=2) >= 0 ){
|
||||
if( *yyxi == yychar ) break;
|
||||
}
|
||||
if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */
|
||||
}
|
||||
|
||||
if( yyn == 0 ){ /* error */
|
||||
/* error ... attempt to resume parsing */
|
||||
|
||||
switch( yyerrflag ){
|
||||
|
||||
case 0: /* brand new error */
|
||||
|
||||
yyerror( "syntax error" );
|
||||
yyerrlab:
|
||||
++yynerrs;
|
||||
|
||||
case 1:
|
||||
case 2: /* incompletely recovered error ... try again */
|
||||
|
||||
yyerrflag = 3;
|
||||
|
||||
/* find a state where "error" is a legal shift action */
|
||||
|
||||
while ( yyps >= yys ) {
|
||||
yyn = yypact[*yyps] + YYERRCODE;
|
||||
if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
|
||||
yystate = yyact[yyn]; /* simulate a shift of "error" */
|
||||
goto yystack;
|
||||
}
|
||||
yyn = yypact[*yyps];
|
||||
|
||||
/* the current yyps has no shift onn "error", pop stack */
|
||||
|
||||
#ifdef YYDEBUG
|
||||
if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
|
||||
#endif
|
||||
--yyps;
|
||||
--yypv;
|
||||
}
|
||||
|
||||
/* there is no state on the stack with an error shift ... abort */
|
||||
|
||||
yyabort:
|
||||
return(1);
|
||||
|
||||
|
||||
case 3: /* no shift yet; clobber input char */
|
||||
|
||||
#ifdef YYDEBUG
|
||||
if( yydebug ) printf( "error recovery discards char %d\n", yychar );
|
||||
#endif
|
||||
|
||||
if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
|
||||
yychar = -1;
|
||||
goto yynewstate; /* try again in the same state */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* reduction by production yyn */
|
||||
|
||||
#ifdef YYDEBUG
|
||||
if( yydebug ) printf("reduce %d\n",yyn);
|
||||
#endif
|
||||
yyps -= yyr2[yyn];
|
||||
yypvt = yypv;
|
||||
yypv -= yyr2[yyn];
|
||||
yyval = yypv[1];
|
||||
yym=yyn;
|
||||
/* consult goto table to find next state */
|
||||
yyn = yyr1[yyn];
|
||||
yyj = yypgo[yyn] + *yyps + 1;
|
||||
if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
|
||||
switch(yym){
|
||||
|
||||
case 4:
|
||||
{ yyerrok; } break;
|
||||
case 5:
|
||||
{ printf("store\n"); } break;
|
||||
case 6:
|
||||
{ printf("add\n"); } break;
|
||||
case 7:
|
||||
{ printf("negate\nadd\n"); } break;
|
||||
case 8:
|
||||
{ printf("multiply\n"); } break;
|
||||
case 9:
|
||||
{ printf("divide\n"); } break;
|
||||
case 10:
|
||||
{ printf("negate\n"); } break;
|
||||
case 12:
|
||||
{ printf("load\n"); } break;
|
||||
case 13:
|
||||
{ printf("push %s\n", yytext); } break;
|
||||
case 14:
|
||||
{ printf("%s\n", yytext); } break;
|
||||
}
|
||||
goto yystack; /* stack new state and value */
|
||||
|
||||
}
|
||||
int yywrap() { return 1; }
|
Loading…
Add table
Add a link
Reference in a new issue