Exemplo n.º 1
0
        /// <summary>
        /// Visit a parse tree produced by <see cref="Generated.Z80AsmParser.equExpr"/>.
        /// </summary>
        /// <param name="context">The parse tree.</param>
        /// <return>The visitor result.</return>
        public override object VisitEquExpr(Z80AsmParser.EquExprContext context)
        {
            if (IsInvalidContext(context))
            {
                return(null);
            }

            var expr           = (ExpressionNode)VisitRelExpr(context.GetChild(0) as Z80AsmParser.RelExprContext);
            var nextChildIndex = 2;

            while (nextChildIndex < context.ChildCount)
            {
                var rightExpr = VisitRelExpr(context.GetChild(nextChildIndex)
                                             as Z80AsmParser.RelExprContext);
                var opToken = context.GetChild(nextChildIndex - 1).NormalizeToken();
                var equExpr = opToken == "=="
                    ? new EqualOperationNode()
                    : new NotEqualOperationNode() as BinaryOperationNode;
                equExpr.LeftOperand  = expr;
                equExpr.RightOperand = (ExpressionNode)rightExpr;
                expr            = equExpr;
                nextChildIndex += 2;
            }
            return(expr);
        }
Exemplo n.º 2
0
        public override object VisitEquExpr(Z80AsmParser.EquExprContext context)
        {
            if (context == null)
            {
                return(null);
            }

            var subExprs = context.relExpr();
            var expr     = VisitRelExpr(subExprs[0]);
            var opIndex  = 1;

            for (var i = 1; i < subExprs.Length; i++)
            {
                var rightExpr = VisitRelExpr(subExprs[i]);
                var opToken   = context.GetChild(opIndex).GetText();
                BinaryOperationNode equExpr;
                switch (opToken)
                {
                case "==":
                    equExpr = new EqualOperationNode(expr, rightExpr);
                    break;

                case "===":
                    equExpr = new CaseInsensitiveEqualOperationNode(expr, rightExpr);
                    break;

                case "!=":
                    equExpr = new NotEqualOperationNode(expr, rightExpr);
                    break;

                default:     // !==
                    equExpr = new CaseInsensitiveNotEqualOperationNode(expr, rightExpr);
                    break;
                }
                expr     = equExpr;
                opIndex += 2;
            }
            return(expr);
        }