}         //method

        #endregion

        #region Creating parser states
        private void CreateInitialAndFinalStates()
        {
            //there is always just one initial production "Root' -> .Root", and we're interested in LR item at 0 index
            LR0ItemList itemList = new LR0ItemList();

            itemList.Add(Data.AugmentedRoot.Productions[0].LR0Items[0]);
            Data.InitialState = FindOrCreateState(itemList); //it is actually create
            Data.InitialState.Items[0].NewLookaheads.Add(Grammar.Eof.Key);
            #region comment about FinalState
            //Create final state - because of the way states construction works, it doesn't create the final state automatically.
            // We need to create it explicitly and assign it to _data.FinalState property
            // The final executed reduction is "Root' -> Root.". This jump is executed as follows:
            //   1. parser creates Root' node
            //   2. Parser pops the state from stack - that would be initial state
            //   3. Finally, parser tries to find the transition in state.Actions table by the key of [Root'] element.
            // We must create the final state, and create the entry in transition table
            // The final state is based on the same initial production, but different LRItem - the one with dot AFTER the root nonterminal.
            // it is item at index 1.
            #endregion
            itemList.Clear();
            itemList.Add(Data.AugmentedRoot.Productions[0].LR0Items[1]);
            Data.FinalState = FindOrCreateState(itemList); //it is actually create
            //Create shift transition from initial to final state
            Data.InitialState.Actions[Data.AugmentedRoot.Key] =
                new ActionRecord(Data.AugmentedRoot.Key, ParserActionType.Shift, Data.FinalState, null);
        }
Ejemplo n.º 2
0
        private void CreateInitialAndFinalStates()
        {
            LR0ItemList itemList = new LR0ItemList();

            itemList.Add(_data.AugmentedRoot.Productions[0].LR0Items[0]);
            _data.InitialState = FindOrCreateState(itemList);
            _data.InitialState.Items[0].NewLookaheads.Add(Grammar.Eof.Key);

            itemList.Clear();
            itemList.Add(_data.AugmentedRoot.Productions[0].LR0Items[1]);

            _data.FinalState = FindOrCreateState(itemList);
            _data.InitialState.Actions[_data.AugmentedRoot.Key] =
                new ActionRecord(_data.AugmentedRoot.Key, ParserActionType.Shift, _data.FinalState, null);
        }
Ejemplo n.º 3
0
    private void CreateInitialAndFinalStates()
    {
      LR0ItemList itemList = new LR0ItemList();
      itemList.Add(_data.AugmentedRoot.Productions[0].LR0Items[0]);
      _data.InitialState = FindOrCreateState(itemList);
      _data.InitialState.Items[0].NewLookaheads.Add(Grammar.Eof.Key);

      itemList.Clear();
      itemList.Add(_data.AugmentedRoot.Productions[0].LR0Items[1]);

      _data.FinalState = FindOrCreateState(itemList);
      _data.InitialState.Actions[_data.AugmentedRoot.Key] =
        new ActionRecord(_data.AugmentedRoot.Key, ParserActionType.Shift, _data.FinalState, null);
    }