-
-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ternary operator ? should be right associative #712
Comments
$ osh -c '((1?a=1:(b=1)))'
((1?a=1:(b=1)))
^
[ -c flag ]:1: Parser expected Id.Arith_Colon, got Id.Arith_Equal |
I'm sorry the bug is not caused by this change. I'm not sure why the problem did not appear in Edit: OK, this problem started to appear because of a recent change to |
OK cool, yes it should be doing the right thing now! It was parsing incorrectly before this. I guess you need parens around |
Thank you. Yes, I know that I can work around it by adding parens, and in fact, now I have parens there to test ble.sh in Oil. But, we don't usually need such parens in conditional operators in C and similar languages. Is there any reason not to support it in Oil? I tested with shells and was surprised that |
Ah it is possible that there is a precedence bug between |
Yeah according to the precedence table, https://en.cppreference.com/w/c/language/operator_precedence
Shell specifies that its arithmetic is identical to C arithmetic, so I guess this is a bug. So I am not sure right now how to fix this using the TDOP parsing algorithm, but it can probably be done. It sounds like it's a special case in C, which was originally done with the shunting yard algorithm... not sure if that matters or not. |
What's wrong with the output? If you're referring to the error messages, only stdout is counted in the golf and the stderr junk is intended. You can prepend it with
:
to stop it.The prime numbers program works with
let
aslet(){ IFS=,;return $((!($*)));}
andeval_unsafe_arith
.The divisors program doesn't work even with workarounds for the lack of
$_
and$[
as OSH doesn't support mixed case in brace expansion ({a..C}
).The FizzBuzz program doesn't work even with workarounds for the lack of
$_
; it seems to be because OSH doesn't support nested ternary:bash
,dash
,ksh
,mrsh
,yash
, andzsh
seem to support it, butash
doesn't seem to eitherOriginally posted by @Crestwave in #161 (comment)
The text was updated successfully, but these errors were encountered: