4 Pages

lab4

Course: ICOM 4029, Fall 2009
School: UPR Mayagüez
Rating:
 
 
 
 
 

Word Count: 650

Document Preview

of University Puerto Rico Mayagez Campus College of Engineering Department of Electrical and Computer Engineering ICOM4029 Compilers Professor: Bienvenido Vlez Technical Assistant: Ren D. Bada Laboratory 4 PA's 1 & 2 I. Solution to Programming Assignment 1 Here's a sample solution to PA1: class Stack inherits IO{ (* Class Stack uses roughly the same code as class List in the samples except that the...

Register Now

Unformatted Document Excerpt

Coursehero >> United States >> UPR Mayagüez >> ICOM 4029

Course Hero has millions of student submitted documents similar to the one
below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.

Course Hero has millions of student submitted documents similar to the one below including study guides, practice problems, reference materials, practice exams, textbook help and tutor support.
of University Puerto Rico Mayagez Campus College of Engineering Department of Electrical and Computer Engineering ICOM4029 Compilers Professor: Bienvenido Vlez Technical Assistant: Ren D. Bada Laboratory 4 PA's 1 & 2 I. Solution to Programming Assignment 1 Here's a sample solution to PA1: class Stack inherits IO{ (* Class Stack uses roughly the same code as class List in the samples except that the elements are Strings and some stack operations are added. It defines empty stacks. *) --isNil is used to check if the stack is empty isNil() : Bool {true}; --head returns the top element, which does not exist on empty --stacks so it is an error. top() : String { { abort(); ""; } }; --tail returns a Stack containing elements after the top element --This is an error on empty stacks. rest() : Stack { { abort(); self; } }; --push returns a new stack with argument "i" pushed. --If something is pushed, now the stack is not empty and is of --dynamic type NonEmptyStack. -i = the String to push into the stack push(i : String) : Stack { (new NonEmptyStack).init(i, self) }; --pop returns a new stack without the original top element. pop() : Stack{ rest() }; --print displays the contents of the stack. --It prints the top of the stack and then recursively prints --the rest. -l = the stack to be printed print(l : Stack) : Object { if l.isNil() then 0 else { out_string(l.top().concat("\n")); print(l.rest()); } fi }; }; class NonEmptyStack inherits Stack { -- Class NonEmptyStack defines non-empty stacks. top : String; --the top element rest : Stack; --a stack containing the rest of the elements isNil() : Bool { false }; top() : String { top }; rest() : Stack { rest }; -- Initializes a NonEmptyStack object -i = the initial top element -s = the initial stack with the rest of the elements init(i : String, s : Stack) : Stack { { top <- i; rest <- s; self; } }; }; class Main inherits IO { theStack : Stack <- new Stack; --the stack object inStr : String; --for storing the command x : Bool <- false; --for exiting the program loop temp1 : String; --for storing an element : temp2 String; --for storing a 2nd element --switch switches the top 2 elements of the stack switch() : Object { { -- temporarily store and pop the next 2 elements temp1 <- theStack.top(); theStack <- theStack.pop(); temp2 <- theStack.top(); theStack <- theStack.pop(); -- push them in reverse order theStack <- theStack.push(temp1); theStack <- theStack.push(temp2); } }; --sum adds the top 2 elements of the stack and pushes the result sum() : Object { let tempNum : Int, conv : A2I <- new A2I in { -- temporarily store and pop the the two operands temp1 <- theStack.top(); theStack <- theStack.pop(); temp2 <- theStack.top(); theStack <- theStack.pop(); -- calculate the sum } }; tempNum <- conv.a2i(temp1) + conv.a2i(temp2); -- push the result theStack <- theStack.push(conv.i2a(tempNum)); --eval does the following: -- *if the top is 's' then switch the following 2 elements -- *if it is '+', add the 2 following elements and store the sum -- *otherwise, do nothing eval() : Object { if theStack.isNil() then 0 else { -- get the top of the stack temp1 <- theStack.top(); if temp1 = "s" then { theStack <- theStack.pop(); --switch the following 2 elements switch(); } else if temp1 = "+" then { -...

Find millions of documents on Course Hero - Study Guides, Lecture Notes, Reference Materials, Practice Exams and more. Course Hero has millions of course specific materials providing students with the best way to expand their education.

Below is a small sample set of documents:

UPR Mayagüez - ICOM - 4029
University of Puerto Rico Mayagez Campus College of Engineering Department of Electrical and Computer Engineering ICOM4029 Compilers Professor: Bienvenido Vlez Technical Assistant: Ren D. BadaLaboratory 8 Semantic Analysis (continued) I. Role of
UPR Mayagüez - ICOM - 4036
ICOM 4015 Advanced ProgrammingLecture 13 Data Abstraction IReading: Chapter 6Prof. Bienvenido Vlez05/17/09ICOM 40151Data Abstraction Lecture Series Lecture 1 introduction to classes Lecture 2 encapsulation Lecture 3 class speciali
UPR Mayagüez - ICOM - 4036
Chapter 12 Topics Introduction Object-Oriented Programming Design Issues for Object-Oriented Languages Support for Object-Oriented Programming in Smalltalk Support for Object-Oriented Programming in C+ Support for Object-Oriented Programming in
UPR Mayagüez - ICOM - 4036
Variables, Names, Scope and LifetimeICOM 4036 Lecture 9ISBN 0-321-19362-8What is Variable? Imperative view A variable is an abstraction of a memory (state) cell Functional view A variable is an abstraction of a value Every definition int
UPR Mayagüez - ICOM - 4036
University of Puerto Rico Department of Electrical and Computer Engineering ICOM 4036: Programming Languages Spring 2006 Problem Set #1 (DUE Feb 15 In class) 1. Provide the state diagram for a Turing Machine recognizing the set of strings anbncn of e
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|03 Oct 2003 14:17:34 -0000 vti_extenderversion:SR|5.0.2.4330 vti_title:SR|Department of Electrical and Computer Engineering vti_backlinkinfo:VX|courses/spring2002/inel4206/inel4206.htm courses/Fall2003/
UPR Mayagüez - ICOM - 4015
IntroductionAdvanced Programming ICOM 4015 Lecture 1 Reading: Java Concepts Chapter 1Fall 2008Slides adapted from Java Concepts companion slides1Lecture Goals To understand the activity of programming To learn about machine code and high l
UPR Mayagüez - ICOM - 4015
ICOM 4015: Advanced ProgrammingLecture 2Reading: Chapter Two: Using ObjectsICOM 4015 Fall 2008Big Java by Cay Horstmann Copyright 2008 by John Wiley &amp; Sons. All rights reserved.Chapter Two: Using ObjectsICOM 4015 Fall 2008Big Java by Cay H
UPR Mayagüez - ICOM - 4015
ICOM 4015: Advanced ProgrammingLecture 4Chapter Four: Fundamental Data TypesICOM 4015 Fall 2008Big Java by Cay Horstmann Copyright 2008 by John Wiley &amp; Sons. All rights reserved.Chapter Four: Fundamental Data TypesICOM 4015 Fall 2008Big Jav
UPR Mayagüez - ICOM - 4015
ICOM 4015: Advanced ProgrammingLecture 5Chapter Five: DecisionsICOM 4015 Fall 2008Big Java by Cay Horstmann Copyright 2008 by John Wiley &amp; Sons. All rights reserved.Chapter Five: DecisionsBig Java by Cay Horstmann Copyright 2008 by John Wil
UPR Mayagüez - ICOM - 4015
ICOM 4015: Advanced ProgrammingLecture 8Chapter Eight: Designing ClassesICOM 4015 Fall 2008Big Java by Cay Horstmann Copyright 2008 by John Wiley &amp; Sons. All rights reserved.Chapter Eight: Designing ClassesBig Java by Cay Horstmann Copyright
UPR Mayagüez - ICOM - 4015
ICOM 4015: Advanced ProgrammingLecture 9Chapter Nine: Interfaces and PolymorphismICOM 4015 Fall 2008Big Java by Cay Horstmann Copyright 2008 by John Wiley &amp; Sons. All rights reserved.Chapter Nine: Interfaces and PolymorphismBig Java by Cay H
UPR Mayagüez - ICOM - 4015
ICOM 4015: Advanced ProgrammingLecture 10Chapter Ten: InheritanceICOM 4015 Fall 2008Big Java by Cay Horstmann Copyright 2008 by John Wiley &amp; Sons. All rights reserved.Chapter Ten: InheritanceBig Java by Cay Horstmann Copyright 2008 by John
UPR Mayagüez - ICOM - 4015
ICOM 4015: Advanced ProgrammingLecture 13Chapter Thirteen: RecursionICOM 4015 Fall 2008Big Java by Cay Horstmann Copyright 2008 by John Wiley &amp; Sons. All rights reserved.Chapter Thirteen: RecursionBig Java by Cay Horstmann Copyright 2008 b
UPR Mayagüez - ICOM - 4015
ICOM 4015: Advanced ProgrammingLecture 14Chapter Fourteen: Sorting and SearchingICOM 4015 Fall 2008Big Java by Cay Horstmann Copyright 2008 by John Wiley &amp; Sons. All rights reserved.Chapter Fourteen: Sorting and SearchingBig Java by Cay Hor
UPR Mayagüez - INEL - 4206
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|15 Jan 2003 14:53:06 -0000 vti_extenderversion:SR|5.0.2.3409 vti_title:SR|Department of Electrical and Computer Engineering vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|courses/spring200
UPR Mayagüez - ICOM - 4029
Department of Electrical and Computer Engineering University of Puerto Rico Mayagez CampusICOM 4029 Compilers Fall 2003Prof: Bienvenido Vlez Asistente: Arturo SilvaLaboratorio N 2: Ejecutando FLEX bajo LinuxObjetivos1. Entender la metodologa
UPR Mayagüez - ICOM - 4036
The Nature of ComputingICOM 4036 Lecture 2Prof. Bienvenido VelezSpring 2007ICOM 4036 Programming Laguages Lecture 21Some Inaccurate Yet Popular Perceptions of Computing Computing = Computers Computing = Programming Computing = Software
UPR Mayagüez - ICOM - 4036
Universidad de Puerto Rico Recinto Universitario de Mayagez Departamento de Ingeniera Elctrica y ComputadorasICOM 4036 Programming LanguagesOtoo 2004 Ejercicios de prctica Examen Parcial I 1. Add a STACK pointer register to the Easy I Data Path.
UPR Mayagüez - ICOM - 4036
ICOM 4036: PROGRAMMING LANGUAGESLecture 5 Functional Programming The Case of Scheme 05/17/09Required Readings Texbook (Scott PLP) Chapter 11 Section 2: Functional Programming Scheme Language Description Revised Report on the Algorithmic Langu
UPR Mayagüez - INEL - 4206
Universidad de Puerto Rico Recinto Universitario de MayagezINEL 4206 MicroprocesadoresPrimavera 2002 Ejercicios de prctica Examen Parcial I 1. Processor Implementation. Add an instruction BrL (Branch and link) to the Easy I processor designed in
UPR Mayagüez - INEL - 4206
INEL 4206 Fall 2002 Exmen I Nombre: _5/17/09 Seccin: _Anota tu nombre y nmero de seccin en todas las hojas del examen AHORA! (penalidad de 5 puntos)Tienes 2 horas para completar tres problemas. Lee cuidadosamente todo el examen antes de empezar
UPR Mayagüez - INEL - 4206
INEL 4206 Fall 2002 Exmen I Nombre: _5/17/09Anota tu nombre y nmero de seccin en todas las hojas del examen AHORA! (penalidad de 5 puntos)Tienes 2 horas para completar todos los problemas. Lee cuidadosamente todo el examen antes de empezar a tra
UPR Mayagüez - ICOM - 4015
ICOM 4015 Advanced ProgrammingLecture 9 Data Abstraction II Class Specialization Subtype PolymorphismProf. Bienvenido Vlez05/17/09ICOM 40151Inheritance Subtype Polymorphism Outline Defining derived classes Member inheritance Method over
UPR Mayagüez - INEL - 4206
Easy IControl Unit(Level 3 Flowcharts) fetchop1DI&lt;0:9&gt; ABUS AOFetchOpfetchop2AO EAB EDB DI00 11x00 00x00 branch on opcode 100 101 0000 01000 011opcodeaoprsoprloadstorebrnjumpFall 2002INEL 4206 Microprocessors
UPR Mayagüez - INEL - 4206
The Nature of ComputingINEL 4206 Microprocessors Lecture 2Bienvenido Vlez Ph. D. School of Engineering University of Puerto Rico - MayagezSome Inaccurate (Although Popular) Perceptions of Computing Computing = (Electronic) Computers Computing
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|15 Jan 2004 16:25:08 -0000 vti_extenderversion:SR|5.0.2.4330 vti_title:SR|Department of Electrical and Computer Engineering vti_syncwith_ece.uprm.edu\:21/public_html:TX|15 Jan 2004 16:25:08 -0000 vti_sy
UPR Mayagüez - INEL - 4206
Universidad de Puerto Rico Recinto Universitario de MayagezINEL 4206 MicroprocesadoresPrimavera 2002 Ejercicios de prctica Examen Parcial I 1. Processor Implementation. Add an instruction BrL (Branch and link) to the Easy I processor designed in
UPR Mayagüez - INEL - 4206
INEL 4206 Spring 2002 Exmen II Nombre: _5/17/09 Seccin: _Anota tu nombre y nmero de seccin en todas las hojas del examen AHORA! (penalidad de 5 puntos)Tienes 2 horas para completar tres problemas. Lee cuidadosamente todo el examen antes de empez
UPR Mayagüez - ICOM - 4036
Universidad de Puerto Rico Recinto Universitario de MayagezICOM 4036 Programming LanguagesOtoo 2003 Ejercicios de prctica Examen Parcial II 1. Write a logic program in Prolog to compute the greatest common divisor (GCD) of 2 integer arguments. Th
UPR Mayagüez - ICOM - 4029
Programming Assignments Dates Happy Hour October 15 November 22 December 14-16PA 3 (Parser) 4a (Semantic Analyzer) 4b 5a (Code Generator) 5bHand-out Date September 29 October 11 October 25 November 15 November 29Deadline October 11 October 25 N
UPR Mayagüez - INEL - 4206
Evaluacion Curso INEL 4206 Segundo Examen.Menciona los aspectos que ms te gustan de la clase INEL 4206 en orden decreciente de importancia.AspectoEl uso de las transparencias en la clase y tener un buen Web-Site para el curso.Porcentaje37.09
UPR Mayagüez - INEL - 4206
Universidad de Puerto Rico Mayaguez Department of Electrical and Computer Engineering INEL 4206 Microprocessors Exam III Summary of Topics Review all previous material up to Exam II Procedures o Parameter Passing o Stack frames o Recursive proce
UPR Mayagüez - ICOM - 4015
Sus contestaciones al problemario 2 deben ser entregadas electrnicamente por e-mail siguiendo las siguientes instrucciones.0. Crear un directorio para almacenar los archivos relacionados con cadaproblemario. No tiene que hacer este paso si ya lo h
UPR Mayagüez - ICOM - 4015
Department of Electrical and Computer Engineering University of Puerto Rico Mayagez ICOM 4015 Advanced Programming Fall 2006 Exam I Practice Exercises and Problem Set 1 DUE: September 14, 2006 In class 1) Create a new Eclipse project titled icom4015
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_author:SR|BVWS\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timelastmodified:TR|15 Aug 2005 18:50:12 -0000 vti_timecreated:TR|08 Nov 2004 11:08:29 -0000 vti_title:SR|Universidad de Puerto Rico vti_extenderversion:SR|5.0.2.6417
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|29 Aug 2005 18:28:44 -0000 vti_extenderversion:SR|5.0.2.6417 vti_author:SR|CHURCH\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timecreated:TR|20 Jan 2004 16:01:58 -0000 vti_title:SR|Chapter 1 vti_nexttolast
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|18 Oct 2005 18:41:18 -0000 vti_extenderversion:SR|5.0.2.6417 vti_author:SR|CHURCH\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timecreated:TR|04 Sep 2003 17:25:30 -0000 vti_title:SR|Imperative Programming T
UPR Mayagüez - PA - 4029
ICOM 4029 Compiler Writing 1HandoutProgramming Assignment I1 Due Friday, September 3, 2004 at 11:59pmThis assignment asks you to write a short Cool program. The purpose is to acquaint you with the Cool language and to give you experience with so
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|13 Oct 2004 16:46:56 -0000 vti_extenderversion:SR|5.0.2.6417 vti_author:SR|CHURCH\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timecreated:TR|04 Sep 2003 17:25:30 -0000 vti_title:SR|Imperative Programming T
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|11 May 2004 18:57:00 -0000 vti_extenderversion:SR|5.0.2.4803 vti_backlinkinfo:VX|courses/Fall2004/icom4036/icom4036.htm courses/Spring2004/icom4036/icom4036.htm vti_author:SR|CHURCH\bvelez vti_modifiedb
UPR Mayagüez - INEL - 4206
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|25 Nov 2002 14:19:52 -0000 vti_extenderversion:SR|5.0.2.3409 vti_author:SR|CHURCH\bvelez vti_modifiedby:SR|CHURCH\bvelez vti_timecreated:TR|22 Nov 2002 13:30:27 -0000 vti_title:SR|Problema vti_assignedt
UPR Mayagüez - ICOM - 4015
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|30 Jan 2001 13:43:12 -0000 vti_extenderversion:SR|4.0.2.4426 vti_backlinkinfo:VX|courses/spring2001/icom4015/icom4015.htm vti_cacheddtm:TX|30 Jan 2001 13:43:12 -0000 vti_filesize:IR|42496 vti_cachedlink
UPR Mayagüez - ICOM - 4015
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|18 Sep 2001 12:37:56 -0000 vti_extenderversion:SR|4.0.2.4426 vti_filesize:IR|60416 vti_title:SR|ICOM 4015 Advanced Programming vti_assignedto:SR| vti_approvallevel:SR| vti_backlinkinfo:VX|courses/fall20
UPR Mayagüez - ICOM - 4015
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|14 Nov 2001 16:22:06 -0000 vti_extenderversion:SR|4.0.2.4426 vti_backlinkinfo:VX|courses/fall2001/icom4015/icom4015.htm vti_filesize:IR|44544 vti_title:SR|ICOM 4015 Advanced Programming vti_syncwith_ece
UPR Mayagüez - PA - 4029
ICOM 4029 Compiler WritingHandout 4Programming Assignment IV1 A Semantic Analyzer for COOLDue Friday, November 14, 2003i.IntroductionIn this assignment you will implement the static semantics of Cool. You will use the abstract syntax trees
UPR Mayagüez - ICOM - 4015
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|02 Oct 2001 15:15:56 -0000 vti_extenderversion:SR|5.0.2.4803 vti_title:SR| vti_backlinkinfo:VX|courses/fall2001/icom4015/icom4015.htm vti_syncwith_ece.uprm.edu\:21/public_html:TX|02 Oct 2001 15:15:56 -0
UPR Mayagüez - ICOM - 4015
vti_encoding:SR|utf8-nl vti_author:SR|Michael vti_timecreated:TR|29 Feb 2000 02:30:38 -0000 vti_timelastmodified:TR|27 Mar 2000 14:32:00 -0000 vti_filesize:IR|50176 vti_title:SR|ICOM 4015 Advanced Programming vti_assignedto:SR| vti_approvallevel:SR|
UPR Mayagüez - ICOM - 4015
vti_encoding:SR|utf8-nl vti_author:SR|Michael vti_timecreated:TR|29 Feb 2000 02:30:38 -0000 vti_timelastmodified:TR|27 Mar 2000 14:32:00 -0000 vti_filesize:IR|59904 vti_title:SR|ICOM 4015 Advanced Programming vti_assignedto:SR| vti_approvallevel:SR|
UPR Mayagüez - ICOM - 4029
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|04 Oct 2004 20:46:56 -0000 vti_extenderversion:SR|5.0.2.6417 vti_author:SR|BVWS\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timecreated:TR|04 Oct 2004 20:46:56 -0000 vti_cacheddtm:TX|04 Oct 2004 20:46:56 -
UPR Mayagüez - ICOM - 4029
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|04 Oct 2004 20:46:56 -0000 vti_extenderversion:SR|5.0.2.6417 vti_author:SR|BVWS\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timecreated:TR|04 Oct 2004 20:46:56 -0000 vti_cacheddtm:TX|04 Oct 2004 20:46:56 -
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|05 Apr 2005 17:18:26 -0000 vti_extenderversion:SR|5.0.2.6417 vti_author:SR|CHURCH\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timecreated:TR|19 Mar 2004 16:55:12 -0000 vti_title:SR|Universidad de Puerto Ri
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|08 Nov 2004 11:17:18 -0000 vti_extenderversion:SR|5.0.2.6417 vti_author:SR|BVWS\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timecreated:TR|08 Nov 2004 11:17:18 -0000 vti_cacheddtm:TX|08 Nov 2004 11:17:18 -
UPR Mayagüez - ICOM - 4036
vti_encoding:SR|utf8-nl vti_author:SR|BVWS\bvelez vti_modifiedby:SR|BVWS\bvelez vti_timelastmodified:TR|08 Nov 2004 11:08:29 -0000 vti_timecreated:TR|08 Nov 2004 11:08:29 -0000 vti_cacheddtm:TX|08 Nov 2004 11:02:46 -0000 vti_filesize:IR|36352 vti_cac
UPR Mayagüez - ICOM - 4029
vti_encoding:SR|utf8-nl vti_timelastmodified:TR|27 Aug 2003 18:35:04 -0000 vti_extenderversion:SR|5.0.2.4330 vti_author:SR|CHURCH\bvelez vti_modifiedby:SR|CHURCH\bvelez vti_timecreated:TR|20 Aug 2003 18:05:26 -0000 vti_title:SR|Introduction to Progra