/* Generated by re2c */
#include <limits.h>
#include <stdio.h>

template<int base>
static bool adddgt(unsigned long &u, unsigned int d)
{
    if (u > (ULONG_MAX - d) / base) {
        return false;
    }
    u = u * base + d;
    return true;
}

enum YYCONDTYPE {
	yycinit,
	yycbin,
	yycdec,
	yychex,
	yycoct,
};


static bool lex(const char *s, unsigned long &u)
{
    const char *YYMARKER;
    const char *YYCTXMARKER;
    int c = yycinit;
    u = 0;
    
{
	char yych;
	switch (c) {
	case yycinit: goto yyc_init;
	case yycbin: goto yyc_bin;
	case yycdec: goto yyc_dec;
	case yychex: goto yyc_hex;
	case yycoct: goto yyc_oct;
	}
/* *********************************** */
yyc_init:
	yych = *s;
	switch (yych) {
	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 yy3;
	}
yy3:
	++s;
	{ return false; }
yy5:
	yych = *(YYMARKER = ++s);
	switch (yych) {
	case 'B':
	case 'b':	goto yy9;
	case 'X':
	case 'x':	goto yy11;
	default:	goto yy6;
	}
yy6:
	c = yycoct;
	goto yyc_oct;
yy7:
	++s;
	s -= 1;
	c = yycdec;
	goto yyc_dec;
yy9:
	yych = *++s;
	switch (yych) {
	case '0':
	case '1':	goto yy12;
	default:	goto yy10;
	}
yy10:
	s = YYMARKER;
	goto yy6;
yy11:
	yych = *++s;
	switch (yych) {
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':
	case 'A':
	case 'B':
	case 'C':
	case 'D':
	case 'E':
	case 'F':
	case 'a':
	case 'b':
	case 'c':
	case 'd':
	case 'e':
	case 'f':	goto yy14;
	default:	goto yy10;
	}
yy12:
	++s;
	s -= 1;
	c = yycbin;
	goto yyc_bin;
yy14:
	++s;
	s -= 1;
	c = yychex;
	goto yyc_hex;
/* *********************************** */
yyc_bin:
	yych = *s;
	switch (yych) {
	case 0x00:	goto yy18;
	case '0':
	case '1':	goto yy22;
	default:	goto yy20;
	}
yy18:
	++s;
	{ return true; }
yy20:
	++s;
	{ return false; }
yy22:
	++s;
	{ if (!adddgt<2>(u, s[-1] - '0')) return false; goto yyc_bin; }
/* *********************************** */
yyc_dec:
	yych = *s;
	switch (yych) {
	case 0x00:	goto yy26;
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':	goto yy30;
	default:	goto yy28;
	}
yy26:
	++s;
	{ return true; }
yy28:
	++s;
	{ return false; }
yy30:
	++s;
	{ if (!adddgt<10>(u, s[-1] - '0')) return false; goto yyc_dec; }
/* *********************************** */
yyc_hex:
	yych = *s;
	switch (yych) {
	case 0x00:	goto yy34;
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':
	case '8':
	case '9':	goto yy38;
	case 'A':
	case 'B':
	case 'C':
	case 'D':
	case 'E':
	case 'F':	goto yy40;
	case 'a':
	case 'b':
	case 'c':
	case 'd':
	case 'e':
	case 'f':	goto yy42;
	default:	goto yy36;
	}
yy34:
	++s;
	{ return true; }
yy36:
	++s;
	{ return false; }
yy38:
	++s;
	{ if (!adddgt<16>(u, s[-1] - '0'))      return false; goto yyc_hex; }
yy40:
	++s;
	{ if (!adddgt<16>(u, s[-1] - 'A' + 10)) return false; goto yyc_hex; }
yy42:
	++s;
	{ if (!adddgt<16>(u, s[-1] - 'a' + 10)) return false; goto yyc_hex; }
/* *********************************** */
yyc_oct:
	yych = *s;
	switch (yych) {
	case 0x00:	goto yy46;
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
	case '7':	goto yy50;
	default:	goto yy48;
	}
yy46:
	++s;
	{ return true; }
yy48:
	++s;
	{ return false; }
yy50:
	++s;
	{ if (!adddgt<8>(u, s[-1] - '0')) return false; goto yyc_oct; }
}

}

int main(int argc, char **argv)
{
    for (int i = 1; i < argc; ++i) {
        unsigned long u;
        if (lex(argv[i], u)) {
            printf("%lu\n", u);
        } else {
            printf("error\n");
        }
    }
    return 0;
}
re2c: warning: line 35: rule in condition 'init' matches empty string [-Wmatch-empty-string]
