Esempio n. 1
0
 public void AddParseActionToTable(int row, int cell, ParserAction parserAction)
 {
     if (ActionTable[row, cell] == null)
     {
         ActionTable[row, cell] = parserAction;
     }
     else
     {
         if (!ActionTable[row, cell].Equals(parserAction))
         {
             ActionTable[row, cell].ErrorAction = parserAction;
         }
     }
 }
Esempio n. 2
0
        private void AddReduceAccept(Variable head, States.State currentState)
        {
            foreach (RowState currentStateRowState in currentState.RowStates)
            {
                ParserAction parser = new ParserAction();
                //if some rule is finished it means reduce or accept
                if (!currentStateRowState.Finished)
                {
                    continue;
                }

                if (currentStateRowState.Variable.Equals(head))
                {
                    parser.Action = Action.Accept;
                    AddParseActionToTable(currentState.StateId, _mapperToNumber.Map(Terminal.EndOfFile), parser);
                }
                else
                {
                    parser.Action   = Action.Reduce;
                    parser.Variable = currentStateRowState.Variable;
                    parser.Handle   = currentStateRowState.Rule;

                    if (_lrType == LRType.Zero)
                    {
                        for (int i = 0; i < _mapperToNumber.TerminalCount; i++)
                        {
                            AddParseActionToTable(currentState.StateId, i, parser);
                        }
                    }
                    else if (_lrType == LRType.SLR_One)
                    {
                        foreach (Terminal terminal in currentStateRowState.Variable.Follows)
                        {
                            AddParseActionToTable(currentState.StateId, _mapperToNumber.Map(terminal), parser);
                        }
                    }
                    else if (_lrType == LRType.ClR_One)
                    {
                        foreach (Terminal terminal in currentStateRowState.LookAhead)
                        {
                            AddParseActionToTable(currentState.StateId, _mapperToNumber.Map(terminal), parser);
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 private void AddShiftGo(States.State currentState)
 {
     foreach (KeyValuePair <ISymbol, States.State> fsmStateNextState in currentState.NextStates)
     {
         //shift
         if (fsmStateNextState.Key is Terminal terminal)
         {
             ParserAction action = new ParserAction
             {
                 ShiftState = fsmStateNextState.Value.StateId,
                 Action     = Action.Shift
             };
             AddParseActionToTable(currentState.StateId, _mapperToNumber.Map(terminal), action);
         }
         //goto
         else if (fsmStateNextState.Key is Variable variable)
         {
             GoToTable[currentState.StateId, _mapperToNumber.Map(variable)] =
                 new GoTo(fsmStateNextState.Value.StateId);
         }
     }
 }
Esempio n. 4
0
 public void Init()
 {
     ActionTable = new ParserAction[_fsm.States.Count, _mapperToNumber.TerminalCount];
     GoToTable   = new GoTo[_fsm.States.Count, _mapperToNumber.VariableCount];
 }