Example #1
0
 private void CodeIf(IfStatement ifStatement, List<LocalVariable> locals, List<GlobalVariable> globals, FuncParam[] parameters, ILGenerator il,
     Stack<Label> breaks, List<Function> allFuncs, LocalBuilder tmpVar)
 {
     var trueJmp = il.DefineLabel();
     CodeExpression(ifStatement.Condition, locals, globals, parameters, il, allFuncs, tmpVar);
     il.Emit(OpCodes.Brtrue_S, trueJmp);
     CodeStatement(ifStatement.FalseStatement, locals, globals, parameters, il, breaks, allFuncs, tmpVar);
     il.MarkLabel(trueJmp);
     CodeStatement(ifStatement.TrueStatement, locals, globals, parameters, il, breaks, allFuncs, tmpVar);
 }
Example #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;
 }