コード例 #1
0
ファイル: Z80AsmVisitor.cs プロジェクト: stuurmn/spectnetide
        /// <summary>
        /// Visit a parse tree produced by <see cref="Generated.Z80AsmParser.shiftExpr"/>.
        /// </summary>
        /// <param name="context">The parse tree.</param>
        /// <return>The visitor result.</return>
        public override object VisitShiftExpr(Z80AsmParser.ShiftExprContext context)
        {
            if (IsInvalidContext(context))
            {
                return(null);
            }

            var expr           = (ExpressionNode)VisitAddExpr(context.GetChild(0) as Z80AsmParser.AddExprContext);
            var nextChildIndex = 2;

            while (nextChildIndex < context.ChildCount)
            {
                var rightExpr = VisitAddExpr(context.GetChild(nextChildIndex)
                                             as Z80AsmParser.AddExprContext);
                var opToken   = context.GetChild(nextChildIndex - 1).NormalizeToken();
                var shiftExpr = opToken == "<<"
                    ? new ShiftLeftOperationNode()
                    : new ShiftRightOperationNode() as BinaryOperationNode;

                shiftExpr.LeftOperand  = expr;
                shiftExpr.RightOperand = (ExpressionNode)rightExpr;
                expr            = shiftExpr;
                nextChildIndex += 2;
            }
            return(expr);
        }
コード例 #2
0
        public override object VisitShiftExpr(Z80AsmParser.ShiftExprContext context)
        {
            if (context == null)
            {
                return(null);
            }

            var subExprs = context.addExpr();
            var expr     = VisitAddExpr(subExprs[0]);
            var opIndex  = 1;

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

                default:     // >>
                    shiftExpr = new ShiftRightOperationNode(expr, rightExpr);
                    break;
                }
                expr     = shiftExpr;
                opIndex += 2;
            }
            return(expr);
        }
コード例 #3
0
 public ShiftLeftOperationNode(Z80AsmParser.ShiftExprContext context, Z80AsmVisitor visitor)
     : base(context, context.expr()[0], context.expr()[1], visitor)
 {
 }
コード例 #4
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="Z80AsmParser.shiftExpr"/>.
 /// <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 VisitShiftExpr([NotNull] Z80AsmParser.ShiftExprContext context)
 {
     return(VisitChildren(context));
 }
コード例 #5
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="Z80AsmParser.shiftExpr"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitShiftExpr([NotNull] Z80AsmParser.ShiftExprContext context)
 {
 }