private string dumpReductionAction(ReductionAction <int, object> reductionAction, string symbolTypeName, Func <int, string> symbolNameConvert, string treeNodeName) { string accept_horizon = dumpSymbolChunkSet(reductionAction.AcceptHorizon, symbolTypeName, symbolNameConvert); string reject_horizon = dumpSymbolChunkSet(reductionAction.RejectHorizon, symbolTypeName, symbolNameConvert); return("ReductionAction.Create(" + dumpNfaCell(reductionAction.Cell, symbolTypeName, symbolNameConvert, treeNodeName) + (accept_horizon != null || reject_horizon != null ? ",/*accept*/" + (accept_horizon != null ? accept_horizon : CodeWords.Null) + ",/*reject*/" + (reject_horizon != null ? reject_horizon : CodeWords.Null) : "") + ")"); }
internal static ReductionAction <SYMBOL_ENUM, TREE_NODE> Create <SYMBOL_ENUM, TREE_NODE>(SingleState <SYMBOL_ENUM, TREE_NODE> state, CoverSets <SYMBOL_ENUM> coverSets, HorizonSets <SYMBOL_ENUM> horizonSets) where SYMBOL_ENUM : struct where TREE_NODE : class { SymbolChunkSet <SYMBOL_ENUM> cover = coverSets[state.LhsSymbol]; SymbolChunkSet <SYMBOL_ENUM> horizon = horizonSets[state.LhsSymbol]; // if we have internal conflict between symbols, we cannot use horizon data (because we couldn't tell if we reached horizon) bool use_horizon = !horizon.IsEmpty && !cover.Overlaps(horizon); var action = new ReductionAction <SYMBOL_ENUM, TREE_NODE>(state.CreateCell(), use_horizon ? horizon : null, use_horizon ? new SymbolChunkSet <SYMBOL_ENUM>() : null); return(action); }
private bool disambiguateShiftReduceConflictOnHorizon(SingleState <SYMBOL_ENUM, TREE_NODE> shiftItem, ReductionAction <SYMBOL_ENUM, TREE_NODE> reduceAction) { foreach (SYMBOL_ENUM incoming in shiftItem.RhsUnseenSymbols) { if (!coverSets[incoming].Overlaps(coverSets[reduceAction.Cell.LhsSymbol]) && !coverSets[incoming].Overlaps(reduceAction.AcceptHorizon)) { // we have to use cover set, and not the incoming symbol, because // it could be non-terminal, and those do NOT exist by definition in the input stream, only on stack reduceAction.RejectHorizon.Add(coverSets[incoming]); return(true); } } if (!shiftItem.AfterLookaheads.Overlaps(coverSets[reduceAction.Cell.LhsSymbol]) && !shiftItem.AfterLookaheads.Overlaps(reduceAction.AcceptHorizon)) { reduceAction.RejectHorizon.Add(shiftItem.AfterLookaheads); return(true); } return(false); }
public void AddReduce(int sourceNodeId, SymbolChunk <SYMBOL_ENUM> inputChunk, SingleState <SYMBOL_ENUM, TREE_NODE> reductionItem) { setSingle(sourceNodeId, inputChunk, new ParseAction <SYMBOL_ENUM, TREE_NODE>(false, ReductionAction.Create(reductionItem.CreateCell()))); }