Skip to content

Commit

Permalink
hoc: don't nest calls to follow() when lexing ++/+= and --/-= (9fans#287
Browse files Browse the repository at this point in the history
)

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.
  • Loading branch information
deepcube authored and dancrossnyc committed Sep 19, 2019
1 parent 9389de6 commit f1dd3f0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/cmd/hoc/hoc.y
Original file line number Diff line number Diff line change
Expand Up @@ -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, '%');
Expand Down

0 comments on commit f1dd3f0

Please sign in to comment.