michaeljabbour / michaeljabbour/altairbasic

Add I/O Operations for Files

Open
#6 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
1
Forks
0
PR merge metrics
No merged PRs in 30d

Description

# Add I/O Operations for Files

## Issue Description
The original ALTAIR BASIC had capabilities for file operations, but our implementation currently lacks commands for reading from and writing to files from within BASIC programs. Adding file I/O capabilities would enhance the interpreter's functionality and allow more complex programs.

## Features to Implement
1. **OPEN Statement**: Open a file for reading, writing, or both

2. **CLOSE Statement**: Close an open file

3. **INPUT# Statement**: Read data from an open file

4. **PRINT# Statement**: Write data to an open file

5. **EOF Function**: Test for end-of-file condition

## Technical Details
The implementation will require:
1. File handle management in the interpreter
2. Extension of the parser to recognize file I/O statements
3. Implementation of the corresponding operations in the interpreter
4. Error handling for file operations
5. Directory and path handling across platforms

## Security Considerations
- Limit file access to specific directories for security
- Handle permissions and error states properly
- Consider sandboxing file operations

## Compatibility Considerations
- Ensure behavior matches original ALTAIR BASIC where appropriate
- Handle platform-specific path differences (Windows vs Unix)
- Support both text and binary file modes

## Proposed Implementation Approach
1. Add file handle management to the environment
2. Create AST nodes for file operations
3. Implement the parser rules for the new statements
4. Add interpreter methods for file I/O
5. Create examples demonstrating file operations

## Priority
Medium - This adds important functionality but isn't needed for basic operation

## Related Components
- src/core/parser.cpp - For new syntax
- src/core/ast.h/cpp - For new AST nodes
- src/core/interpreter.cpp - For execution
- src/io/io_system.cpp - For actual file operations

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading src/core/parser.cpp, src/core/ast.h/cpp, src/core/interpreter.cpp, and src/io/io_system.cpp to map the existing syntax, AST, execution, and I/O layers. Define the file-handle, path, mode, permission, and platform behavior before implementing the OPEN, CLOSE, INPUT#, PRINT#, and EOF features. Done means the commands work with appropriate error handling and examples demonstrate file operations.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
cli
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.