/* Generated by re2c */
#line 1 "calc_006.s.re"
/* re2c lesson 001_upn_calculator, calc_006, (c) M. Boerger 2006 */
-#line 34 "calc_006.s.re"
+#line 36 "calc_006.s.re"
#include <stdlib.h>
#include <stdio.h>
int stack[4];
int depth = 0;
-int push_num(const char *t, const char *l, int radix)
+int push_num(const unsigned char *t, const unsigned char *l, int radix)
{
int num = 0;
--t;
while(++t < l)
{
- num = num * radix + (*t - '0');
+ num = num * radix + (*t - (unsigned char)'0');
}
DEBUG(printf("Num: %d\n", num));
int scan(char *s)
{
- char *p = s;
- char *t;
+ unsigned char *p = (unsigned char*)s;
+ unsigned char *t;
int res = 0;
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR p
while(!res)
yych = *YYCURSOR;
goto yy21;
yy3:
-#line 105 "calc_006.s.re"
+#line 107 "calc_006.s.re"
{ continue; }
#line 99 "<stdout>"
yy4:
if((yych = *YYCURSOR) <= '/') goto yy5;
if(yych <= '9') goto yy17;
yy5:
-#line 107 "calc_006.s.re"
+#line 109 "calc_006.s.re"
{ res = push_num(t, p, 10); continue; }
#line 107 "<stdout>"
yy6:
goto yy16;
yy7:
++YYCURSOR;
-#line 108 "calc_006.s.re"
+#line 110 "calc_006.s.re"
{ res = stack_add(); continue; }
#line 115 "<stdout>"
yy9:
++YYCURSOR;
-#line 109 "calc_006.s.re"
+#line 111 "calc_006.s.re"
{ res = stack_sub(); continue; }
#line 120 "<stdout>"
yy11:
++YYCURSOR;
-#line 110 "calc_006.s.re"
- { res = depth == 1 ? 0 : 2; continue; }
+#line 112 "calc_006.s.re"
+ { res = depth == 1 ? 0 : 2; break; }
#line 125 "<stdout>"
yy13:
++YYCURSOR;
-#line 111 "calc_006.s.re"
+#line 113 "calc_006.s.re"
{ res = 1; continue; }
#line 130 "<stdout>"
yy15:
if(yych <= '/') goto yy19;
if(yych <= '9') goto yy17;
yy19:
-#line 106 "calc_006.s.re"
+#line 108 "calc_006.s.re"
{ res = push_num(t, p, 8); continue; }
#line 146 "<stdout>"
yy20:
if(yych == ' ') goto yy20;
goto yy3;
}
-#line 112 "calc_006.s.re"
+#line 114 "calc_006.s.re"
}
return res;
while(!res && ++argp < argc)
{
- inp = argv[argp];
+ inp = strdup(argv[argp]);
len = strlen(inp);
if (inp[0] == '\"' && inp[len-1] == '\"')
{
+ inp[len - 1] = '\0';
++inp;
- len -=2;
}
res = scan(inp);
+ free(inp);
}
switch(res)
{
- optimizing the generated code by using -s command line switch of re2c
. This tells re2c to generate code that uses if statements rather
- then endless switch/case expressions where appropriate.
+ then endless switch/case expressions where appropriate. Note that the
+ generated code now requires the input to be unsigned char rather than char
+ due to the way comparisons are generated.
*/
#include <stdlib.h>
int stack[4];
int depth = 0;
-int push_num(const char *t, const char *l, int radix)
+int push_num(const unsigned char *t, const unsigned char *l, int radix)
{
int num = 0;
--t;
while(++t < l)
{
- num = num * radix + (*t - '0');
+ num = num * radix + (*t - (unsigned char)'0');
}
DEBUG(printf("Num: %d\n", num));
int scan(char *s)
{
- char *p = s;
- char *t;
+ unsigned char *p = (unsigned char*)s;
+ unsigned char *t;
int res = 0;
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR p
while(!res)
INT { res = push_num(t, p, 10); continue; }
"+" { res = stack_add(); continue; }
"-" { res = stack_sub(); continue; }
- "\000" { res = depth == 1 ? 0 : 2; continue; }
+ "\000" { res = depth == 1 ? 0 : 2; break; }
[^] { res = 1; continue; }
*/
}
while(!res && ++argp < argc)
{
- inp = argv[argp];
+ inp = strdup(argv[argp]);
len = strlen(inp);
if (inp[0] == '\"' && inp[len-1] == '\"')
{
+ inp[len - 1] = '\0';
++inp;
- len -=2;
}
res = scan(inp);
+ free(inp);
}
switch(res)
{
/* Generated by re2c */
#line 1 "calc_007.b.re"
/* re2c lesson 001_upn_calculator, calc_007, (c) M. Boerger 2006 */
-#line 8 "calc_007.b.re"
+#line 9 "calc_007.b.re"
#include <stdlib.h>
#include <stdio.h>
int stack[4];
int depth = 0;
-int push_num(const char *t, const char *l, int radix)
+int push_num(const unsigned char *t, const unsigned char *l, int radix)
{
int num = 0;
--t;
while(++t < l)
{
- num = num * radix + (*t - '0');
+ num = num * radix + (*t - (unsigned char)'0');
}
DEBUG(printf("Num: %d\n", num));
int scan(char *s)
{
- char *p = s;
- char *t;
+ unsigned char *p = (unsigned char*)s;
+ unsigned char *t;
int res = 0;
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR p
while(!res)
yych = *YYCURSOR;
goto yy21;
yy3:
-#line 79 "calc_007.b.re"
+#line 80 "calc_007.b.re"
{ continue; }
#line 134 "<stdout>"
yy4:
if((yych = *YYCURSOR) <= '/') goto yy5;
if(yych <= '9') goto yy17;
yy5:
-#line 81 "calc_007.b.re"
+#line 82 "calc_007.b.re"
{ res = push_num(t, p, 10); continue; }
#line 142 "<stdout>"
yy6:
goto yy16;
yy7:
++YYCURSOR;
-#line 82 "calc_007.b.re"
+#line 83 "calc_007.b.re"
{ res = stack_add(); continue; }
#line 150 "<stdout>"
yy9:
++YYCURSOR;
-#line 83 "calc_007.b.re"
+#line 84 "calc_007.b.re"
{ res = stack_sub(); continue; }
#line 155 "<stdout>"
yy11:
++YYCURSOR;
-#line 84 "calc_007.b.re"
- { res = depth == 1 ? 0 : 2; continue; }
+#line 85 "calc_007.b.re"
+ { res = depth == 1 ? 0 : 2; break; }
#line 160 "<stdout>"
yy13:
++YYCURSOR;
-#line 85 "calc_007.b.re"
+#line 86 "calc_007.b.re"
{ res = 1; continue; }
#line 165 "<stdout>"
yy15:
if(yych <= '/') goto yy19;
if(yych <= '9') goto yy17;
yy19:
-#line 80 "calc_007.b.re"
+#line 81 "calc_007.b.re"
{ res = push_num(t, p, 8); continue; }
#line 182 "<stdout>"
yy20:
goto yy3;
}
}
-#line 86 "calc_007.b.re"
+#line 87 "calc_007.b.re"
}
return res;
while(!res && ++argp < argc)
{
- inp = argv[argp];
+ inp = strdup(argv[argp]);
len = strlen(inp);
if (inp[0] == '\"' && inp[len-1] == '\"')
{
+ inp[len - 1] = '\0';
++inp;
- len -=2;
}
res = scan(inp);
+ free(inp);
}
switch(res)
{
- optimizing the generated code by using -b command line switch of re2c
. This tells re2c to generate code that uses a decision table. The -b switch
- also contains the -s behavior.
+ also contains the -s behavior. And -b also requires the input to be
+ unsigned chars.
*/
#include <stdlib.h>
int stack[4];
int depth = 0;
-int push_num(const char *t, const char *l, int radix)
+int push_num(const unsigned char *t, const unsigned char *l, int radix)
{
int num = 0;
--t;
while(++t < l)
{
- num = num * radix + (*t - '0');
+ num = num * radix + (*t - (unsigned char)'0');
}
DEBUG(printf("Num: %d\n", num));
int scan(char *s)
{
- char *p = s;
- char *t;
+ unsigned char *p = (unsigned char*)s;
+ unsigned char *t;
int res = 0;
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR p
while(!res)
INT { res = push_num(t, p, 10); continue; }
"+" { res = stack_add(); continue; }
"-" { res = stack_sub(); continue; }
- "\000" { res = depth == 1 ? 0 : 2; continue; }
+ "\000" { res = depth == 1 ? 0 : 2; break; }
[^] { res = 1; continue; }
*/
}
while(!res && ++argp < argc)
{
- inp = argv[argp];
+ inp = strdup(argv[argp]);
len = strlen(inp);
if (inp[0] == '\"' && inp[len-1] == '\"')
{
+ inp[len - 1] = '\0';
++inp;
- len -=2;
}
res = scan(inp);
+ free(inp);
}
switch(res)
{
*/
int ScanFullSpeed(char *pzStrToScan, size_t lenStrToScan)
{
- char *pzCurScanPos = pzStrToScan;
- char *pzBacktrackInfo = 0;
-#define YYCTYPE char
+ unsigned char *pzCurScanPos = (unsigned char*)pzStrToScan;
+ unsigned char *pzBacktrackInfo = 0;
+#define YYCTYPE unsigned char
#define YYCURSOR pzCurScanPos
#define YYLIMIT (pzStrToScan+lenStrToScan)
#define YYMARKER pzBacktrackInfo
*/
int scan(char *pzStrToScan, size_t lenStrToScan)
{
- char *pzCurScanPos = pzStrToScan;
- char *pzBacktrackInfo = 0;
-#define YYCTYPE char
+ unsigned char *pzCurScanPos = (unsigned char*)pzStrToScan;
+ unsigned char *pzBacktrackInfo = 0;
+#define YYCTYPE unsigned char
#define YYCURSOR pzCurScanPos
#define YYLIMIT (pzStrToScan+lenStrToScan)
#define YYMARKER pzBacktrackInfo
*/
int ScanFullSpeed(char *pzStrToScan, size_t lenStrToScan)
{
- char *pzCurScanPos = pzStrToScan;
- char *pzBacktrackInfo = 0;
-#define YYCTYPE char
+ unsigned char *pzCurScanPos = (unsigned char*)pzStrToScan;
+ unsigned char *pzBacktrackInfo = 0;
+#define YYCTYPE unsigned char
#define YYCURSOR pzCurScanPos
#define YYLIMIT (pzStrToScan+lenStrToScan)
#define YYMARKER pzBacktrackInfo
*/
int scan(char *pzStrToScan, size_t lenStrToScan)
{
- char *pzCurScanPos = pzStrToScan;
- char *pzBacktrackInfo = 0;
-#define YYCTYPE char
+ unsigned char *pzCurScanPos = (unsigned char*)pzStrToScan;
+ unsigned char *pzBacktrackInfo = 0;
+#define YYCTYPE unsigned char
#define YYCURSOR pzCurScanPos
#define YYLIMIT (pzStrToScan+lenStrToScan)
#define YYMARKER pzBacktrackInfo
# error BSIZE must be greater YYMAXFILL
#endif
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR s.cur
#define YYLIMIT s.lim
#define YYFILL(n) { if ((res = fill(&s, n)) >= 0) break; }
typedef struct Scanner
{
- FILE *fp;
- char *cur, *tok, *lim, *eof;
- char buffer[BSIZE];
+ FILE *fp;
+ unsigned char *cur, *tok, *lim, *eof;
+ unsigned char buffer[BSIZE];
} Scanner;
int fill(Scanner *s, int len)
{
if (!len)
{
- s->tok = s->cur = buf = s->lim = s->buffer
+ s->cur = s->tok = s->lim = s->buffer;
s->eof = 0;
}
if (!s->eof)
# error BSIZE must be greater YYMAXFILL
#endif
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR s.cur
#define YYLIMIT s.lim
#define YYFILL(n) { if ((res = fill(&s, n)) >= 0) break; }
typedef struct Scanner
{
- FILE *fp;
- char *cur, *tok, *lim, *eof;
- char buffer[BSIZE];
+ FILE *fp;
+ unsigned char *cur, *tok, *lim, *eof;
+ unsigned char buffer[BSIZE];
} Scanner;
int fill(Scanner *s, int len)
{
if (!len)
{
- s->tok = s->cur = buf = s->lim = s->buffer
+ s->cur = s->tok = s->lim = s->buffer;
s->eof = 0;
}
if (!s->eof)
# error BSIZE must be greater YYMAXFILL
#endif
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR s.cur
#define YYLIMIT s.lim
#define YYMARKER s.mrk
typedef struct Scanner
{
- FILE *fp;
- char *cur, *tok, *lim, *eof, *mrk;
- char buffer[BSIZE];
+ FILE *fp;
+ unsigned char *cur, *tok, *lim, *eof, *mrk;
+ unsigned char buffer[BSIZE];
} Scanner;
int fill(Scanner *s, int len)
{
if (!len)
{
- s->tok = s->cur = s->lim = s->mrk = s->buffer;
+ s->cur = s->tok = s->lim = s->mrk = s->buffer;
s->eof = 0;
}
if (!s->eof)
# error BSIZE must be greater YYMAXFILL
#endif
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR s.cur
#define YYLIMIT s.lim
#define YYMARKER s.mrk
typedef struct Scanner
{
- FILE *fp;
- char *cur, *tok, *lim, *eof, *mrk;
- char buffer[BSIZE];
+ FILE *fp;
+ unsigned char *cur, *tok, *lim, *eof, *mrk;
+ unsigned char buffer[BSIZE];
} Scanner;
int fill(Scanner *s, int len)
{
if (!len)
{
- s->tok = s->cur = s->lim = s->mrk = s->buffer;
+ s->cur = s->tok = s->lim = s->mrk = s->buffer;
s->eof = 0;
}
if (!s->eof)
# error BSIZE must be greater YYMAXFILL
#endif
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR s.cur
#define YYLIMIT s.lim
#define YYMARKER s.mrk
typedef struct Scanner
{
- FILE *fp;
- char *cur, *tok, *lim, *eof, *ctx, *mrk;
- char buffer[BSIZE];
+ FILE *fp;
+ unsigned char *cur, *tok, *lim, *eof, *ctx, *mrk;
+ unsigned char buffer[BSIZE];
} Scanner;
int fill(Scanner *s, int len)
{
if (!len)
{
- s->tok = s->cur = s->lim = s->mrk = s->buffer;
+ s->cur = s->tok = s->lim = s->mrk = s->buffer;
s->eof = 0;
}
if (!s->eof)
# error BSIZE must be greater YYMAXFILL
#endif
-#define YYCTYPE char
+#define YYCTYPE unsigned char
#define YYCURSOR s.cur
#define YYLIMIT s.lim
#define YYMARKER s.mrk
typedef struct Scanner
{
- FILE *fp;
- char *cur, *tok, *lim, *eof, *ctx, *mrk;
- char buffer[BSIZE];
+ FILE *fp;
+ unsigned char *cur, *tok, *lim, *eof, *ctx, *mrk;
+ unsigned char buffer[BSIZE];
} Scanner;
int fill(Scanner *s, int len)
{
if (!len)
{
- s->tok = s->cur = s->lim = s->mrk = s->buffer;
+ s->cur = s->tok = s->lim = s->mrk = s->buffer;
s->eof = 0;
}
if (!s->eof)