mirror of
https://salsa.debian.org/dskoll/remind.git
synced 2026-04-17 06:48:47 +02:00
Properly parse unary '+' operator. It's ignored, essentially.
This commit is contained in:
27
src/expr.c
27
src/expr.c
@@ -2144,8 +2144,7 @@ static int make_atom(expr_node *atom, Var *locals)
|
||||
/* */
|
||||
/* Parse an atom. */
|
||||
/* */
|
||||
/* ATOM: '+' ATOM | */
|
||||
/* '(' EXPR ')' | */
|
||||
/* ATOM: '(' EXPR ')' | */
|
||||
/* CONSTANT | */
|
||||
/* VAR | */
|
||||
/* FUNCTION_CALL */
|
||||
@@ -2159,18 +2158,6 @@ static expr_node *parse_atom(char const **e, int *r, Var *locals, int level)
|
||||
*r = PEEK_TOKEN();
|
||||
if (*r != OK) return NULL;
|
||||
|
||||
/* Ignore unary-plus operators */
|
||||
while (TOKEN_IS("+")) {
|
||||
*r = GET_TOKEN();
|
||||
if (*r != OK) {
|
||||
return NULL;
|
||||
}
|
||||
*r = PEEK_TOKEN();
|
||||
if (*r != OK) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (TOKEN_IS("(")) {
|
||||
/* Parenthesiszed expession: '(' EXPR ')' */
|
||||
|
||||
@@ -2238,6 +2225,7 @@ static expr_node *parse_atom(char const **e, int *r, Var *locals, int level)
|
||||
/* */
|
||||
/* FACTOR_EXP: '-' FACTOR_EXP | */
|
||||
/* '!' FACTOR_EXP | */
|
||||
/* '+' FACTOR_EXP */
|
||||
/* ATOM */
|
||||
/* */
|
||||
/***************************************************************/
|
||||
@@ -2251,11 +2239,13 @@ static expr_node *parse_factor(char const **e, int *r, Var *locals, int level)
|
||||
if (*r != OK) {
|
||||
return NULL;
|
||||
}
|
||||
if (TOKEN_IS("!") || TOKEN_IS("-")) {
|
||||
if (TOKEN_IS("!") || TOKEN_IS("-") || TOKEN_IS("+")) {
|
||||
if (TOKEN_IS("!")) {
|
||||
op = '!';
|
||||
} else {
|
||||
} else if (TOKEN_IS("-")) {
|
||||
op = '-';
|
||||
} else {
|
||||
op = '+';
|
||||
}
|
||||
/* Pull off the peeked token */
|
||||
GET_TOKEN();
|
||||
@@ -2264,6 +2254,11 @@ static expr_node *parse_factor(char const **e, int *r, Var *locals, int level)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Ignore unary plus operator */
|
||||
if (op == '+') {
|
||||
return node;
|
||||
}
|
||||
|
||||
/* Optimize '-' or '!' followed by integer constant */
|
||||
if (node->type == N_CONSTANT &&node->u.value.type == INT_TYPE) {
|
||||
if (op == '-') {
|
||||
|
||||
Reference in New Issue
Block a user