[ create a new paste ] login | about

Link: http://codepad.org/pnBO3znk    [ raw code | output | fork ]

C, pasted on Nov 19:
#include <stdio.h>
#include <ctype.h>

#define t(s) (W=T(s))

char *X, *B, *L, I[99];
int M, W, V;

int
D()
{
	if (W == 9) {
		printf("'%.*s' is ", V, X);
		t(0);
	} else if (W == 40) {
		t(0);
		D();
		t(41);
	} else if (W == 42) {
		t(0);
		D();
		printf("ptr to ");
	} else {
		0;
	}
	while (1) {
		if (W == 40) {
			t(0);
			printf("func returning ");
			t(41);
		} else if (W == 91) {
			// この辺りがバグの原因っぽい気がする
			if (t(0) == 32) {
				printf("array[0..%d] of ", atoi(X) - 1);
				t(0);
			} else {
				printf("array of ");
				t(93);
			}
		} else {
			0;
			break;
		}
	}
}

int
T(s)
{
	if (!s || s == W) {
		while (*B == 9 || *B == 32)
			B++;
		X = B;
		V = 0;
		W = isalpha(*B);
		if (W) {
		       W = 9;
		} else if (isdigit(*B)) {
			W = 32;
		} else {
			W = *B++;
		}
		if (W < 33) {
			while (isalnum(*B)) {
				B++;
				V++;
			}
		}
	}
	return W;
}

int
main()
{
	do {
		printf("input: ");
		B = gets(I);
		if (t(0) == 9) {
			L = X;
			M = V;
			t(0);
			D();
			printf("%.*s.\n\n", M, L);
		}
	} while (B);
}


Output:
1
Segmentation fault


Create a new paste based on this one


Comments: