{"record":{"id":"143cb6008f775b51","repo":"Tencent/matrix","slug":"d-parsing-conflicts","errorCode":null,"errorMessage":"%d parsing conflicts.\n","messagePattern":"(.+?) parsing conflicts\\.\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c","lineNumber":1519,"sourceCode":"    /* Generate a report of the parser generated.  (the \"y.output\" file) */\n    if( !quiet ) ReportOutput(&lem);\n\n    /* Generate the source code for the parser */\n    ReportTable(&lem, mhflag);\n\n    /* Produce a header file for use by the scanner.  (This step is\n    ** omitted if the \"-m\" option is used because makeheaders will\n    ** generate the file for us.) */\n    if( !mhflag ) ReportHeader(&lem);\n  }\n  if( statistics ){\n    printf(\"Parser statistics: %d terminals, %d nonterminals, %d rules\\n\",\n      lem.nterminal, lem.nsymbol - lem.nterminal, lem.nrule);\n    printf(\"                   %d states, %d parser table entries, %d conflicts\\n\",\n      lem.nstate, lem.tablesize, lem.nconflict);\n  }\n  if( lem.nconflict ){\n    fprintf(stderr,\"%d parsing conflicts.\\n\",lem.nconflict);\n  }\n  exit(lem.errorcnt + lem.nconflict);\n  return (lem.errorcnt + lem.nconflict);\n}\n/******************** From the file \"msort.c\" *******************************/\n/*\n** A generic merge-sort program.\n**\n** USAGE:\n** Let \"ptr\" be a pointer to some structure which is at the head of\n** a null-terminated list.  Then to sort the list call:\n**\n**     ptr = msort(ptr,&(ptr->next),cmpfnc);\n**\n** In the above, \"cmpfnc\" is a pointer to a function which compares\n** two instances of the structure and returns an integer, as in\n** strcmp.  The second argument is a pointer to the pointer to the\n** second element of the linked list.  This address is used to compute","sourceCodeStart":1501,"sourceCodeEnd":1537,"githubUrl":"https://github.com/Tencent/matrix/blob/3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7/matrix/matrix-android/matrix-sqlite-lint/src/lemon/lemon-gen/lemon.c#L1501-L1537","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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","Add precedence declarations (%left, %right, %nonassoc) for the operator tokens involved","Restructure the ambiguous productions so the parse is deterministic (explicit list/terminator rules)","Accept a known conflict deliberately by fixing the grammar so lemon resolves it per your intent, verifying the generated parse matches expected behavior"],"exampleFix":"// before\nexpr ::= expr PLUS expr.\nexpr ::= expr TIMES expr.\n// after\n%left PLUS.\n%left TIMES.\nexpr ::= expr PLUS expr.\nexpr ::= expr TIMES expr.","handlingStrategy":"validation","validationCode":"// fail fast on conflicts by always checking lemon's exit code\nlemon -q -s grammar.y || { echo 'grammar conflicts detected; inspect grammar.out'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add %left/%right/%nonassoc precedence declarations when defining expression grammars","Keep the generated .out state report in CI artifacts to diagnose new conflicts","Refactor ambiguous optional-terminator productions into explicit alternatives","Port yacc/bison grammars carefully: lemon treats every conflict as a failure"],"tags":["grammar","parser-generator","lemon","ambiguity","lalr"],"backgroundTag":"grammar-conflict","analyzedSha":"3b8293bd65d47eeea7caf1f32a3a5d4d5eab60e7","analyzedAt":"2026-09-08T08:01:39.722Z","contentChangedAt":"2026-09-08T08:01:39.722Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}