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)); }
//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; }
//Check if there is an action already in state for this term; if yes, and it is Conditional action, // then simply add an extra conditional entry to it. If an action does not exist, or it is not conditional, // create new conditional action for this term. private void AddConditionalEntry(ParserState state, BnfTerm term, ConditionalParserAction.ConditionalEntry entry) { ParserAction oldAction; ConditionalParserAction condAction = null; if (state.Actions.TryGetValue(term, out oldAction)) condAction = oldAction as ConditionalParserAction; if (condAction == null) { //there's no old action, or it is not conditional; create new conditional action condAction = new ConditionalParserAction(); condAction.DefaultAction = oldAction; state.Actions[term] = condAction; } condAction.ConditionalEntries.Add(entry); if (condAction.DefaultAction == null) condAction.DefaultAction = FindDefaultAction(state, term); if (condAction.DefaultAction == null) //if still no action, then use the cond. action as default. condAction.DefaultAction = entry.Action; }
public ShiftParserAction(BnfTerm term, ParserState newState) { Term = term; NewState = newState; }
public SyntaxError(SourceLocation location, string message, ParserState parserState) { Location = location; Message = message; ParserState = parserState; }
internal ParserAction(ParserState newState, Production reduceProduction, Action <ConflictResolutionArgs> conflictResolver) : this(ParserActionType.Code, newState, reduceProduction) { ConflictResolver = conflictResolver; }
public ParseTreeNode(ParserState initialState) : this() { State = initialState; }