From 77119eba7479e6352d22a3ce991d48b6ad0884bc Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 15 Sep 2011 14:25:51 +0200 Subject: [PATCH 1/1] isl_stream_next_token: treat "-0" as two tokens '-' and '0' Usually, a '-' followed by a sequence of digits is treated as a single (negative) number. When parsing affine expressions, negative numbers are allowed without a preceding '+'. However, if "-0" is parsed as '0' then there is no way of distinguishing between "-0" and "0" and so "-0" was not allowed in affine expressions. We now treat "-0" as two tokens, so that it can be used in affine expressions. The flip side is that "-0" can no longer be used where a single integer is expected. Signed-off-by: Sven Verdoolaege --- isl_stream.c | 10 ++++++++++ isl_test.c | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/isl_stream.c b/isl_stream.c index 01a2caa..3643893 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -391,6 +391,7 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line) } } if (c == '-' || isdigit(c)) { + int minus = c == '-'; tok = isl_token_new(s->ctx, line, col, old_line != line); if (!tok) return NULL; @@ -405,6 +406,15 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line) isl_stream_ungetc(s, c); isl_stream_push_char(s, '\0'); isl_int_read(tok->u.v, s->buffer); + if (minus && isl_int_is_zero(tok->u.v)) { + tok->col++; + tok->on_new_line = 0; + isl_stream_push_token(s, tok); + tok = isl_token_new(s->ctx, line, col, old_line != line); + if (!tok) + return NULL; + tok->type = (enum isl_token_type) '-'; + } return tok; } if (isalpha(c) || c == '_') { diff --git a/isl_test.c b/isl_test.c index 075650a..a0173b3 100644 --- a/isl_test.c +++ b/isl_test.c @@ -140,6 +140,10 @@ void test_parse(struct isl_ctx *ctx) str2 = "[N, M] -> { [i] : N = 2 and 4i <= 2 + M and 4i >= -1 + M }"; test_parse_map_equal(ctx, str, str2); + str = "{ [x] : x >= 0 }"; + str2 = "{ [x] : x-0 >= 0 }"; + test_parse_map_equal(ctx, str, str2); + test_parse_pwqp(ctx, "{ [i] -> i + [ (i + [i/3])/2 ] }"); test_parse_map(ctx, "{ S1[i] -> [([i/10]),i%10] : 0 <= i <= 45 }"); } -- 2.7.4