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

            var expr           = (ExpressionNode)VisitUnaryExpr(context.GetChild(0) as Z80AsmParser.UnaryExprContext);
            var nextChildIndex = 2;

            while (nextChildIndex < context.ChildCount)
            {
                var rightExpr = VisitUnaryExpr(context.GetChild(nextChildIndex)
                                               as Z80AsmParser.UnaryExprContext);
                var opToken  = context.GetChild(nextChildIndex - 1).NormalizeToken();
                var multExpr = opToken == "*"
                    ? new MultiplyOperationNode()
                    : (opToken == "/"
                        ? new DivideOperationNode()
                        : new ModuloOperationNode() as BinaryOperationNode);

                multExpr.LeftOperand  = expr;
                multExpr.RightOperand = (ExpressionNode)rightExpr;
                expr            = multExpr;
                nextChildIndex += 2;
            }
            return(expr);
        }
Exemplo n.º 2
0
        public override object VisitMultExpr(Z80AsmParser.MultExprContext context)
        {
            if (context == null)
            {
                return(null);
            }

            var subExprs = context.minMaxExpr();
            var expr     = VisitMinMaxExpr(subExprs[0]);
            var opIndex  = 1;

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

                case "/":
                    mulExpr = new DivideOperationNode(expr, rightExpr);
                    break;

                default:     // %
                    mulExpr = new ModuloOperationNode(expr, rightExpr);
                    break;
                }
                expr     = mulExpr;
                opIndex += 2;
            }
            return(expr);
        }
Exemplo n.º 3
0
 public ModuloOperationNode(Z80AsmParser.MultExprContext context, Z80AsmVisitor visitor)
     : base(context, context.expr()[0], context.expr()[1], visitor)
 {
 }
Exemplo n.º 4
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="Z80AsmParser.multExpr"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitMultExpr([NotNull] Z80AsmParser.MultExprContext context)
 {
     return(VisitChildren(context));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="Z80AsmParser.multExpr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitMultExpr([NotNull] Z80AsmParser.MultExprContext context)
 {
 }