Skip to content

feat(lang): add if/else control flow (V2 Tier 2b)#12

Merged
particlesector merged 1 commit into
mainfrom
feat/lang-if-else
Apr 22, 2026
Merged

feat(lang): add if/else control flow (V2 Tier 2b)#12
particlesector merged 1 commit into
mainfrom
feat/lang-if-else

Conversation

@particlesector
Copy link
Copy Markdown
Owner

Enables conditional geometry in SCAD scripts:

show = 1;
if (show) sphere(r = 5); else cube([4,4,4]);
if (r > 10) { sphere(r=r); cylinder(h=r, r=2); }

Changes:

  • Token.h: If, Else token kinds
  • Lexer.cpp: "if", "else" keywords
  • AST.h: IfNode (condition ExprPtr, thenChildren, elseChildren); added to AstNode variant with makeIf() helper
  • Parser.h/cpp: parseIf() — condition expression, then/else via parseBody(); chained else-if works naturally since if is a node
  • CsgEvaluator.h/cpp: evalIf() — evaluates condition via Interpreter, walks live branch, wraps multi-child results in a union (same pattern as transform); inherits outer xform
  • Tests: 14 new tests across lexer, parser, and CSG evaluator (108 total, 631 assertions)
  • tests/if_else_test.scad: 6 visual scenes

Enables conditional geometry in SCAD scripts:

  show = 1;
  if (show) sphere(r = 5); else cube([4,4,4]);
  if (r > 10) { sphere(r=r); cylinder(h=r, r=2); }

Changes:
- Token.h: If, Else token kinds
- Lexer.cpp: "if", "else" keywords
- AST.h: IfNode (condition ExprPtr, thenChildren, elseChildren);
  added to AstNode variant with makeIf() helper
- Parser.h/cpp: parseIf() — condition expression, then/else via
  parseBody(); chained else-if works naturally since if is a node
- CsgEvaluator.h/cpp: evalIf() — evaluates condition via
  Interpreter, walks live branch, wraps multi-child results in
  a union (same pattern as transform); inherits outer xform
- Tests: 14 new tests across lexer, parser, and CSG evaluator
  (108 total, 631 assertions)
- tests/if_else_test.scad: 6 visual scenes

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@particlesector particlesector merged commit a12b246 into main Apr 22, 2026
4 checks passed
@particlesector particlesector deleted the feat/lang-if-else branch April 22, 2026 05:18
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.

2 participants