Skip to content

Commit

Permalink
Bug Fix
Browse files Browse the repository at this point in the history
添加 Array Total Indexes Assign 功能
如:
a[1] <- [1, 2, 3, 4, 5]
  • Loading branch information
iewnfod committed Sep 21, 2023
1 parent cbeb585 commit 27c0aaa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/AST/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,5 +204,12 @@ def get_tree(self, level=0):
return LEVEL_STR * level + self.type + ' ' + str(self.id) + '\n' + self.indexes.get_tree(level+1) + '\n' + self.items.get_tree(level+1)

def exe(self):
indexes = self.indexes.exe()
items = self.items.exe()
keys = list(Array_get(self.id, self.indexes).exe()[0].keys())
if len(keys) == len(items):
for i in range(len(items)):
index = deepcopy(self.indexes)
index.add_index(Integer(keys[i]))
Array_assign(self.id, index, items[i]).exe()
else:
add_error_message(f'Cannot assign to `{self.id}` because they are not the same size', self)
1 change: 1 addition & 0 deletions src/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def p_array_total_assign_statement(p):

def p_array_index_total_assign_statement(p):
"""statement : ID LEFT_SQUARE indexes RIGHT_SQUARE ASSIGN LEFT_SQUARE array_items RIGHT_SQUARE"""
p[0] = AST.Array_indexes_total_assign(p[1], p[3], p[7])

def p_array_items(p):
"""array_items : array_items COMMA expression
Expand Down

0 comments on commit 27c0aaa

Please sign in to comment.