/* Generated by re2c */
#line 1 "calc_004.re"
// re2c $INPUT -o $OUTPUT 
/* re2c lesson 001_upn_calculator, calc_004, (c) M. Boerger 2006 - 2007 */
#line 20 "calc_004.re"


#include <stdlib.h>
#include <stdio.h>
#include <string.h>

char * tokendup(const char *t, const char *l)
{
	size_t n = l -t + 1;
	char *r = (char*)malloc(n);
	
	memmove(r, t, n-1);
	r[n] = '\0';
	return r;
}

int scan(char *s, int l)
{
	char *p = s;
	char *q = 0;
	char *t;
#define YYCTYPE         char
#define YYCURSOR        p
#define YYLIMIT         (s+l+2)
#define YYMARKER        q
#define YYFILL(n)		{ printf("OOD\n"); return 2; }
	
	for(;;)
	{
		t = p;

#line 38 "calc_004.c"
		{
			YYCTYPE yych;
			if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
			yych = *YYCURSOR;
			switch (yych) {
				case 0x00: goto yy1;
				case '+': goto yy3;
				case '-': goto yy4;
				case '0': goto yy5;
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9': goto yy7;
				default: goto yy2;
			}
yy1:
			++YYCURSOR;
#line 61 "calc_004.re"
			{ printf("EOF\n");	return 0; }
#line 63 "calc_004.c"
yy2:
			++YYCURSOR;
#line 62 "calc_004.re"
			{ printf("ERR\n");	return 1; }
#line 68 "calc_004.c"
yy3:
			++YYCURSOR;
#line 59 "calc_004.re"
			{ printf("+\n");	continue; }
#line 73 "calc_004.c"
yy4:
			++YYCURSOR;
#line 60 "calc_004.re"
			{ printf("+\n");	continue; }
#line 78 "calc_004.c"
yy5:
			yych = *++YYCURSOR;
			switch (yych) {
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9': goto yy8;
				default: goto yy6;
			}
yy6:
#line 58 "calc_004.re"
			{ t = tokendup(t, p); printf("Num: %s\n", t); free(t); continue; }
#line 97 "calc_004.c"
yy7:
			++YYCURSOR;
			if (YYLIMIT <= YYCURSOR) YYFILL(1);
			yych = *YYCURSOR;
			switch (yych) {
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9': goto yy7;
				default: goto yy6;
			}
yy8:
			++YYCURSOR;
			if (YYLIMIT <= YYCURSOR) YYFILL(1);
			yych = *YYCURSOR;
			switch (yych) {
				case '0':
				case '1':
				case '2':
				case '3':
				case '4':
				case '5':
				case '6':
				case '7':
				case '8':
				case '9': goto yy8;
				default: goto yy9;
			}
yy9:
#line 57 "calc_004.re"
			{ t = tokendup(t, p); printf("Oct: %s\n", t); free(t); continue; }
#line 135 "calc_004.c"
		}
#line 63 "calc_004.re"

	}
	return 0;
}

int main(int argc, char **argv)
{
	if (argc > 1)
	{
		return scan(argv[1], strlen(argv[1]));
	}
	else
	{
		fprintf(stderr, "%s <expr>\n", argv[0]);
		return 0;
	}
}
