Skip to content

Error running your example on python3 #2

Open

Description

@ibreakoutx

python main.py

PythonCompiler/parser.py:41: ParserGeneratorWarning: 4 shift/reduce conflicts
return self.pg.build()

Did you come across a similar error

Activity

  1. marcelogdeandrade commented on Feb 20, 2019

    @marcelogdeandrade
    Owner

    Sadly I didn't come across this error. Can you please give more information about this issue? Your system specs and what version of each lib are you using?

    Thank you for reporting it 😊

  2. NoahGWood commented on Feb 22, 2019

    @NoahGWood

    The warnings are coming up because you forgot to pass a list of precedents to your ParserGenerator

    Easy enough fix, just update your Parser class to reflect this:
    pg = ParserGenerator( # A list of all token names, accepted by the parser. ['NUMBER', 'OPEN_PARENS', 'CLOSE_PARENS', 'PLUS', 'MINUS', 'MUL', 'DIV' ], # A list of precedence rules with ascending precedence, to # disambiguate ambiguous production rules. precedence=[ ('left', ['PLUS', 'MINUS']), ('left', ['MUL', 'DIV']) ] )
    code from https://rply.readthedocs.io/en/latest/users-guide/parsers.html

  3. marcelogdeandrade commented on Feb 27, 2019

    @marcelogdeandrade
    Owner

    Oh, I didn't use precedents because I chose to do a more theoretical approach, solving this issue in the EBNF. I'll look into it to solve this warning.

    Thanks for the help

  4. haferburg commented on Oct 27, 2019

    @haferburg

    The grammar you used in the article doesn't solve this problem, though. You'd have to use different productions for different operators. If you want to combine them like you did, you do have to provide a precedence list, and the generator will handle splitting up the productions for you.

    Here's what fixes the issue for the code in the article.

        self.pg = ParserGenerator(
            # A list of all token names accepted by the parser.
            [
                "NUMBER",
                "PRINT",
                "OPEN_PAREN",
                "CLOSE_PAREN",
                "SEMI_COLON",
                "SUM",
                "SUB",
            ],
            precedence=[("left", ["SUM", "SUB"])],
        )
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions