Beispiel #1
0
        public override object VisitTerm([NotNull] CMMParser.TermContext context)
        {
            Object res = VisitChildren(context);
            Double op1, op2;

            if (context.ChildCount.Equals(3))
            {
                // 添加计算代码
                switch (context.GetChild(1).GetText())
                {
                case "*":
                    codes.Add(new IntermediateCode(InstructionType.mul, context.Start.Line));
                    // 计算当前表达式的值 以便万一要给数组分配大小
                    // op1 = (Double)expStack.Pop();
                    // op2 = (Double)expStack.Pop();
                    // expStack.Push(op2 * op1);
                    break;

                case "/":
                    codes.Add(new IntermediateCode(InstructionType.div, context.Start.Line));
                    // op1 = (Double)expStack.Pop();
                    // op2 = (Double)expStack.Pop();
                    // 计算当前表达式的值 以便万一要给数组分配大小
                    // expStack.Push(op2 / op1);

                    break;

                default:

                    break;
                }
            }
            else
            {
                // 不用处理
            }

            return(res);
        }
Beispiel #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="CMMParser.term"/>.
 /// <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 VisitTerm([NotNull] CMMParser.TermContext context)
 {
     return(VisitChildren(context));
 }
Beispiel #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="CMMParser.term"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitTerm([NotNull] CMMParser.TermContext context)
 {
 }