TEXT 142
Lexically-ok.txt By admin on 24th October 2021 06:35:39 PM
  1. // This program should print the number 20.
  2. program Twenty:
  3.   int a;
  4.   int b;
  5.   a := 2;
  6.   b := 1;
  7.   if not (a < 0) then
  8.     int b;
  9.     b := - 2;     //     (the inner b, the outer one is still 1)
  10.     a := a * b    // a = -4
  11.   else
  12.     int c;
  13.     c := a - b;
  14.     a := a * (c - b)
  15.   fi;
  16.   print a * (a - b)    // -4 * (-4 - 1)  =  -4 * (-5)  =  20
  17. end
  18. // This program should print the number 20.
  19. program Twenty:
  20.   int a;
  21.   int b;
  22.   a := 2;
  23.   b := 1;
  24.   while a >= 0 do
  25.     int b;
  26.     b := - 2;     // (the inner b, the outer one is still 1)
  27.     a := a * b    // a = -4
  28.   od;
  29.   print a * (a - b)    // -4 * (-4 - 1)  =  -4 * (-5)  =  20
  30. end
  31.  // This program should print the number 20.
  32. program Twenty2:
  33.   int a;
  34.   int b;
  35.   a : = 2;
  36.   b := 1;
  37.   if not (a < 0) then
  38.     int b;
  39.     b := - 2;     //     (the inner b, the outer one is still 1)
  40.     a := a * b    // a = -4
  41.   else
  42.     int c;
  43.     c := a - b;
  44.     a := a * (c - b)
  45.   fi;
  46.   print a * (a - b)    // -4 * (-4 - 1)  =  -4 * (-5)  =  20
  47. end
  48. // Euclid's algorithm for the greatest common divisor.
  49. program GCD:
  50.    int a;  int b;
  51.    a := 15;
  52.    b := 20;
  53.    print a;  print b;
  54.    while a != b do
  55.       if a < b then b := b - a
  56.       else a := a - b
  57.       fi
  58.    od;
  59.    print a
  60. end
  61. program Hiding :
  62.    int a;
  63.    int b;
  64.    a := 2;
  65.    b := 5;
  66.    while not (a != b) do
  67.      int b;
  68.      b := 2 * a;
  69.      print b;
  70.      a := a + 1
  71.    od;
  72.    print b
  73. end
  74. program condtional:
  75.   if 3 < 3 then
  76.     print false
  77.   fi
  78. end
  79. program condtional2 :
  80.   if 3<3 then print false fi
  81. end
  82. program lexicallyOk :
  83.    intt a;
  84.    int b;
  85.    a :== 2;
  86.    b := 5;
  87.    while (a != b) do not print else do
  88.      int b;
  89.      b := 2 *** a;
  90.      print b;
  91.      a := a + 1
  92.    od;
  93.    print b
  94. end
  95. program lexically-Ok-2
  96.    program Print:
  97.   print(77)
  98. end
  99. program bad_expression:
  100.    int a;
  101.    int b;
  102.    if4 a < b then5
  103.      2int b;
  104.      b := 2 * a
  105.    5else
  106.      bool b;
  107.      b := 2 * a
  108.    fii
  109. end

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.