Esempio n. 1
0
        public override TerminalNode Val()
        {
            if (!this.IsConstant())
            {
                return(null);
            }
            TerminalNode result = factor.Val();
            Tag          op     = unaryOp.Count > 0 ? unaryOp[0] : Tag.NULL;

            if (op == Tag.DL_NOT)
            {
                if (unaryOp.Count % 2 != 0)
                {
                    result = new BoolNode(!((result as BoolNode).value == 1));
                }
            }
            else if (op == Tag.DL_MINUS || op == Tag.DL_PLUS)
            {
                op = Tag.DL_PLUS;
                foreach (var item in unaryOp)
                {
                    if (item == Tag.DL_MINUS)
                    {
                        op = op == Tag.DL_MINUS ? Tag.DL_PLUS : Tag.DL_MINUS;
                    }
                }

                if (op == Tag.DL_MINUS)
                {
                    result = new IntNode(-(result as IntNode).value);
                }
            }

            return(result);
        }
Esempio n. 2
0
        public override TerminalNode Val()
        {
            if (!this.IsConstant())
            {
                return(null);
            }
            TerminalNode result = new BoolNode(false);

            foreach (var node in children)
            {
                if (node.Op != Tag.NULL)
                {
                    if (node.Op == Tag.DL_MULTI)
                    {
                        if (Utils.IsNumType(node.Type()))
                        {
                            result = new IntNode(((result as IntNode).value * (node.Val() as IntNode).value));
                        }
                    }
                    else if (node.Op == Tag.DL_OBELUS)
                    {
                        if (Utils.IsNumType(node.Type()))
                        {
                            result = new IntNode(((result as IntNode).value / (node.Val() as IntNode).value));
                        }
                    }
                }
                else
                {
                    result = node.Val();
                }
            }
            return(result);
        }