On 7/7/22 12:11 PM, Steffen Nurpmeso wrote:
Hello!
Hi.
Funnily my parser has only one (what i know) problem left, the same as bash. On the other hand i found more.
The thing about all of this is that these are operators, and so delimit tokens. Whitespace is siginficant only when determining the length of the token or operator. Operators have context-dependent meaning (e.g., `+' can be a unary or binary operator depending on context, and `++10' does not mean the same thing as `+ +10').
[ # make this work with (ba)sh \ command -v shopt && shopt -s expand_aliases;\ alias p=printf;alias e=echo;alias s=export # s I=10 J=33 ] e "<$(( 3 + ( 11 ) ))>" s I=10 J=33;p "<$(( +10 + + +I ))>";e "<$I>"
Unary plus, constant, binary plus operator, unary plus, unary plus, identifier
s I=10 J=33;p "<$(( +10 + ++I ))>";e "<$I>"
Unary plus, constant, binary plus operator, prefix increment, identifier
s I=10 J=33;p "<$(( +10 ++ +I ))>";e "<$I>"
Unary plus, constant, binary plus, unary plus, unary plus, identifier (this is one place where the bash arithmetic parser is forgiving, since the above interpretation predated the addition of ++ and --)
s I=10 J=33;p "<$(( +10 +++ I ))>";e "<$I>"
Unary plus, constant, binary plus, unary plus, unary plus, identifier (same)
s I=10 J=33;p "<$(( +10+++I ))>";e "<$I>"
Unary plus, constant, binary plus, prefix increment, identifier
And one more thing. -<802379605485813759> +<9223372036854775807> This is from $ bash -c 'echo $((999999999999999999999999999999999999999999999))' 802379605485813759 $ dash -c 'echo $((999999999999999999999999999999999999999999999))' 9223372036854775807
dash is what happens when you clamp the value at INTMAX_MAX (LLONG_MAX) because it overflows -- but don't say anything about it -- instead of just doing the conversion without checking for overflow. Neither value is `right', and even the predictability of INTMAX_MAX is useless. Chet -- ``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/