Shift-Reduce conflict.State 21 when using if else statement

Jun 14, 2013 at 12:49 PM
Edited Jun 14, 2013 at 2:04 PM
Hello again Roman,
Your guidance is proving to be extremely helpful to me.

I have created a node for statement and if else statement.

I want to interpret following simple statement
if(3<4){4+5}

My Grammar
public class MathEngineGrammar : InterpretedLanguageGrammar
    {
        public MathEngineGrammar()
            : base(false)
        {
            NumberLiteral Number = TerminalFactory.CreateCSharpNumber("Number");
            var statementList = new NonTerminal("statementList",typeof(StatementListNode));
            var statement = new NonTerminal("statement",typeof(StatementNode));
            var if_statement = new NonTerminal("if_statement",typeof(IfStatementNode));

            var expression = new NonTerminal("expression");
            var binexpr = new NonTerminal("binexpr", typeof(BinaryOperationNode));            
            var binop = new NonTerminal("binop", "operator");

            
            statementList.Rule = MakeStarRule(statementList, null, statement);
            statement.Rule = expression | if_statement;
            if_statement.Rule = ToTerm("if") + "(" + expression + ")" + "{"+expression+"}";

            expression.Rule = binexpr | Number;            
            binexpr.Rule = expression + binop + expression;
            binop.Rule = ToTerm("+") | "-" | "/" | "*" | "<" | ">" | "<=" | ">=";

            this.Root = statementList;

            MarkPunctuation("(", ")");

            RegisterOperators(1, "+", "-");
            RegisterOperators(2, "*", "/");
            AddOperatorReportGroup("operator");

            this.MarkTransient(expression, binop);
            //LanguageFlags = LanguageFlags.CreateAst;
        }
    }
I got following error
Attempt by method 'DynamicClass.CreateAstNode()' to access type 'MathEngineSample1.Nodes.IfStatementNode' failed.
on following line
parseNode.AstNode = config.DefaultNodeCreator(); in AstBuilder.cs
On debugging i found that Language Error Level is "Conflict" and saying
Shift-reduce conflict. State S21, lookaheads [< > <= >=]. Selected shift as preferred action.
Jun 14, 2013 at 2:24 PM
perhaps i need to register the 4 operators.
Jun 14, 2013 at 2:34 PM
I registered the operators and issue was gone but still got this error yet again.
Attempt by method 'DynamicClass.CreateAstNode()' to access type 'MathEngineSample1.Nodes.IfStatementNode' failed.
Debugging to find out where the issue is.

Any suggestion ?
Jun 14, 2013 at 3:09 PM
Silly me !! I had not declared the IfStatementNode public. Issue resolved .