Avoiding Grammar Conflicts

I have a grammar file - https://github.com/itrelease/fubar-script/blob/jsast/src/grammar.js , but I get conflicts and I really don't know how to solve this. If someone could explain to me, that would be helpful.

These rules produce conflicts :

ParamVar: [
  ['Identifier', '$$ = $Identifier;'],
  ['THIS', '$$ = new yy.ThisExpression();']
],

PrimaryExpression: [
  ['THIS', '$$ = new yy.ThisExpression();'],
  ['Literal', '$$ = $Literal;'],
  ['ArrayLiteral', '$$ = $ArrayLiteral;'],
  ['Identifier', '$$ = $Identifier;'],
  ['ObjectLiteral', '$$ = $ObjectLiteral;'],
  ['( Expression )', '$$ = $Expression;']
],
+3
source share
1 answer

There isn’t in your current grammar PrimaryExpressionNoBrace, but I suppose a problem arose with this old version of the grammar.

The conflict is caused by this product:

MemberExpression: [
      ['PrimaryExpression', '$$ = $PrimaryExpression;'],
      ['ArrowFunctionExpression', '$$ = $ArrowFunctionExpression'],
      ...

Where

  • a PrimaryExpressionis deduced on PrimaryExpressionNoBracefor which'( Expression )'

  • PrimaryExpressionNoBrace, IDENTIFIER THIS

  • a ArrowFunctionExpression '( FormalParameterList ) => Block'

  • FormalParameterList IDENTIFIER THIS.

, , IDENTIFIER THIS, LR-, PrimaryExpressionNoBrace FormalParameterList, - (, ). , .

+2

All Articles