Пример #1
0
        /*
         * 处理赋值操作,
         * 前提:leftValue将待赋值的变量在局部变更量表中的索引已经压入栈中,expression处理的结果已经压入操作栈中
         */
        public override object VisitAssignment([NotNull] CMMParser.AssignmentContext context)
        {
            Visit(context.leftValue());

            // tmp是一个虚拟的变量,用于 存储leftVal的索引 在局部变量表的位置
            int tmp = curLocalVariablesTableLength;

            // 把leftVal的值放到局部变更量表Count位置上
            IntermediateCode code0 = new IntermediateCode(tmp, InstructionType.pop, context.leftValue().Start.Line);

            codes.Add(code0);

            // 把Expression的值压入栈中
            Visit(context.expression());

            //将Experession的值放入Count中
            IntermediateCode code1 = new IntermediateCode("(" + tmp + ")", InstructionType.pop, context.expression().Start.Line);

            // 这个过程中,局部变量表并没有增加新的元素,所以curLocalVariable并没有Add操作
            codes.Add(code1);

            // 局部变量表里面,1号位置的值是0
            return(null);
        }
Пример #2
0
 /// <summary>
 /// Visit a parse tree produced by <see cref="CMMParser.assignment"/>.
 /// <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 VisitAssignment([NotNull] CMMParser.AssignmentContext context)
 {
     return(VisitChildren(context));
 }
Пример #3
0
 /// <summary>
 /// Exit a parse tree produced by <see cref="CMMParser.assignment"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitAssignment([NotNull] CMMParser.AssignmentContext context)
 {
 }