On 7/6/22 1:10 PM, Steffen Nurpmeso wrote:
Hello.
'Struggling with a Dijkstra two stack parser i am thankful to be
able to compare against bash that uses a completely different and
correct parser!
I stumbled upon this (bash 5.1.16); i find it "understandable" in
respect to clarity, but inconsistent, and also in hindsight to the
announcement of a forthcoming release i thought i report it quick:
$ bash -c 'I=10; echo $((1++I)); echo $I'
bash: line 1: 1++I: syntax error in expression (error token is "++I")
$ bash -c 'I=10; echo $((1++1)); echo $I'
10
Thanks for the report. Most of these are due to bash trying to be helpful.
The pre/postfix operators are parsed as such when they make sense depending
on what precedes or follows them. For instance, if you have ++I, it's
parsed as a pre-increment; if you have ++1, it's parsed as two unary plus
operators and an integer constant.
(Part of this was an attempt to be backwards compatible when I added the
++ and -- operators, since they weren't present until bash-2.04.)
$ bash -c 'I=10;echo "<$(( +10+++I ))>"'
<21>
unary plus, constant, binary plus operator, pre-increment, variable
$ bash -c 'I=10;echo "<$(( +10+ ++I ))>"'
<21>
same
$ bash -c 'I=10;echo "<$(( +10+ +I ))>"'
<20>
unary plus, constant, binary plus operator, unary plus, variable
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/