added new tri files

java11
simonkellet 2 years ago
parent a4c304f58d
commit 7c64cb7eff
  1. 46
      programs/add.tri
  2. 30
      programs/errorsfix.tri

@ -0,0 +1,46 @@
! Program that will: read two ints, print their sum and their product. If they are the same, print "Same"
! Global Consts, Funcs.
let
type String ~ array 6 of Char; ! String type implemented, not used yet
var num1 : Integer;
var num2 : Integer;
func sum(x : Integer, y : Integer) : Integer ~
x + y; ! Return x + y
func product(x : Integer, y : Integer) : Integer ~
x * y; ! Return x * y
func isSame(x : Integer, y : Integer) : Boolean ~
if x = y then true else false
! Main Loop
in
begin
num1 := 0;
num2 := 0; ! Init. values to 0
getint(var num1);
getint(var num2); ! Get user input
! Sum
putint(num1); put('+'); put(' '); putint(num2); put(' '); put('='); put(' ');
putint(sum(num1, num2)); puteol();
puteol();
! Product
putint(num1); put(' '); put('*'); put(' '); putint(num2); put(' '); put('='); put(' ');
putint(product(num1, num2)); puteol();
if isSame(num1, num2) = true then
put('S'); put('a'); put('m'); put('e'); puteol();
else
puteol();
end

@ -0,0 +1,30 @@
! Program with a variety of contextual errors.
let
type String ~ array 4 of Char;
type Name ~ array 3 of String;
type Rec ~ record x: Integer, x: Integer end;
var me: Name;
var silly : maxint;
var silly: Rec;
proc putstr (s: String) ~
let var i: Integer
in
begin
s[4] := ' ';
i := 0;
while i do
begin i := i+true;
put (s[\i])
end
end
in
begin
me[true] := ['T','i','n','y'];
me[2][2] := 0;
put (me[1]); put (4); put ();
putstr (initials (me)); puteol ()
end