コード例 #1
0
 public CustomParserAction(LanguageData language, ParserState state,
                           ExecuteActionMethod executeRef)
 {
     Language   = language;
     State      = state;
     ExecuteRef = executeRef;
     Conflicts.UnionWith(state.BuilderData.Conflicts);
     // Create default shift and reduce actions
     foreach (var shiftItem in state.BuilderData.ShiftItems)
     {
         ShiftActions.Add(new ShiftParserAction(shiftItem));
     }
     foreach (var item in state.BuilderData.ReduceItems)
     {
         ReduceActions.Add(ReduceParserAction.Create(item.Core.Production));
     }
 }
コード例 #2
0
        //Find an LR item without hints compatible with term (either shift on term or reduce with term as lookahead);
        // this item without hints would become our default. We assume that other items have hints, and when conditions
        // on all these hints fail, we chose this remaining item without hints.
        private ParserAction FindDefaultAction(ParserState state, BnfTerm term)
        {
            //First check reduce items
            var reduceItems = state.BuilderData.ReduceItems.SelectByLookahead(term as Terminal);

            foreach (var item in reduceItems)
            {
                if (item.Core.Hints.Count == 0)
                {
                    return(ReduceParserAction.Create(item.Core.Production));
                }
            }
            var shiftItem = state.BuilderData.ShiftItems.SelectByCurrent(term).FirstOrDefault();

            if (shiftItem != null)
            {
                return(new ShiftParserAction(shiftItem));
            }
            //if everything failed, returned first reduce item
            return(null);
        }