DIRECTORY
GrammarBasic USING[Grammar, Production, Symbol],
TerminalSequences USING[TerminalSeq, GenTerminalSeqsFromSet],
LR0ItemSetsBasic USING[LR0Item],
LR0Items USING[CompleteProduction],
LR1ItemSetsBasic USING[LR1ItemSet, LR1ItemSubset, CreateEmptyLR1ItemSet, FreezeLR1ItemSet, GenerateDirtySubsetsFromLR1ItemSet, GenerateSubsetsFromLR1ItemSet, InsertSubsetInLR1ItemSet],
LR1Items USING[GenKernelV1EpsilonItemSubsets, GenKernelGoTo1ItemSubsetsFromKernelItemSubset, GenCloseOfLR1ItemSubset],
LR1ItemSets USING[];
LR1ItemSetsImpl: CEDAR PROGRAM IMPORTS LR0Items, LR1ItemSetsBasic, LR1Items, TerminalSequences EXPORTS LR1ItemSets =
BEGIN OPEN GrammarBasic, TerminalSequences, LR0ItemSetsBasic, LR0Items, LR1ItemSetsBasic, LR1Items;
GenReductionRulesFromKernel: PUBLIC PROC[set: LR1ItemSet, for: PROC[TerminalSeq, Production]] =
BEGIN
HandleOneItem: PROC[subSet: LR1ItemSubset] =
BEGIN
production: Production ← CompleteProduction[subSet.lr0Item];
IF production # NIL THEN
BEGIN
SeeOneTermSeq: PROC[termSeq: TerminalSeq] =
{for[termSeq, production]};
GenTerminalSeqsFromSet[subSet.terminals, SeeOneTermSeq];
END;
END;
HandleOneKernelSubset: PROC[subset: LR1ItemSubset] =
{GenCloseOfLR1ItemSubset[subset, HandleOneItem]};
GenerateSubsetsFromLR1ItemSet[set, HandleOneKernelSubset];
END;
CreateV1EpsilonKernel: PUBLIC PROC[grammar: Grammar] RETURNS[LR1ItemSet] =
BEGIN
tentativeSet: LR1ItemSet ← CreateEmptyLR1ItemSet[grammar];
InsertV1EpsilonKernelItems[grammar, tentativeSet];
RETURN[FreezeLR1ItemSet[tentativeSet, TRUE]];
END;
GenKernelGoTo1ItemSubsetsFromDirtyKernelItems: PUBLIC PROC[set: LR1ItemSet, for: PROC[Symbol, LR1ItemSubset]] =
BEGIN -- and mark them clean
GenTheItems: PROC[preGoToLR1ItemSubset: LR1ItemSubset] =
{GenKernelGoTo1ItemSubsetsFromKernelItemSubset[preGoToLR1ItemSubset, for]};
GenerateDirtySubsetsFromLR1ItemSet[set, GenTheItems];
END;
InsertV1EpsilonKernelItems: PUBLIC PROC[grammar: Grammar, set: LR1ItemSet] =
BEGIN
InsertOne: PROC[subset: LR1ItemSubset] =
{[] ← InsertSubsetInLR1ItemSet[subset, set]};
GenKernelV1EpsilonItemSubsets[grammar, InsertOne];
END;
GenKernelGoTo1ItemSubsetsFromKernel: PUBLIC PROC[set: LR1ItemSet, for: PROC[Symbol, LR1ItemSubset]] =
BEGIN
HandleOneKernelItemSubset: PROC[kernelItemSubset: LR1ItemSubset] =
{GenKernelGoTo1ItemSubsetsFromKernelItemSubset[kernelItemSubset, for]};
GenerateSubsetsFromLR1ItemSet[set, HandleOneKernelItemSubset];
END;
END..
-- RTE: November 1, 1984 2:27:57 pm PST: CreateV1EpsilonKernel insisted that the set not have been seen before, but if we are splitting a ring outside of the ring containing start, it will have been seen before.