Tencent/matrix · error

parsing conflicts.

Error message

%d parsing conflicts.

What it means

Lemon reports the number of shift/reduce (and reduce/reduce) conflicts discovered while building the LALR parser tables, printing '%d parsing conflicts.' to stderr. It then exits with errorcnt + nconflict, so any conflict makes the run fail. Conflicts mean the grammar is ambiguous and lemon resolved them (usually by favoring shifts) but refuses to pass silently.

Solutions

  1. Read the conflict report in lemon's generated .out file (run with -g or inspect the state machine) to locate the conflicting state and token
  2. Add precedence declarations (%left, %right, %nonassoc) for the operator tokens involved
  3. Restructure the ambiguous productions so the parse is deterministic (explicit list/terminator rules)
  4. Accept a known conflict deliberately by fixing the grammar so lemon resolves it per your intent, verifying the generated parse matches expected behavior

Example fix

// before
expr ::= expr PLUS expr.
expr ::= expr TIMES expr.
// after
%left PLUS.
%left TIMES.
expr ::= expr PLUS expr.
expr ::= expr TIMES expr.
Defensive patterns

Strategy: validation

Validate before calling

// fail fast on conflicts by always checking lemon's exit code
lemon -q -s grammar.y || { echo 'grammar conflicts detected; inspect grammar.out'; exit 1; }

Prevention

When it happens

Trigger: Running lemon on a grammar where a state has both a shift action and a reduce action for the same lookahead token (classic dangling-else, optional-terminator, or operator-precedence patterns) and no %left/%right/%nonassoc precedence declarations or conflict resolutions apply.

Common situations: Adding a new construct that makes an optional trailing element ambiguous (e.g. `list ::= list item SEMI.` vs `list ::= list item.`); grammar evolution after merging branches; porting a yacc/bison grammar relying on default bison resolution into lemon which treats conflicts as errors; missing precedence declarations for expression operators.

Related errors


AI-assisted analysis of Tencent/matrix@3b8293bd65 (2026-09-08). Data as JSON: /api/errors/143cb6008f775b51. Report an issue: GitHub.

Appendix: source

Thrown at matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c:1519

    /* Generate a report of the parser generated.  (the "y.output" file) */
    if( !quiet ) ReportOutput(&lem);

    /* Generate the source code for the parser */
    ReportTable(&lem, mhflag);

    /* Produce a header file for use by the scanner.  (This step is
    ** omitted if the "-m" option is used because makeheaders will
    ** generate the file for us.) */
    if( !mhflag ) ReportHeader(&lem);
  }
  if( statistics ){
    printf("Parser statistics: %d terminals, %d nonterminals, %d rules\n",
      lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule);
    printf("                   %d states, %d parser table entries, %d conflicts\n",
      lem.nstate, lem.tablesize, lem.nconflict);
  }
  if( lem.nconflict ){
    fprintf(stderr,"%d parsing conflicts.\n",lem.nconflict);
  }
  exit(lem.errorcnt + lem.nconflict);
  return (lem.errorcnt + lem.nconflict);
}
/******************** From the file "msort.c" *******************************/
/*
** A generic merge-sort program.
**
** USAGE:
** Let "ptr" be a pointer to some structure which is at the head of
** a null-terminated list.  Then to sort the list call:
**
**     ptr = msort(ptr,&(ptr->next),cmpfnc);
**
** In the above, "cmpfnc" is a pointer to a function which compares
** two instances of the structure and returns an integer, as in
** strcmp.  The second argument is a pointer to the pointer to the
** second element of the linked list.  This address is used to compute

View on GitHub (pinned to 3b8293bd65)