[J3] Question about the conditional expression syntax in 21-157r2

Thomas König tk at tkoenig.net
Wed Jun 30 21:49:32 UTC 2021


Hi,

> So IMO,
> 
>     special parens = best
>     ordinary parens = acceptable 
>     no parens = unacceptable

If I may make a suggestion...

One possibility would be to prohibit a cond-expr as part of a cond-expr.

So,

   cond1 ? (cond2 ? expr : expr2) : expr3

would be permitted, but

   cond ? cond2 ? expr : expr2 : expr3

or nested conditions would not be.

It would probably be necessary to add an extra level of expressions to
the syntax rules for this, something like

defined-binary-op-expr is [ defined-binary-op-expr defined-binary-op ] 
level-5-expr

...

cond-expr is defined-binary-op-expr ? defined-binary-op-expr : 
defined-binary-op-expr

expr is cond-expr or defined-binary-op-expr

(I think this grammar would be unambiguous, I hope I'm right).

Best regards

	Thomas


More information about the J3 mailing list