You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+82-2Lines changed: 82 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,19 @@ $ python interpreter.py
27
27
28
28
Although this started of as a personal project, it has been enhanced considerably by some other Github users. You can see them in the list of contributors! It's very much a group endeavour now.
29
29
30
+
## Recent Updates
31
+
32
+
### Array INPUT and READ Support
33
+
The interpreter now supports reading data directly into array elements using both **INPUT** and **READ** statements:
34
+
35
+
-**Array Elements as Targets**: Use syntax like `INPUT A(1), B(I+2)` and `READ N$(1), N$(2)`
36
+
-**Expression Indices**: Support for complex expressions in array indices like `A(I*2+1)`
37
+
-**Mixed Data Types**: Read numeric and string data into appropriate array types
38
+
-**Error Handling**: Proper SUBSCRIPT ERROR and OUT OF DATA error messages
39
+
-**Specification Compliant**: Follows classic BASIC behavior for all edge cases
40
+
41
+
See the comprehensive test program `examples/array_input_read_tests.bas` for demonstrations of all functionality.
42
+
30
43
## Operators
31
44
32
45
A limited range of arithmetic expressions are provided. Addition and subtraction have the lowest precedence,
@@ -311,8 +324,38 @@ Hello Another Line of Data
311
324
>
312
325
```
313
326
314
-
It is a limitation of this BASIC dialect that it is not possible to assign constants directly to array variables
315
-
within a **READ** statement, only simple variables.
327
+
#### Array Support in READ
328
+
329
+
The **READ** statement now supports reading data directly into array elements, using expressions for array indices:
330
+
331
+
```
332
+
> 10 DIM A(5)
333
+
> 20 DIM N$(3)
334
+
> 30 DATA 10, 20, 30, "Hello", "World"
335
+
> 40 READ A(1), A(2), A(3), N$(1), N$(2)
336
+
> 50 PRINT A(1); A(2); A(3); N$(1); N$(2)
337
+
> RUN
338
+
102030HelloWorld
339
+
>
340
+
```
341
+
342
+
Array indices can be complex expressions including variables and arithmetic:
343
+
344
+
```
345
+
> 10 DIM B(10)
346
+
> 20 I = 2
347
+
> 30 DATA 100, 200
348
+
> 40 READ B(I*3), B(I+4)
349
+
> 50 PRINT "B(6)="; B(6) REM Shows 200 (second value overwrites first)
350
+
> RUN
351
+
B(6)=200
352
+
>
353
+
```
354
+
355
+
Proper error handling is provided:
356
+
-**SUBSCRIPT ERROR**: When array indices are out of bounds or negative
357
+
-**OUT OF DATA**: When there are no more DATA items to read
358
+
- Index validation occurs BEFORE consuming DATA items
The **INPUT** statement now supports inputting data directly into array elements:
769
+
770
+
```
771
+
> 10 DIM A(3)
772
+
> 20 DIM N$(2)
773
+
> 30 INPUT "Enter 3 numbers: "; A(1), A(2), A(3)
774
+
> 40 INPUT "Enter 2 names: "; N$(1), N$(2)
775
+
> 50 PRINT A(1); A(2); A(3); N$(1); N$(2)
776
+
> RUN
777
+
Enter 3 numbers: 5, 10, 15
778
+
Enter 2 names: Alice, Bob
779
+
51015AliceBob
780
+
>
781
+
```
782
+
783
+
Array indices can use expressions with variables:
784
+
785
+
```
786
+
> 10 DIM B(10)
787
+
> 20 I = 5
788
+
> 30 INPUT "Enter value for B(I): "; B(I)
789
+
> 40 PRINT "B(5)="; B(5)
790
+
> RUN
791
+
Enter value for B(I): 42
792
+
B(5)=42
793
+
>
794
+
```
795
+
796
+
Error handling includes:
797
+
-**SUBSCRIPT ERROR**: When array indices are out of bounds
798
+
-**"? REDO FROM START"**: When input types don't match array types
799
+
- Index validation occurs BEFORE prompting for input
800
+
723
801
A mismatch between the input value and input variable type will trigger an error, and the user will be asked
724
802
to re-input the values again.
725
803
@@ -927,6 +1005,8 @@ and expanded by Don Woods.
927
1005
928
1006
**Pneuma.bas* - A brief 21st century take on the venerable text adventure.
929
1007
1008
+
**array_input_read_tests.bas* - A comprehensive test program that validates array INPUT and READ functionality, including expression indices, boundary conditions, error handling, and mixed data types. Demonstrates all the features of array element input and data reading.
1009
+
930
1010
## Informal grammar definition
931
1011
932
1012
**ABS**(*numerical-expression*) - Calculates the absolute value of the result of *numerical-expression*
0 commit comments