Skip to content

add: Variables and Logic#1

Merged
ThePat02 merged 3 commits intomasterfrom
feat/logic
Jun 20, 2025
Merged

add: Variables and Logic#1
ThePat02 merged 3 commits intomasterfrom
feat/logic

Conversation

@ThePat02
Copy link
Copy Markdown
Owner

This pull request introduces significant enhancements to the quill language and its interpreter, including support for variable declarations, assignments, conditional statements, and more robust expression handling. Additionally, it introduces a new example script showcasing these features. The changes span across the Abstract Syntax Tree (AST), interpreter logic, and the example script.

Language Features and Syntax Enhancements:

  1. Expanded AST Support:

    • Added new expression types (BooleanLiteral, IntegerLiteral, InfixExpression, PrefixExpression, InterpolatedString) and statement types (LetStatement, AssignStatement, IfStatement) to support variable declarations, assignments, and conditional logic. ([[1]](https://github.com/ThePat02/quill/pull/1/files#diff-21a96fe9ac8432a6a8ab1a6270893e2f84419b176e4889bd8696b1720329b82aR50-R155), [[2]](https://github.com/ThePat02/quill/pull/1/files#diff-435c5aebaadc51c284cea54190e5ffa0de06a65190c20f0cf71db8f9077d672aL100-R249))
    • Enhanced existing AST node DialogStatement to support expressions for text, enabling interpolation and dynamic content. ([internal/ast/statements.goL31-R74](https://github.com/ThePat02/quill/pull/1/files#diff-435c5aebaadc51c284cea54190e5ffa0de06a65190c20f0cf71db8f9077d672aL31-R74))
  2. Interpreter Updates:

    • Implemented execution logic for new statement types (LetStatement, AssignStatement, IfStatement) and expanded expression evaluation to handle interpolation, infix, and prefix operations. ([[1]](https://github.com/ThePat02/quill/pull/1/files#diff-584e5570407b02964ad571ea8ac4603bc6fdabbbcec9bb12734a3dac2909e748R97-L119), [[2]](https://github.com/ThePat02/quill/pull/1/files#diff-584e5570407b02964ad571ea8ac4603bc6fdabbbcec9bb12734a3dac2909e748R134-R232), [[3]](https://github.com/ThePat02/quill/pull/1/files#diff-584e5570407b02964ad571ea8ac4603bc6fdabbbcec9bb12734a3dac2909e748R530-R737))
    • Added variable storage and management (variables map) to track declared variables and their values during execution. ([[1]](https://github.com/ThePat02/quill/pull/1/files#diff-584e5570407b02964ad571ea8ac4603bc6fdabbbcec9bb12734a3dac2909e748R58), [[2]](https://github.com/ThePat02/quill/pull/1/files#diff-584e5570407b02964ad571ea8ac4603bc6fdabbbcec9bb12734a3dac2909e748R80))

Example Script:

  1. New Example Script (examples/shop.q):
    • Introduced a shop simulation demonstrating variable handling, conditional logic, and dynamic text interpolation. The script includes features like purchasing items, checking wallet balance, and handling insufficient funds. ([examples/shop.qR1-R54](https://github.com/ThePat02/quill/pull/1/files#diff-599f96a6d1ef22cc0874f9fdd977700f047a90f04bcce49489db87acaa93d1c6R1-R54))

Code Robustness:

  1. Improved String Representations:

    • Enhanced String() methods across AST nodes to handle nil cases gracefully, ensuring robust debugging and error handling. ([[1]](https://github.com/ThePat02/quill/pull/1/files#diff-21a96fe9ac8432a6a8ab1a6270893e2f84419b176e4889bd8696b1720329b82aR12-R14), [[2]](https://github.com/ThePat02/quill/pull/1/files#diff-21a96fe9ac8432a6a8ab1a6270893e2f84419b176e4889bd8696b1720329b82aR25-R27), [[3]](https://github.com/ThePat02/quill/pull/1/files#diff-21a96fe9ac8432a6a8ab1a6270893e2f84419b176e4889bd8696b1720329b82aR38-R40), [[4]](https://github.com/ThePat02/quill/pull/1/files#diff-644fc1ed5ebae9c40e2542a3450a224634d7e413997e9ebad135a02aad1c0fd6R22-R30), [[5]](https://github.com/ThePat02/quill/pull/1/files#diff-435c5aebaadc51c284cea54190e5ffa0de06a65190c20f0cf71db8f9077d672aL12-R19), [[6]](https://github.com/ThePat02/quill/pull/1/files#diff-435c5aebaadc51c284cea54190e5ffa0de06a65190c20f0cf71db8f9077d672aL22-R36), [[7]](https://github.com/ThePat02/quill/pull/1/files#diff-435c5aebaadc51c284cea54190e5ffa0de06a65190c20f0cf71db8f9077d672aL58-R117))
  2. Error Handling:

    • Added detailed error reporting for undefined variables, invalid operations, and unsupported expression types in the interpreter. ([[1]](https://github.com/ThePat02/quill/pull/1/files#diff-584e5570407b02964ad571ea8ac4603bc6fdabbbcec9bb12734a3dac2909e748R134-R232), [[2]](https://github.com/ThePat02/quill/pull/1/files#diff-584e5570407b02964ad571ea8ac4603bc6fdabbbcec9bb12734a3dac2909e748R530-R737))

These changes collectively enhance the language's capabilities, making it more expressive and suitable for complex interactive narratives. The example script serves as a practical demonstration of these new features.

@ThePat02 ThePat02 requested a review from Copilot June 20, 2025 09:15
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 enriches the Quill language with variable declarations, assignments, conditional logic, and enhanced interpolation, alongside a demonstration script.

  • Expanded AST with LetStatement, AssignStatement, IfStatement, Boolean/Integer literals, infix/prefix expressions, and updated String() methods to guard against nil.
  • Updated tokenizer and scanner to recognize new operators (+=, >=, &&, etc.) and keywords (LET, IF, ELSE, TRUE, FALSE).
  • Enhanced interpreter to store variables, execute new statements, evaluate complex expressions, and report detailed errors; added examples/shop.q to showcase features.

Reviewed Changes

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

Show a summary per file
File Description
internal/token/types.go Added new operator tokens and variable keywords; updated comments
internal/scanner/scanner.go Extended scanning logic for multi-character operators
internal/interpreter/interpreter.go Introduced variable storage and execution for let/assign/if; expression evaluator updates
internal/ast/statements.go Added AST nodes and String() guards for new statements
internal/ast/node.go Added nil check in Program.String()
internal/ast/expressions.go Added AST nodes and guards for new literals/expressions
examples/shop.q New example script demonstrating variables and logic

@ThePat02 ThePat02 merged commit d56b49e into master Jun 20, 2025
1 check passed
@ThePat02 ThePat02 deleted the feat/logic branch June 20, 2025 09: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