1
Vote

How to resolve Reduce/Shift with extra look ahead

description

Please see attachment.

If I understand the process correctly, I wish to use the ResolveInCode option to control the decision at S119 by peeking at an extra token. So a few hints were added for a few of the NonTerminal Rules that I though are near S119 like so:

optNot.Rule = GrammarHint(HintType.ResolveInCode, null) + Empty | not;

However the OnResolvingConflict(...) override that I provided within the Grammar class is never called.

By looking at the state 119, how to determine on which Rule to place the hint so that it is called (or is there some additional requirements)? Or should I be trying to use the "Recovering...looking for state with error shift" feature?

( There are no grammar errors but some inadequate's which have not been a problem except for this particular input. )

Thanks,
Chris

file attachments

comments

crokusek wrote Apr 10, 2014 at 6:25 PM

Here is what ended up working. Please comment on any bad practices:

Thanks,
Chris


optNot.Rule = Empty | (new GrammarHint(HintType.ResolveInCode, null) + not);

// Allows use of a look ahead to resolve a questionably defined grammar sections
public override void OnResolvingConflict(ConflictResolutionArgs args)
{
bool foundMatch = false;
switch (args.Context.CurrentParserInput.Term.Name)
{
    case Term.not:

        // Want to limit to just the state with the issue (but not by State#)
        //
        if (args.ReduceProduction.LValue.Name == Term.valueTerm) 
        {
            args.Scanner.BeginPreview();
            var preview = args.Scanner.GetToken();
            string termName = preview.KeyTerm.Text;
            args.Result = termName == Term.in_ ? ParserActionType.Reduce : ParserActionType.Shift;
            args.Scanner.EndPreview(true);
            foundMatch = true;
         }
         break;
}
}

crokusek wrote Apr 10, 2014 at 6:26 PM

Here is what ended up working. Please comment on any bad practices:

Thanks,
Chris
optNot.Rule = Empty | (new GrammarHint(HintType.ResolveInCode, null) + not);

// Allows use of a look ahead to resolve a questionably defined grammar sections
public override void OnResolvingConflict(ConflictResolutionArgs args)
{
    bool foundMatch = false;
    switch (args.Context.CurrentParserInput.Term.Name)
    {
        case Term.not:

            // Want to limit to just the state with the issue (but not by State#)
            //
            if (args.ReduceProduction.LValue.Name == Term.valueTerm) 
            {
                args.Scanner.BeginPreview();
                var preview = args.Scanner.GetToken();
                string termName = preview.KeyTerm.Text;
                args.Result = termName == Term.in_ ? ParserActionType.Reduce : ParserActionType.Shift;
                args.Scanner.EndPreview(true);
                foundMatch = true;
             }
             break;
    }
}