Parsing conflict in Lemon grammar

40 views Asked by At

I am writing a parser for LaTeX mathematical formulas to convert them into MathML. So I wrote this grammar for Lemon.

%token BEGIN_GROUP END_GROUP MATH_SHIFT ALIGNMENT_TAB.
%token END_OF_LINE PARAMETER SUPERSCRIPT SUBSCRIPT.
%token SPACE LETTER DIGIT SYMBOL.
%token COMMAND COMMAND_LEFT COMMAND_RIGHT.
%token COMMAND_LIMITS COMMAND_NOLIMITS.
%token BEGIN_ENV END_ENV.
%token NBSP.

/* Some API */

document ::= list.

list ::= list element.
list ::= .

element ::= identifier(Id).
element ::= symbol(O).
element ::= number(Num).

identifier ::= LETTER.

symbol ::= SYMBOL.

number(N) ::= number DIGIT(D). /* Append digit */
number(N) ::= DIGIT(D). /* Init digits */

/* Lexer code */

This grammar is incomplete, it doesn't contains main program code. This is an output from Lemon parser:

State 2:
      (2) element ::= number *
          number ::= number * DIGIT

                         DIGIT shift-reduce 3      number ::= number DIGIT
                         DIGIT reduce       2       ** Parsing conflict **
                     {default} reduce       2      element ::= number

This grammar produces one parsing conflict. How can I resolve this conflict?

I am writing my parser for the first time so I don't have enough experience to solve this problem.

0

There are 0 answers