Skip to content

Variable reassignment requires bhadwa (redeclaration) #3

Description

@Adityarya11

Problem:
The language has no mutation syntax separate from declaration. To update a variable you must write bhadwa count matlb count - 1 which is semantically a redeclaration, not a reassignment. This is incorrect behavior — redeclaring an already-defined variable should either error or at minimum be a separate syntax from first declaration.

Expected behavior:
A dedicated assignment syntax for mutation without bhadwa:

count matlb count - 1

Should update the existing variable in the current scope, not redeclare it.

Current behavior:
count matlb count - 1 without bhadwa produces a parse error because the parser only accepts matlb after bhadwa as an assignment. The token matlb is not handled as a standalone statement opener.

Fix required in:

  • src/parser/parser.ccparseStatement() needs to handle Identifier followed by Assign as a mutation statement
  • src/interpreter/evaluator.cc — needs a separate VarAssignStmt execution path that errors if the variable is not already defined
  • include/ast.h — new VarAssignStmt node separate from VarDeclStmt

Priority: Medium — affects loop patterns, making common programs unwritable without the workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions