Skip to content

Grupo 06 - Dicionários #34

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

enzzoMs
Copy link

@enzzoMs enzzoMs commented Feb 21, 2025

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 and not 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 if dict.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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants