Example #1
0
        private static void ExpandState(GrammarCompilationContext context, IntermediateParserState state)
        {
            // Check for possible shifts.
            foreach (var shifter in state.Items.Shifters)
            {
                var currentElement = shifter.Kernel.Element;

                // Get all LR(1) items sharing the same grammar element, get or
                // create the state that corresponds to the shifted items, and create
                // a transition to that state.
                var shiftedKernels = from item in state.Items
                    let kernel = item.Kernel
                    where kernel.Element == currentElement
                    select kernel.NextItem;
                var kernelsArray = shiftedKernels.ToArray();

                var nextState = context.GetOrCreateState(kernelsArray);
                shifter.NextItem = nextState.Items.First(x => x.Kernel == shifter.Kernel.NextItem);
                context.GetOrCreateTransition(state, currentElement, nextState);
                if (!state.State.Actions.ContainsKey(currentElement))
                {
                    var action = new ShiftParserAction(nextState.State);
                    var customActionElement = currentElement as CustomActionGrammarElement;
                    if (customActionElement != null)
                        action.CustomAction = customActionElement.Action;
                    state.State.Actions[currentElement] = action;
                }
            }
        }
Example #2
0
 private static IntermediateParserState CreateInitialState(GrammarCompilationContext context, GrammarDefinition augmentedRoot)
 {
     // The initial state contains the very first LR(0) item, which is the augmented root '.Root'.
     var initialItem = context.GrammarData.GrammarReductionsMapping[augmentedRoot][0].Lr0Items[0];
     var initialState = context.GetOrCreateState(new [] { initialItem });
     return initialState;
 }