Пример #1
0
 private void MainWindow_StackChanged(Stack <Token> stack, PrecedenceRelation relation,
                                      ArraySegment <Token> segment, List <Token> prn)
 {
     ViewModel.PrecedenceParsingSteps.Add(new PrecedenceParsingStep
     {
         StackContent = stack.Aggregate(string.Empty, (agr, cur) => string.Join(" ", cur.Substring, agr)).Trim(),
         InputTokens  = segment.Aggregate(string.Empty, (agr, cur) => string.Join(" ", agr, cur.Substring)).Trim(),
         Prn          = prn.Aggregate(string.Empty, (agr, cur) => string.Join(" ", agr, cur.Substring)).Trim(),
         Relation     = relation.ToString()
     });
 }
Пример #2
0
        private void SetRelation(Dictionary <Token, Dictionary <Token, PrecedenceRelation?> > relationMatrix,
                                 Token leftToken,
                                 Token rightToken,
                                 PrecedenceRelation precedenceRelation)
        {
            if (!relationMatrix.ContainsKey(leftToken))
            {
                relationMatrix[leftToken] = new Dictionary <Token, PrecedenceRelation?>();
            }

            if (relationMatrix[leftToken].ContainsKey(rightToken) &&
                precedenceRelation != relationMatrix[leftToken][rightToken])
            {
                _logger.Error("Conflict: {0} {1} (was {2}, attempted {3})", leftToken, rightToken,
                              relationMatrix[leftToken][rightToken], precedenceRelation);
                throw new InvalidOperationException("There is an another relation in this cell already");
            }
            relationMatrix[leftToken][rightToken] = precedenceRelation;
        }
Пример #3
0
 protected virtual void OnStackChanged(Stack <Token> stack, PrecedenceRelation relation,
                                       ArraySegment <Token> inputTokens, List <Token> prn)
 {
     StackChanged?.Invoke(stack, relation, inputTokens, prn);
 }