#πŸ”’ Code not liking ")" in file

4 messages Β· Page 1 of 1 (latest)

tacit phoenix
#

So in a file, I have display("Hello, World!")
And my code does not line " the ) (yet it still runs).

When I remove it to display("Hello, World!" it runs with no issue.

parser/lexer/what ever its called

        if str(tokens[idx][1]).upper() == 'DISPLAY':
            if (idx + 2) < len(tokens) and tokens[idx + 1][0] == 'LPAREN' and tokens[idx + 2][0] == 'STRING_LITERAL':
                print(get_value(tokens[idx + 2]))
                idx += 3
            elif (idx + 2) < len(tokens) and tokens[idx + 1][0] == 'LPAREN' and tokens[idx + 2][0] == 'IDENTIFIER':
                if (idx + 3) < len(tokens) and tokens[idx + 3][0] == 'RPAREN':
                    value = get_value(tokens[idx + 2])
                    if value is not None:
                        print(value)
                    else:
                        raise UndefinedVariable("Undefined Variable: ", tokens[idx + 2][1])
                    idx += 4  # Skip the closing parenthesis
                else:
                    raise MismatchedParentheses("Mismatched Parentheses For Display Statement")
            else:
                raise InvalidStatement("Display statement Invalid")
hollow ginkgoBOT
#

@tacit phoenix

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hollow ginkgoBOT
#

@tacit phoenix

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.