Exemplo n.º 1
0
        private void Complete(Column col, State state)
        {
            if (state.Rule.Name.NonTerminal == GammaRule)
            {
                col.GammaStates.Add(state);
                return;
            }

            foreach (var st in state.StartColumn)
            {
                var term = st.NextProductionTerm();
                NonTerminalStack intersection;
                if (IsCompletedTermConsistentWithNextTerm(state.Rule.Name, term, out intersection))
                {
                    if (state.Node.LogProbability < 0)
                    {
                        throw new LogException(
                                  string.Format(
                                      "trrrr! NODE log probability lower than 0: {0}, reductor state: {1}, predecessor state {2}",
                                      state.Node.LogProbability, state, st));
                    }
                    var y        = State.MakeNode(st, state.EndColumn.Index, state.Node);
                    var newState = new State(st.Rule, st.DotIndex + 1, st.StartColumn, y);
                    newState.Rule.Production[st.DotIndex].Stack = intersection;

                    col.AddState(newState, ParsingOperation.Complete);
                    if (Debug)
                    {
                        Console.WriteLine("{0} & {1} & {2} & Completed from States {3} and {4}\\\\",
                                          newState.StateNumber,
                                          newState, col.Index, st.StateNumber, state.StateNumber);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void Scan(Column col, State state, string term, string token)
        {
            //if there is nonempty stack arriving to this part of speech term, stop here - the derivation is wrong.
            //SEFI - note: this is a restriction on the form of your grammar.
            //consider removing it to see the conequences.

            //if (Grammar.isPOS(term))
            {
                if (!state.NextProductionTerm().IsStackEmpty())
                {
                    return;
                }
            }

            var v = new Node(term, col.Index - 1, col.Index)
            {
                AssociatedTerminal = token,
                LogProbability     = 0.0f,
                Bits = 1
            };
            var y        = State.MakeNode(state, col.Index, v);
            var newState = new State(state.Rule, state.DotIndex + 1, state.StartColumn, y);

            col.AddState(newState, ParsingOperation.Scan);
            if (Debug)
            {
                Console.WriteLine("{0} & {1} & {2} & Scanned from State {3}, word: {4}\\\\", newState.StateNumber,
                                  newState, col.Index,
                                  state.StateNumber, token);
            }

            if (newState.Node.LogProbability < 0)
            {
                throw new LogException(string.Format("scanarrrr! NODE log probability lower than 0: {0}, state: {1}",
                                                     newState.Node.LogProbability, newState));
            }
        }