コード例 #1
0
        private Node GetTerm()
        {
            Node left = GetFactor();

            if (GetRemainingTokenCount() == 0)
            {
                return(left);
            }

            OperatorNode operatorNode;

            switch (GetTokenType())
            {
            case Token.Plus:
                operatorNode = new OperatorNode(Operator.Plus);
                break;

            case Token.Minus:
                operatorNode = new OperatorNode(Operator.Minus);
                break;

            case Token.In:
            case Token.ClosingParenthesis:
                return(left);

            default:
                throw new ASTException("Expected plus or minus, in or closing parenthesis, got " + GetTokenType());
            }

            ConsumeTokens(1);

            operatorNode.Left  = left;
            operatorNode.Right = GetTerm();
            return(operatorNode);
        }
コード例 #2
0
        void Woodification(TempNode node, ref int i, OperatorsType operatorsType)
        {
            if (node.Datas.Count > i + 1)
            {
                OperatorNode operatorNode = new OperatorNode();
                operatorNode.ThisOperatorsType = operatorsType;
                if (node.Datas[i + 1].Data == "-" || node.Datas[i + 1].Data == "+")
                {
                    node.Datas[i + 1].Data = node.Datas[i + 1].Data + node.Datas[i + 2].Data;
                    node.Datas.RemoveAt(i + 2);
                }

                operatorNode.LeftSide  = node.Datas[i - 1];
                operatorNode.RightSide = node.Datas[i + 1];
                for (int j = i - 1; j <= i + 1; j++)
                {
                    node.Datas.RemoveAt(i - 1);
                }
                node.Datas.Insert(i - 1, operatorNode);
                i--;
            }
            else
            {
                node.Datas.RemoveAt(i);
                i--;
            }
        }
コード例 #3
0
        private Node GetFactor()
        {
            Node left = GetUnary();

            if (GetRemainingTokenCount() == 0)
            {
                return(left);
            }

            OperatorNode operatorNode;

            switch (GetTokenType())
            {
            case Token.Star:
                operatorNode = new OperatorNode(Operator.Star);
                break;

            case Token.Slash:
                operatorNode = new OperatorNode(Operator.Slash);
                break;

            default:
                return(left);
            }

            ConsumeTokens(1);

            operatorNode.Left  = left;
            operatorNode.Right = GetFactor();
            return(operatorNode);
        }
コード例 #4
0
ファイル: PolishNotation.cs プロジェクト: molongwudi/IL2C
 public ExpressionNode(OperatorNode oper, ReducibleNode left, ReducibleNode right, int nextIndex) : base(nextIndex)
 {
     this.Operator = oper;
     this.Left     = left;
     this.Right    = right;
 }