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

Method __get_array_val

PyBasic/basicparser.py:1089–1117  ·  view source on GitHub ↗

Extracts the value from the given BASICArray at the specified indexes :param BASICarray: The BASICArray :param indexvars: The list of indexes, one for each dimension :return: The value at the indexed position in the array

(self, BASICarray, indexvars)

Source from the content-addressed store, hash-verified

1087 self.__token.lexeme+ ') in line ' + str(self.__line_number))
1088
1089 def __get_array_val(self, BASICarray, indexvars):
1090 """Extracts the value from the given BASICArray at the specified indexes
1091
1092 :param BASICarray: The BASICArray
1093 :param indexvars: The list of indexes, one for each dimension
1094
1095 :return: The value at the indexed position in the array
1096
1097 """
1098 if BASICarray.dims != len(indexvars):
1099 raise IndexError('Incorrect number of indices applied to array ' +
1100 'in line ' + str(self.__line_number))
1101
1102 # Fetch the value from the array
1103 try:
1104 if len(indexvars) == 1:
1105 arrayval = BASICarray.data[indexvars[0]-1]
1106
1107 elif len(indexvars) == 2:
1108 arrayval = BASICarray.data[indexvars[0]-1][indexvars[1]-1]
1109
1110 elif len(indexvars) == 3:
1111 arrayval = BASICarray.data[indexvars[0]-1][indexvars[1]-1][indexvars[2]-1]
1112
1113 except IndexError:
1114 raise IndexError('Array index out of range in line ' +
1115 str(self.__line_number))
1116
1117 return arrayval
1118
1119 def __compoundstmt(self):
1120 """Parses compound statements,

Callers 1

__factorMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected