MCPcopy Create free account
hub / github.com/RetiredWizard/PyDOS / BASICArray

Class BASICArray

PyBasic/basicparser.py:62–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

60
61"""
62class BASICArray:
63
64 def __init__(self, dimensions):
65 """Initialises the object with the specified
66 number of dimensions. Maximum number of
67 dimensions is three
68
69 :param dimensions: List of array dimensions and their
70 corresponding sizes
71
72 """
73 self.dims = min(3,len(dimensions))
74
75 if self.dims == 0:
76 raise SyntaxError("Zero dimensional array specified")
77
78 # Check for invalid sizes and ensure int
79 for i in range(self.dims):
80 if dimensions[i] < 0:
81 raise SyntaxError("Negative array size specified")
82 # Allow sizes like 1.0f, but not 1.1f
83 if int(dimensions[i]) != dimensions[i]:
84 raise SyntaxError("Fractional array size specified")
85 dimensions[i] = int(dimensions[i])
86
87 if self.dims == 1:
88 self.data = [None for x in range(dimensions[0])]
89 elif self.dims == 2:
90 self.data = [[None for x in range(dimensions[1])] for x in range(dimensions[0])]
91 else:
92 self.data = [[[None for x in range(dimensions[2])] for x in range(dimensions[1])] for x in range(dimensions[0])]
93
94# def pretty_print(self):
95# print(str(self.data))

Callers 1

__dimstmtMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected