Resolution of the shift / decrease conflict in the LALR parser

I use PLY to create a parser for my language, however, I have a shift / reduction conflict that causes me some problems. My language has common types with the syntax ala C ++ templates. Therefore, right now I have rules such as:

    expression : expression LESS expression %prec COMPARISON
    expression : template
    template : NAME
             | NAME LESS templates GREATER
    templates : template
              | templates COMMA template

However, I found that it could not parse:

a < 2

(which is an obvious problem). Below is the debug output:

PLY: PARSE DEBUG START

State  : 0
Stack  : . <Token: 'NAME' 'a'>
Action : Shift and goto state 42

State  : 42
Stack  : NAME . <Token: 'LESS' '<'>
Action : Shift and goto state 81

State  : 81
Stack  : NAME LESS . <Token: 'NUMBER' '2'>
ERROR: Error  : NAME LESS . <Token: 'NUMBER' '2'>

If more than my analyzer is required, I can provide it. Thanks.

EDIT: , , , . , , , ​​ C/++, , , , .

+3
1

Yacc , . - , yacc , - , .


  • , , , < > .

  • , / , . - , , , . ( , yacc.)

, . , , yacc , , "", . . (RD - , , BNFish yacc, , " ".)

Python Ruby Treetop? . Bison %glr-parser "" , , BFI.

+1

Source: https://habr.com/ru/post/1724132/


All Articles