示例#1
0
 private void CodeReturn(ReturnStatement returnStatement, List<LocalVariable> locals, List<GlobalVariable> globals, FuncParam[] parameters, ILGenerator il, List<Function> allFuncs, LocalBuilder tmpVar)
 {
     CodeExpression(returnStatement.Expression, locals, globals, parameters, il, allFuncs, tmpVar);
     il.Emit(OpCodes.Ret);
 }
示例#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;
 }