Skip to content

[cli] Add ans variable + variable assignment and evaluation#206

Merged
forfudan merged 3 commits intodevfrom
repl
Apr 14, 2026
Merged

[cli] Add ans variable + variable assignment and evaluation#206
forfudan merged 3 commits intodevfrom
repl

Conversation

@forfudan
Copy link
Copy Markdown
Owner

@forfudan forfudan commented Apr 13, 2026

This PR adds end-to-end variable support to the Decimo CLI calculator (tokenization → parsing → evaluation) and wires it into the interactive REPL with ans and name = expr assignment, plus corresponding tests and docs updates.

Changes:

  • Introduce TOKEN_VARIABLE and extend the tokenizer/parser/evaluator pipeline to handle variable references.
  • Add REPL variable store with ans tracking and name = expr assignment support (with reserved-name validation).
  • Add tests for variable tokenization and evaluation; update planning/docs and decimo exports (Integer alias).

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds end-to-end variable support to the Decimo CLI calculator (tokenization → parsing → evaluation) and wires it into the interactive REPL with ans and name = expr assignment, plus corresponding tests and docs updates.

Changes:

  • Introduce TOKEN_VARIABLE and extend the tokenizer/parser/evaluator pipeline to handle variable references.
  • Add REPL variable store with ans tracking and name = expr assignment support (with reserved-name validation).
  • Add tests for variable tokenization and evaluation; update planning/docs and decimo exports (Integer alias).

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
tests/cli/test_tokenizer.mojo Adds tokenizer tests for variable tokens and precedence vs funcs/constants.
tests/cli/test_evaluator.mojo Adds evaluator tests for variable resolution (including ans) and undefined-variable errors.
src/decimo/prelude.mojo Re-exports Integer from bigint in the prelude.
src/decimo/bigint/bigint.mojo Adds comptime Integer = BigInt alias.
src/decimo/init.mojo Exports Integer at the package root.
src/cli/calculator/tokenizer.mojo Adds TOKEN_VARIABLE and optional known-variable handling during identifier lexing.
src/cli/calculator/repl.mojo Implements REPL variable store, assignment parsing, reserved-name validation, and updates banner.
src/cli/calculator/parser.mojo Treats TOKEN_VARIABLE like numbers/constants in shunting-yard output.
src/cli/calculator/evaluator.mojo Resolves TOKEN_VARIABLE via a provided Dict[String, Decimal] and raises on undefined vars.
src/cli/calculator/engine.mojo Threads variable names into tokenization and passes variable dict into evaluation; adds evaluate_and_return.
src/cli/calculator/init.mojo Exports TOKEN_VARIABLE and evaluate_and_return.
docs/todo.md Adds a TODO note about potentially flipping Decimal/BigDecimal naming.
docs/plans/cli_calculator.md Marks Phase 4 variable features as complete and extends the plan table.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@forfudan forfudan merged commit 970cc43 into dev Apr 14, 2026
11 checks passed
@forfudan forfudan deleted the repl branch April 14, 2026 06:14
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