commit 63916da7bd6d73d9a405ce83fc4ca34845667cce
parent 09e95a2d6f8dbafc6601147b2f5f150355813be6
Author: Evan Gates <evan@gnarbox.com>
Date: Wed, 11 Sep 2019 15:46:27 -0700
hoc: Don't nest calls to follow() when lexing ++/+= and --/-=
The code had a nested use of the follow() function that could cause +=+
and -=- to register as ++ and --. The first follow() to execute could
consume a character and match and then the second follow() could consume
another character and match. For example i-=-10 would result in a syntax
error and i-=- would decrement i.
Diffstat:
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hoc/hoc.y b/hoc/hoc.y
@@ -215,8 +215,8 @@ yylex(void) /* hoc6 */
return STRING;
}
switch (c) {
- case '+': return follow('+', INC, follow('=', ADDEQ, '+'));
- case '-': return follow('-', DEC, follow('=', SUBEQ, '-'));
+ case '+': return follow('+', INC, '+') == INC ? INC : follow('=', ADDEQ, '+');
+ case '-': return follow('-', DEC, '-') == DEC ? DEC : follow('=', SUBEQ, '-');
case '*': return follow('=', MULEQ, '*');
case '/': return follow('=', DIVEQ, '/');
case '%': return follow('=', MODEQ, '%');