How it works...

In the first half of this recipe, we walked through the steps to define the grammar, compile time, and runtime semantics, associativity and precedence of the new switch expression/operator. In the second half, we defined the new syntax kinds and syntax node in the compiler.

The grammar, associativity, and precedence for the new switch expression is identical to the grammar for the existing conditional ternary expression.

As both the ternary operators come just after the null coalescing operator (??) in the precedence order, the grammar specifies:

switch-expression: null-coalescing-expression null-coalescing-expression ?: bracketed-argument-list : bracketed-argument-list

The grammar specifies the labels and the values for ...

Get Roslyn Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.