Skip to content

feat: add multiply (*) operator#339

Merged
scarmuega merged 1 commit into
mainfrom
feat/multiply-operator
Jun 10, 2026
Merged

feat: add multiply (*) operator#339
scarmuega merged 1 commit into
mainfrom
feat/multiply-operator

Conversation

@scarmuega

Copy link
Copy Markdown
Contributor

Summary

Adds the multiply (*) operator to the Tx3 data-expression language.

  • Grammar (tx3.pest): data_mul token added to data_infix. Disambiguated from the input* block flag by grammatical context.
  • AST: new MulOp node and DataExpr::MulOp variant.
  • Parsing: mul_op_parse plus a dedicated Pratt precedence level — * binds tighter than +/-, looser than prefix !, left-associative.
  • Analysis / lowering: lowers to tx3-tir's BuiltInOp::Mul.
  • Spec (v1beta0): updated lexical structure (§3.7), syntactic grammar + precedence table (§4.4/§4.5), and the type system (§5.5.1).

Semantics: Int * Int (product), AnyAsset * Int and Int * AnyAsset (scale asset quantities). AnyAsset * AnyAsset is undefined.

Tests

Parser tests for the basic form and precedence (2 + 3 * 42 + (3*4); 3 * 4 + 2(3*4) + 2). Full suite green (171 + 4 doc-tests). Verified end-to-end through tx3c build --emit tir-json: quantity * 2 + 445 lowers to Add[Mul[quantity, 2], 445].

Depends on

tx3-lang/tir#1 (BuiltInOp::Mul). Bump the tx3-tir dependency to the release that includes it before merging.

🤖 Generated with Claude Code

Introduce `*` as an infix data-expression operator that binds tighter
than `+`/`-` and looser than prefix `!`, left-associative.

- Grammar: `data_mul` token in `data_infix`
- AST: `MulOp` node + `DataExpr::MulOp`
- Parsing: `mul_op_parse` and a dedicated Pratt precedence level
- Analysis and lowering to `tx3-tir`'s `BuiltInOp::Mul`
- Spec (v1beta0): lexical, grammar, and type-system updates

Semantics: `Int * Int`, plus `AnyAsset * Int` / `Int * AnyAsset`
asset-quantity scaling.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant