Shift reduces and reduces reduction conflicts

It’s not easy for me to wrap my head around this, and you need help understanding the shift and reducing conflicts. I have a grammar that I cannot understand why this is problematic. I could attach a grammar, but I want to find out how it works.

The first question is, what type of parser does MGrammer create? As far as I understand, the shift reduction and reduction of reduction conflicts depends on the type of parser.

The second question, what does reduction mean, reduces conflict, and what does shift mean that reduces conflict?

I know the basics of lexical analysis and formal grammar, but some time has passed since I worked with language design, so any help here is very appropriate.

Update:

I work with a significant language with spaces, and I wonder how it can be done in MGrammar, do I need to take a look to solve the ambiguities?

+6
shift-reduce-conflict mgrammar oslo
source share
1 answer

A simple example:

if cond if cond2 cmd else cmd2 

Question: Where else belongs? For the human eye, indentation says "to the second if ", but it does not mean anything for the computer (except when using Python ;)). This is a shift / decrease conflict .

An elegant solution is to treat the else as the left-binding operator with the highest priority (which makes it β€œhang” with the closest if ).

A reduce / reduce conflict is an ambiguity. I don't have a good example, but that means there are ways in the grammar where one token can lead to a reduction of the two rules at the same time, and there is no additional information to decide which rule should take precedence.

[EDIT] Bison documents have an example to reduce / decrease .

+10
source share

All Articles