University of Texas at El Paso
Banner
Compuer Science
   
Assignment 1 Minimize    

Compilers and Interpreters: Assignment 1

September 7, 2010

The purpose of this assignment is for you to start getting familiar with the Triangle programming language. In this assignment, you have to write a Triangle program that takes as input a line of text, and transforms it into a palindrome by first forming the reverse of the line and then concatenating the original line.

Here is the Triangle program that reverses a line, taken from our textbook, section B.9.

let 
	type Line ~
		record
			length: Integer,
			content: array 80 of Char
		end;

	proc getline (var l: Line) ~
		begin
		l.length := 0;
		while \ eol() do
			begin
			get(var l.content[l.length]);
			l.length := l.length + 1
			end;
		geteol()
		end;

	proc putreversedline (l: Line) ~
		let var i : Integer
		in
			begin
			i := l.length;
			while i > 0 do
				begin
				i := i - 1;
				put(l.content[i])
				end;
			puteol()
			end;

	var currentline: Line

in
	while \ eof() do
		begin
		getline(var currentline);
		putreversedline(currentline)
		end

Due Thursday, September 16, at the start of class, or 11pm if sent by e-mail. Hand in:

  1. a printout of your Triangle program,
  2. a printout of the TAM code produced by compiling your code,
  3. a printout or a screenshot of the result of running the program,
  4. any documentation you think I should have.