2

I'm trying to make an esolang for fun, and I'm running into some problems with the parser. However, I keep getting the error

ParserGeneratorWarning 4 shift/reduce conflicts

in my parser.py file.

I'm not quite sure what to do, as I'm fairly new to this area of programming.


    def get_parser(self):
        return self.pg.build()

What should happen is that a separate input file should run the command print(4 + 4 - 2); which should output to 6, but I just get the error

ParserGeneratorWarning 4 shift/reduce conflicts return self.pg.build()

vezunchik
  • 3,669
  • 3
  • 16
  • 25

1 Answers1

2

The root cause is that your grammar is functionally ambiguous. There are four decision points in the grammar at which the parser cannot determine whether to

  • reduce a rule's RHS (right-hand side) phrase to a non-terminal symbol
  • use the most recent symbol to extend the RHS of another rule.

For instance, you may have rules

TERM => constant
TERM => constant + constant
EXPR => TERM + TERM

When the parser sees 4 with a look-ahead character of +, it doesn't know whether to reduce the constant immediately to a TERM (and use the + for making an EXPR), or to hold it for a longer TERM, per the second rule.

Since you failed to post the problematic portion of the grammar, we can't fix your specific problem. However, looking up shift-reduce errors will help you learn the disambiguation techniques. Try here and here for starters.

Prune
  • 76,765
  • 14
  • 60
  • 81