コード例 #1
0
ファイル: ParserStack.cs プロジェクト: eightrivers/SSharp
 public void Push(AstNode node, ParserState state)
 {
   _data.Add(new ParserStackElement(node, state));
 }
コード例 #2
0
    private bool AddClosureItems(ParserState state)
    {
      bool result = false;
      for (int i = 0; i < state.Items.Count; i++)
      {
        LRItem item = state.Items[i];
        NonTerminal nextNT = item.Core.NextElement as NonTerminal;
        if (nextNT == null) continue;

        foreach (Production prod in nextNT.Productions)
        {
          LR0Item core = prod.LR0Items[0]; 
          LRItem newItem = TryFindItem(state, core);
          if (newItem == null)
          {
            newItem = new LRItem(state, core);
            state.Items.Add(newItem);
            result = true;
          }

          newItem.NewLookaheads.AddRange(item.Core.TailFirsts);
          if (item.Core.TailIsNullable && !item.PropagateTargets.Contains(newItem))
            item.PropagateTargets.Add(newItem);
        }
      }

      return result;
    }
コード例 #3
0
ファイル: ParserStack.cs プロジェクト: eightrivers/SSharp
 public ParserStackElement(AstNode node, ParserState state)
 {
   Node = node;
   State = state;
 }
コード例 #4
0
 private Dictionary<string, LR0ItemList> GetStateShifts(ParserState state)
 {
   Dictionary<string, LR0ItemList> shifts = new Dictionary<string, LR0ItemList>();
   LR0ItemList list;
   foreach (LRItem item in state.Items)
   {
     GrammarTerm term = item.Core.NextElement;
     if (term == null) continue;
     LR0Item shiftedItem = item.Core.Production.LR0Items[item.Core.Position + 1];
     if (!shifts.TryGetValue(term.Key, out list))
       shifts[term.Key] = list = new LR0ItemList();
     list.Add(shiftedItem);
   }
   return shifts;
 }
コード例 #5
0
 private ParserState FindOrCreateState(LR0ItemList lr0Items)
 {
   string key = CalcItemListKey(lr0Items);
   ParserState result;
   if (_stateHash.TryGetValue(key, out result))
     return result;
   result = new ParserState("S" + _data.States.Count, lr0Items);
   _data.States.Add(result);
   _stateHash[key] = result;
   return result;
 }
コード例 #6
0
 private LRItem FindItem(ParserState state, Production production, int position)
 {
   foreach (LRItem item in state.Items)
     if (item.Core.Production == production && item.Core.Position == position)
       return item;
   string msg = string.Format("Failed to find an LRItem in state {0} by production [{1}] and position {2}. ",
     state, production.ToString(), position.ToString());
   throw new CompilerException(msg);
 }
コード例 #7
0
 private LRItem TryFindItem(ParserState state, LR0Item core)
 {
   foreach (LRItem item in state.Items)
     if (item.Core == core)
       return item;
   return null;
 }
コード例 #8
0
ファイル: SyntaxError.cs プロジェクト: eightrivers/SSharp
 public SyntaxError(SourceLocation location, string message, ParserState state)
 {
   Location = location;
   Message = message;
   State = state;
 }
コード例 #9
0
ファイル: CompilerContext.cs プロジェクト: eightrivers/SSharp
 public void AddError(SourceLocation location, string message, ParserState state)
 {
   Errors.Add(new SyntaxError(location, message, state));
 }
コード例 #10
0
 private void ExecuteShiftAction(ActionRecord action)
 {
     _stack.Push(_currentToken, _currentState);
     _currentState = action.NewState;
     NextToken();
 }