public override void Transform(AbstractSyntaxTree astNode)
        {
            switch (astNode.Type)
            {
            case TokenType.InfixOperator:
            case TokenType.PostfixOperator:
            case TokenType.PrefixOperator:
                astNode.Collapse();
                return;

            case TokenType.ParenthesesNode:
                if (astNode.Children.Count == 1)
                {
                    astNode.Collapse();
                }
                return;

            default:
                return;
            }
        }
コード例 #2
0
 public override void Transform(AbstractSyntaxTree astNode)
 {
     if (astNode.Type == TokenType.PrefixNode)
     {
         if (astNode.Children.Count == 1)
         {
             astNode.Collapse();
             return;
         }
         else
         {
             var source = astNode.Children;
             var value  = new AbstractSyntaxTree(new Node(TokenType.PrefixNode), source.GetRange(1, source.Count - 1));
             var prefix = source.First();
             astNode.Children = new List <AbstractSyntaxTree>()
             {
                 value, prefix
             };
         }
     }
 }