Skip to content

Spec #38.1: Implement OPTION BASE statement #56

Description

@treytomes

Description

Parse and store array base index (0 or 1) per ECMA-55 specification.

OPTION BASE sets the lower bound for all array subscripts. Must be called before any arrays are allocated.

ECMA-55 References

  • ECMA55-ARR-001: OPTION BASE 0 or OPTION BASE 1
  • ECMA55-ARR-002: Must appear before any DIM statements

Acceptance Criteria

  • Parse valid OPTION BASE 0 and OPTION BASE 1 statements
  • Reject invalid values (OPTION BASE 2, -1, etc.)
  • Reject multiple OPTION BASE statements
  • Default to BASE 0 if not specified
  • Error if OPTION BASE after array allocation
  • All tests pass
  • Test coverage ≥ 80%

Tests to Write First

// Valid cases
OPTION BASE 0 → sets base to 0
OPTION BASE 1 → sets base to 1

// Invalid cases
OPTION BASE 2 → syntax error
OPTION BASE -1 → syntax error
OPTION BASE 0, then OPTION BASE 1 → error (duplicate)

// Default behavior
No OPTION BASE → defaults to 0

// Timing error
DIM A(10), then OPTION BASE 1 → error (too late)

Implementation Tasks

  • Create OptionBaseStatementParser.cs
  • Add ArrayBase property to IEnvironment
  • Add validation for BASE value (0 or 1 only)
  • Track whether BASE has been set
  • Validate BASE not changed after array allocation

Files Affected

  • src/ECMABasic.Domain/IEnvironment.cs
  • src/ECMABasic.Application/Parsers/OptionBaseStatementParser.cs
  • src/ECMABasic.Application/EnvironmentBase.cs
  • test/ECMABasic.Test/OptionBaseStatementTests.cs

Parent Issue

Part of #38 - Implement DIM and OPTION BASE for array support

Estimated Effort

2-3 hours

Dependencies

None - this is the foundation for array support

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ecma-55ECMA-55 Minimal BASIC specification complianceenhancementNew feature or request

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions