Skip to content

Commit 3e648a1

Browse files
author
aafent
committed
Fixes to [] notation
1 parent 67ffb9e commit 3e648a1

File tree

5 files changed

+35
-25
lines changed

5 files changed

+35
-25
lines changed

FAST.FBasic.InteractiveConsole/Tests/array.bas

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,19 @@ REM
55
coldim arr1, c1, c2
66
let [arr1.c1(1)] = "xxx"
77

8-
INDEXDELETE arr1,1
9-
print [arr1.c1(1)]
10-
118
coldim a1, c1, c2, c3 ' define array a1 with 3 columns
129
coladd a1, c4 ' add one column
1310

1411
let [a1.c4(2)] = "XXX"
15-
let index=1
16-
print "#5.C4=";
12+
let index=2
13+
print "#2.C4=";
1714
print [a1.c4(index)]
1815

1916
print "#2.C4=";
2017
print [a1.c4(2)]
2118

2219
print "Array length=";
23-
print count("a1")
20+
print ubound("a1")
2421

2522
print "#2 Column=";
2623
'print colname("a1",2)
@@ -29,16 +26,4 @@ print cname("a1",2)
2926
print "Number of columns=";
3027
print cnamescount("a1")
3128

32-
Halt
33-
34-
35-
'// Statements:
36-
'// JADIM name, [ColumnName1], [ColumnName2], ..., [ColumnNameN]
37-
'// COLNAME array_name, column_number, column_name
38-
'// ADDCOL array_name, column_name
39-
'// ASET array_name, column_name, value
40-
'//
41-
'// Functions:
42-
'// count(array_name)
43-
4429
Halt

FAST.FBasic.InteractiveConsole/Tests/wordFreq.bas

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
REM Test program for CALL and GOTO statements
22
REM
33
REM
4-
54
text="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
65
eiusmod tempor incididunt ut labore et dolore magna aliqua.
76
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip
@@ -15,17 +14,14 @@ let minWordLength=2
1514
let minCount=2
1615
WORDFREQ words, text, minWordLength, minCount
1716

18-
COLNAME words, 1, "a"
19-
COLNAME words, 2, "b"
20-
2117
let cnt=ubound("words")
2218
print "Words found: "+cnt
2319

2420
for i=1 To cnt
2521
print "Word: ";
26-
print [words.a(i)];
22+
print [words.1(i)];
2723
print " : ";
28-
print [words.b(i)]
24+
print [words.2(i)]
2925
next i
3026

3127
halt

FAST.FBasicInterpreter/Core/IdentifierNotationParser.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,29 @@ public class IdentifierNotationParser
4949
/// </summary>
5050
public string DataElement { get; private set; } = null;
5151

52+
/// <summary>
53+
/// Data element number, convert to number the data element
54+
/// </summary>
55+
public int DataElementAsNumber
56+
{
57+
get
58+
{
59+
return int.Parse(this.DataElement);
60+
}
61+
}
62+
63+
/// <summary>
64+
/// Check if the data element is a numeric value
65+
/// </summary>
66+
public bool IsDataElementNumeric
67+
{
68+
get
69+
{
70+
if (string.IsNullOrEmpty(this.DataElement)) return false;
71+
return int.TryParse(this.DataElement, out _);
72+
}
73+
}
74+
5275
/// <summary>
5376
/// The function name if the expression is a function name
5477
/// </summary>

FAST.FBasicInterpreter/Core/Interpreter_Elements.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,11 @@ public Value GetIdentifierOrCF(bool permitIdentifier = true,
151151
var parser = new IdentifierNotationParser(lex.Identifier, this);
152152
if (parser.IsArray)
153153
{
154-
return this.GetArray(parser.DataContainerName)[parser.ArrayIndex, parser.DataElement];
154+
return parser.IsDataElementNumeric?
155+
this.GetArray(parser.DataContainerName)[parser.ArrayIndex-1, parser.DataElementAsNumber-1] // 0-base reference
156+
:
157+
this.GetArray(parser.DataContainerName)[parser.ArrayIndex, parser.DataElement] // 1-base reference
158+
;
155159
}
156160
else if (parser.IsCollection)
157161
{

FAST.FBasicInterpreter/Execution/executionResult.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,7 @@ public class ExecutionResult
5353
/// The dictionary key is the variable name and the value is the variable Value
5454
/// </summary>
5555
public Dictionary<string, Value> variables { get; set; } = null;
56+
57+
5658
}
5759
}

0 commit comments

Comments
 (0)