예제 #1
0
        private void CodeWhile(WhileStatement whileStatement, List<LocalVariable> locals, List<GlobalVariable> globals, FuncParam[] parameters, ILGenerator il,
            Stack<Label> breaks, List<Function> allFuncs, LocalBuilder tmpVar)
        {
            var endLabel = il.DefineLabel();
            var startLabel = il.DefineLabel();
            breaks.Push(endLabel);

            il.MarkLabel(startLabel);
            CodeExpression(whileStatement.Condition, locals, globals, parameters, il, allFuncs, tmpVar);
            il.Emit(OpCodes.Brfalse_S, endLabel);
            CodeStatement(whileStatement.Statement, locals, globals, parameters, il, breaks, allFuncs, tmpVar);
            il.Emit(OpCodes.Br_S, startLabel);

            il.MarkLabel(breaks.Pop());
        }
예제 #2
0
 private Statement Smth()
 {
     Statement st = null;
     if (_la == Terminals.Id || _la == Terminals.Num || _la == Terminals.LPar || _la == Terminals.Minus ||
         _la == Terminals.Inv)
     {
         st = Expr();
         Expect(Terminals.Semicolon);
     }
     else if (_la == Terminals.Return)
     {
         Get();
         var r = Expr();
         Expect(Terminals.Semicolon);
         st = new ReturnStatement(r);
     }
     else if (_la == Terminals.Read)
     {
         Get();
         var v = Expect(Terminals.Id) as Id;
         Expect(Terminals.Semicolon);
         st = new ReadStatement(v);
     }
     else if (_la == Terminals.Write)
     {
         Get();
         var r = Expr();
         Expect(Terminals.Semicolon);
         st = new WriteStatement(r);
     }
     else if (_la == Terminals.Writeln)
     {
         Get();
         Expect(Terminals.Semicolon);
         st = new WritelnStatement();
     }
     else if (_la == Terminals.Break)
     {
         Get();
         Expect(Terminals.Semicolon);
         st = new BreakStatement();
     }
     else if (_la == Terminals.If)
     {
         Get();
         Expect(Terminals.LPar);
         var c = Expr();
         Expect(Terminals.RPar);
         var t = Smth();
         Expect(Terminals.Else);
         var f = Smth();
         st = new IfStatement(c, t, f);
     }
     else if (_la == Terminals.While)
     {
         Get();
         Expect(Terminals.LPar);
         var c = Expr();
         Expect(Terminals.RPar);
         var s = Smth();
         st = new WhileStatement(c, s);
     }
     else if (_la == Terminals.Start)
     {
         st = Block();
     }
     else
         SynErr(37);
     return st;
 }