Example #1
0
        public Node BooleanTerm()
        {
            Node node = NotFactor();

            while (CurrentToken().type == TokenType.AND)
            {
                MatchAndEat(TokenType.AND);
                node = new BinOpNode(TokenType.AND, node, NotFactor());
            }
            return(node);
        }
        public static void main(string[] args)
        {
            NumberNode firstNumber  = new NumberNode(100);
            NumberNode secondNumber = new NumberNode(200);

            Node sumNode = new BinOpNode(TokenType.ADD, firstNumber, secondNumber);

            Console.WriteLine("100 + 200 = " + sumNode.Eval());
            Node compareNode = new BinOpNode(TokenType.LESS, firstNumber, secondNumber);

            Console.WriteLine("100 < 200 = " + compareNode.Eval());
        }
Example #3
0
        public Node PreFactor()
        {
            Node node = Factor();

            while (IsPowOp(CurrentToken().type))
            {
                switch (CurrentToken().type)
                {
                case TokenType.POWER:
                    node = new BinOpNode(TokenType.POWER, node, Power());
                    break;
                }
            }
            return(node);
        }
Example #4
0
        public Node BooleanExpression()
        {
            Node node = BooleanTerm();

            while (IsLogicalOp(CurrentToken().type))
            {
                switch (CurrentToken().type)
                {
                case TokenType.OR:
                    MatchAndEat(TokenType.OR);
                    node = new BinOpNode(TokenType.OR, node, BooleanTerm());
                    break;
                }
            }
            return(node);
        }
Example #5
0
        public Node ArithmeticExpression()
        {
            Node node = Term();

            while (IsAddOp(CurrentToken().type))
            {
                switch (CurrentToken().type)
                {
                case TokenType.ADD:
                    node = new BinOpNode(TokenType.ADD, node, Add());
                    break;

                case TokenType.SUBTRACT:
                    node = new BinOpNode(TokenType.SUBTRACT, node, Subtract());
                    break;
                }
            }
            return(node);
        }
Example #6
0
        public Node Term()
        {
            Node node = SignedFactor();

            while (IsMulOp(CurrentToken().type))
            {
                switch (CurrentToken().type)
                {
                case TokenType.MULTIPLY:
                    node = new BinOpNode(TokenType.MULTIPLY, node, Multiply());
                    break;

                case TokenType.DIVIDE:
                    node = new BinOpNode(TokenType.DIVIDE, node, Divide());
                    break;

                case TokenType.MOD:
                    node = new BinOpNode(TokenType.MOD, node, Mod());
                    break;
                }
            }
            return(node);
        }