fork download
  1. #include <iostream>
  2. #include <ostream>
  3. #include <sstream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int level = 0;
  9. void print_indent()
  10. {
  11. cout << string(level*4,' ');
  12. }
  13.  
  14. class Integer
  15. {
  16. string name;
  17. public:
  18. Integer()
  19. {
  20. static int counter = 0;
  21. stringstream ss;
  22. ss << "var" << (++counter);
  23. name = ss.str();
  24. print_indent();
  25. cout << "int " << name << "=0;" << endl;
  26. }
  27. Integer &operator++()
  28. {
  29. print_indent();
  30. cout << "++" << name << ";" << endl;
  31. return *this;
  32. }
  33. Integer &operator=(const Integer &rhs)
  34. {
  35. print_indent();
  36. cout << name << "=" << rhs.name << ";" << endl;
  37. return *this;
  38. }
  39. };
  40. class Block
  41. {
  42. bool done;
  43. public:
  44. Block()
  45. : done(false)
  46. {
  47. print_indent();
  48. cout << "{" << endl;
  49. ++level;
  50. }
  51. bool next()
  52. {
  53. return !done;
  54. }
  55. void after()
  56. {
  57. --level;
  58. print_indent();
  59. cout << "}" << endl;
  60. done = true;
  61. }
  62. };
  63.  
  64. #define BLOCK for(Block b##__LINE__;b##__LINE__.next();b##__LINE__.after())
  65.  
  66. int main()
  67. {
  68. BLOCK {
  69. Integer a,b;
  70. a=b;
  71. ++a;
  72. Integer c;
  73. BLOCK
  74. a=b=c;
  75. ++b;
  76. BLOCK {
  77. b=++a;
  78. c=++a;
  79. }
  80. }
  81. }
Success #stdin #stdout 0s 3040KB
stdin
Standard input is empty
stdout
{
    int var1=0;
    int var2=0;
    var1=var2;
    ++var1;
    int var3=0;
    {
        var2=var3;
        var1=var2;
    }
    ++var2;
    {
        ++var1;
        var2=var1;
        ++var1;
        var3=var1;
    }
}