commit 63916da7bd6d73d9a405ce83fc4ca34845667cce
Author: Evan Gates <[email protected]>
AuthorDate: Wed Sep 11 15:46:27 2019 -0700
Commit: Anselm R Garbe <[email protected]>
CommitDate: Fri Sep 13 15:56:15 2019 +0000
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.
diff --git a/hoc/hoc.y b/hoc/hoc.y
index 9c5a02f..f634e82 100644
--- 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, '%');