Skip to content

feat(compiler): ternary conditional operator cond ? a : b (Wave 56, R-CG-5)#826

Open
gHashTag wants to merge 2 commits into
masterfrom
feat/wave-56/ternary-operator
Open

feat(compiler): ternary conditional operator cond ? a : b (Wave 56, R-CG-5)#826
gHashTag wants to merge 2 commits into
masterfrom
feat/wave-56/ternary-operator

Conversation

@gHashTag
Copy link
Copy Markdown
Owner

Closes #825

Wave 56 — R-CG-5: Ternary conditional operator cond ? a : b

What changed

  • TokenKind::Question + NodeKind::ExprTernary
  • ? added to lexer single-char scanner
  • Parser: right-associative, lowest expression precedence
  • Verilog/C/Zig: cond ? a : b
  • Rust: if cond { a } else { b }

Example

pub fn clamp(val: u8, lo: u8, hi: u8) -> u8 {
    return val < lo ? lo : (val > hi ? hi : val)
}

Test results

9 new tests. All pass.

claude added 2 commits May 24, 2026 13:31
…#823)

Wave 55 adds ExprConcat: {a, b, c} for Verilog bit concatenation.
- Verilog: emits {a, b, c} (native concatenation)
- C/Rust: emits /* concat(a, b, c) */ 0 (width-aware shift+or deferred)
- Parser distinguishes {expr, expr} from struct literal Name{field: val}
- Supports nested concatenation {{a, b}, c}

11 new tests (parse, Verilog, C, Rust, nested, assignment, literals).
All pass.
…oses #825)

Wave 56 adds ExprTernary: cond ? a : b for concise conditional expressions.
- Verilog/C/Zig: emit cond ? a : b (native ternary)
- Rust: emit if cond { a } else { b } (idiomatic)
- Right-associative: a ? x : b ? y : z parses correctly
- Works with comparisons: val < lo ? lo : val

9 new tests (parse, 4 backends, nested, assignment, comparison, right-assoc).
All pass.
This was referenced May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ternary conditional operator cond ? a : b (R-CG-5)

2 participants