Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This Pull Request contains the necessary changes for the implementation of the dictionary data type. Dictionaries are data structures that allow storing key-value pairs, where each key is unique and associated with a specific value.
-> Group Members:
Gabriel Xisto Barros: 211055503
Enzzo Morais de Olinda: 211042720
Davi Mansur Costa: 211042701
-> Main Contributions:
Added support for:
Dictionary expressions.
Example:
dict = { x: 10, y: 20 }
Dictionary key access.
Example:
dict.x
Dictionary key assignment.
Example:
dict.x = 15
Dictionary delete key statement.
Example:
del dict.x
Dictionary merge expression. The merge expression creates a new dictionary that combines the fields of the first dictionary with those of the second, overwriting duplicate key values.
Example:
new_dict = dict with { z = 15 }
Membership operators
in
andnot in
for dictionaries.Example:
x in dict
,x not in dict
To implement these features, modifications were made to the interpreter, type checker, AST, and parser modules. The implementation was validated through 25 tests.
-> Limitations/Issues:
Only identifiers can be used as dictionary keys. It is not possible to use strings, integers, or other types as keys directly.
Example:
dict = { "key": 10, 42: 20 }
-> Error. Only identifiers are allowed as keys.Dictionary expressions can include duplicate keys, which may lead to unexpected behavior.
Example:
dict = { x: 10, x: 20 }
Key access and assignment can only be performed on variables. It is not possible to access or modify keys from an expression that returns a dictionary.
Examples that are NOT allowed:
dict.key.key2
-> Even ifdict.key
returns a valid dictionary, chained access is not allowed.fun().key
-> Even if the function returns a dictionary, its keys cannot be accessed directly.{ x: 10 }.x
-> Dictionary expressions cannot be accessed directly.It is not possible to add a key directly to an existing dictionary. The only way to add a key is through the
with
operator, but this creates a new dictionary without modifying the original.