-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add grammar for "if (test) then {expr}" with no else #284
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If curly braces are used, I would strongly vote for allowing the else
branch. Due to the braces, we now have an unambiguous assignment of conditions and branches. Examples:
Expression | Equivalent expression |
---|---|
if($a) { if($b) { $c } } |
if($a) then if ($b) then $c else () else () |
if($a) { if($b) { $c } else { $d } } |
if($a) then if ($b) then $c else $d else () |
if($a) { if($b) { $c } } else { $e } |
if($a) then if ($b) then $c else () else $e |
if($a) { if($b) { $c } else { $d } } else { $e } |
if($a) then if ($b) then $c else $d else $e |
In addition, we should allow if($a) { $b } else if($c) { $d } else { $e } |
Thanks, @michaelhkay, for adding In my second comment, I proposed to also support if($a) { $b }
else if($c) { $d }
else if($e) { $f } The grammar rules for
Without the extended grammar, we would need to use additional curly braces: if($a) {
$b
} else {
if($c) {
$d
} else {
if($e) {
$f
}
}
} |
i like elsif or elif but i think there's probably no ambiguity (neither for humans nor for the parser) with else if, so sounds OK here. |
Of all the languages I've used, I much preferred Algol68's |
As regards the grammar, we tend to prefer iteration over recursion. So perhaps
|
+1 for the iterative variant of the grammar. The year 1968 is something I wasn't blessed to experience personally, but when I read |
Accepted at meeting 018 |
As discussed in issue #234. In reviewing this PR, I suggest we consider it together with the existing proposals for ternary conditionals (x ?? y !! z) and the "otherwise" operator.