summaryrefslogtreecommitdiff
path: root/expr.y
diff options
context:
space:
mode:
Diffstat (limited to 'expr.y')
-rw-r--r--expr.y60
1 files changed, 40 insertions, 20 deletions
diff --git a/expr.y b/expr.y
index f1648e7..9b28faf 100644
--- a/expr.y
+++ b/expr.y
@@ -45,74 +45,94 @@ expr : STRING {
}
| INTEGER {
- printf("%d\n", $1.u.i);
+ printf("%jd\n", $1.u.i);
}
| '(' expr ')' {
+ $$ = $2;
+ return $$.type;
}
| expr ':' expr {
printf("match\n");
+ /* TODO: number of initial characters in $1.u.s matching re $2.u.s */
}
| expr '*' expr {
expr_only_integers(&$1, &$3);
$$.u.i = $1.u.i * $3.u.i;
- printf("%d\n", $$.u.i);
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr '/' expr {
expr_only_integers(&$1, &$3);
$$.u.i = $1.u.i / $3.u.i;
- printf("%d\n", $$.u.i);
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr '%' expr {
expr_only_integers(&$1, &$3);
$$.u.i = $1.u.i % $3.u.i;
- printf("%d\n", $$.u.i);
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr '+' expr {
expr_only_integers(&$1, &$3);
$$.u.i = $1.u.i + $3.u.i;
- printf("%d\n", $$.u.i);
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr '-' expr {
expr_only_integers(&$1, &$3);
$$.u.i = $1.u.i - $3.u.i;
- printf("%d\n", $$.u.i);
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr '=' expr {
- int r = expr_compare(&$1, &$3) == 0;
- printf("%d\n", r);
+ $$.type = INTEGER;
+ $$.u.i = expr_compare(&$1, &$3) == 0;
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr NE expr {
- int r = expr_compare(&$1, &$3) != 0;
- printf("%d\n", r);
+ $$.type = INTEGER;
+ $$.u.i = expr_compare(&$1, &$3) != 0;
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr '<' expr {
- int r = expr_compare(&$1, &$3) < 0;
- printf("%d\n", r);
+ $$.type = INTEGER;
+ $$.u.i = expr_compare(&$1, &$3) < 0;
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr LE expr {
- int r = expr_compare(&$1, &$3) <= 0;
- printf("%d\n", r);
+ $$.type = INTEGER;
+ $$.u.i = expr_compare(&$1, &$3) <= 0;
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr '>' expr {
- int r = expr_compare(&$1, &$3) > 0;
- printf("%d\n", r);
+ $$.type = INTEGER;
+ $$.u.i = expr_compare(&$1, &$3) > 0;
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr GE expr {
- int r = expr_compare(&$1, &$3) >= 0;
- printf("%d\n", r);
+ $$.type = INTEGER;
+ $$.u.i = expr_compare(&$1, &$3) >= 0;
+ printf("%jd\n", $$.u.i);
+ return $$.type;
}
| expr '&' expr {
@@ -149,10 +169,10 @@ static int expr_compare(YYSTYPE *y1, YYSTYPE *y2)
char *s2 = y2->u.s;
if (y1->type == INTEGER) {
- snprintf(buf, sizeof(buf), "%d", y1->u.i);
+ snprintf(buf, sizeof(buf), "%jd", y1->u.i);
s1 = buf;
} else if (y2->type == INTEGER) {
- snprintf(buf, sizeof(buf), "%d", y2->u.i);
+ snprintf(buf, sizeof(buf), "%jd", y2->u.i);
s2 = buf;
}