Exemplo n.º 1
0
        /*
         * 访问do while表达式
         */
        public override object VisitDoWhileStatement([NotNull] CMMParser.DoWhileStatementContext context)
        {
            // addr0是codeBlock开始地址
            int addr0 = codes.Count;

            Visit(context.codeBlock());

            IntermediateCode code0 = new IntermediateCode(0, InstructionType.push, context.expression().Start.Line);

            // 查看expression的结果
            Visit(context.expression());

            // 比较expression的结果和0的关系,如果不相等的话,就要跳转回去执行codeBlock
            IntermediateCode code1 = new IntermediateCode(addr0, InstructionType.jne, context.expression().Start.Line);

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