Skip to content

Commit

Permalink
bc: remove non-standard '**' operator (#518)
Browse files Browse the repository at this point in the history
* In yylex(), '^' and '**' are both tokenised as $EXP
* Also, '^=' and '**=' are both tokenised as $EXP_EQ
* Operators '**' and '**=' are not part of standard bc grammar so remove them [1]
* Tested against GNU, OpenBSD and Gavin Howard versions of bc

1. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/bc.html

Example input:
2 ^ 8
a = 2
a ^= 8
a
  • Loading branch information
mknos committed Mar 25, 2024
1 parent 9c562ab commit be51b31
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions bin/bc
Expand Up @@ -2224,13 +2224,10 @@ sub yylex
$IDENT;
}

} elsif (($char eq '*' && $line =~ s/^\*=//) or
($char eq '^' && $line =~ s/=//)) {
} elsif ($char eq '^' && $line =~ s/=//) {
$EXP_EQ;
} elsif (($char eq '*' && $line =~ s/^\*//) or
($char eq '^')) {
} elsif ($char eq '^') {
$EXP;

} elsif ($char eq '|' && $line =~ s/^\|//) {
$O_O;
} elsif ($char eq '&' && $line =~ s/^&//) {
Expand Down

0 comments on commit be51b31

Please sign in to comment.