Exemplo n.º 1
0
        /**
         *
         */
        public override object VisitAdditiveExpression([NotNull] CMMParser.AdditiveExpressionContext context)
        {
            Double           op1, op2;
            IntermediateCode code = new IntermediateCode(context.Start.Line);

            // 先遍历左右子树
            VisitChildren(context);
            if (context.ChildCount.Equals(3))
            {
                // 左右
                switch (context.GetChild(1).GetText())
                {
                case "+":
                    code.type = InstructionType.add;
                    // 计算当前表达式的值 以便万一要给数组分配大小
                    // op1 = (Double)expStack.Pop();
                    // op2 = (Double)expStack.Pop();
                    // expStack.Push(op2 + op1);
                    break;

                case "-":
                    code.type = InstructionType.sub;
                    // 计算当前表达式的值 以便万一要给数组分配大小
                    // op1 = (Double)expStack.Pop();
                    // op2 = (Double)expStack.Pop();
                    // expStack.Push(op2 - op1);
                    break;
                }
                codes.Add(code);
            }
            else
            {
                // 子树是term的情况 不用处理
            }


            return(null);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="CMMParser.additiveExpression"/>.
 /// <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 VisitAdditiveExpression([NotNull] CMMParser.AdditiveExpressionContext context)
 {
     return(VisitChildren(context));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="CMMParser.additiveExpression"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitAdditiveExpression([NotNull] CMMParser.AdditiveExpressionContext context)
 {
 }