25 #define DEBUG(x) do { x ; } while (0)
49 v->type = VALUE_TYPE_INTEGER;
62 v->type = VALUE_TYPE_STRING;
73 if (v->type == VALUE_TYPE_STRING)
74 v->data.s =
_free(v->data.s);
80 static void valueDump(
const char *msg,
Value v, FILE *fp)
84 fprintf(fp,
"%s ", msg);
86 if (v->type == VALUE_TYPE_INTEGER)
87 fprintf(fp,
"INTEGER %d\n", v->data.i);
89 fprintf(fp,
"STRING '%s'\n", v->data.s);
91 fprintf(fp,
"NULL\n");
95 #define valueIsInteger(v) ((v)->type == VALUE_TYPE_INTEGER)
96 #define valueIsString(v) ((v)->type == VALUE_TYPE_STRING)
97 #define valueSameType(v1,v2) ((v1)->type == (v2)->type)
120 #define TOK_INTEGER 2
122 #define TOK_IDENTIFIER 4
125 #define TOK_MULTIPLY 7
128 #define TOK_CLOSE_P 10
136 #define TOK_LOGICAL_AND 18
137 #define TOK_LOGICAL_OR 19
140 #define EXPRBUFSIZ BUFSIZ
142 #if defined(DEBUG_PARSER)
143 typedef struct exprTokTableEntry {
148 ETTE_t exprTokTable[] = {
171 static const char *prToken(
int val)
176 for (et = exprTokTable; et->name != NULL; et++) {
289 while (*p && (
xisalnum(*p) || *p ==
'_'))
297 }
else if (*p ==
'\"') {
302 while (*p && *p !=
'\"')
319 DEBUG(printf(
"rdToken: \"%s\" (%d)\n", prToken(token), token));
343 DEBUG(printf(
"doPrimary()\n"));
412 DEBUG(valueDump(
"doPrimary:", v, stdout));
427 DEBUG(printf(
"doMultiplyDivide()\n"));
453 int i1 = v1->data.i, i2 = v2->data.i;
483 DEBUG(printf(
"doAddSubtract()\n"));
508 int i1 = v1->data.i, i2 = v2->data.i;
523 copy =
xmalloc(strlen(v1->data.s) + strlen(v2->data.s) + 1);
548 DEBUG(printf(
"doRelational()\n"));
573 int i1 = v1->data.i, i2 = v2->data.i, r = 0;
599 const char * s1 = v1->data.s;
600 const char * s2 = v2->data.s;
604 r = (strcmp(s1,s2) == 0);
607 r = (strcmp(s1,s2) != 0);
610 r = (strcmp(s1,s2) < 0);
613 r = (strcmp(s1,s2) <= 0);
616 r = (strcmp(s1,s2) > 0);
619 r = (strcmp(s1,s2) >= 0);
644 DEBUG(printf(
"doLogical()\n"));
670 int i1 = v1->data.i, i2 = v2->data.i;
694 DEBUG(printf(
"parseExprBoolean(?, '%s')\n", expr));
717 DEBUG(valueDump(
"parseExprBoolean:", v, stdout));
720 case VALUE_TYPE_INTEGER:
721 result = v->data.i != 0;
723 case VALUE_TYPE_STRING:
725 result = v->data.s[0] !=
'\0';
743 DEBUG(printf(
"parseExprString(?, '%s')\n", expr));
766 DEBUG(valueDump(
"parseExprString:", v, stdout));
770 case VALUE_TYPE_INTEGER: {
772 sprintf(buf,
"%d", v->data.i);
775 case VALUE_TYPE_STRING: