1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
/* 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;
}
}
|