From f1dd3f065a97f57bf59db2e3284868e181734159 Mon Sep 17 00:00:00 2001 From: deepcube Date: Thu, 19 Sep 2019 10:10:28 -0700 Subject: hoc: don't nest calls to follow() when lexing ++/+= and --/-= (#287) 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. --- src/cmd/hoc/hoc.y | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/cmd/hoc/hoc.y') diff --git a/src/cmd/hoc/hoc.y b/src/cmd/hoc/hoc.y index 9c5a02f1..f634e82d 100644 --- a/src/cmd/hoc/hoc.y +++ b/src/cmd/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, '%'); -- cgit v1.2.3