Eliezer A. Albacea
University of the Philippines OPEN UNIVERSITY
Principles of Programming Languages By Eliezer A. Albacea
Copyright © 2002 by Eliezer A. Albacea and the University of the Philippines Open University Apart from any fair use for the purpose of research or private study, criticism or review, this publication may be reproduced, stored or transmitted, in any form or by any means ONLY WITH THE PERMISSION of the author and the UP Open University.
Published in the Philippines by the UP Open University Office of Academic Support and Instructional Services 2/F, National Computer Center CP Garcia Avenue, Diliman, Quezon City 1101 Telephone (63-2)426-1515 Email email@example.com First printing, 2002 Second printing, 2005
Layout by Helen Mercado Creer
Printed in the Philippines
This book is intended for a one-semester course on programming languages. It discusses the basic concepts of programming languages and the actual implementation of basic programming language constructs which makes it different from other language programming books that stop after a discussion of the concepts. As a teacher for many years, I believe it is best to teach and learn concepts when we put them to use. In this case, to implement the language. You should at least have a basic knowledge of the syntax of a variety of programming languages like Pascal, C. FORTRAN, Algol, COBOL, Prolog, Lisp, and ML, though a working knowledge of Pascal and C is sufficient. I used the intermediate language Slim+ as the target language for for translation. Slim+ is a simple stack-oriented language with very simple instructions that can be mapped to any actual machine instrucitons. As an additional aid both for students and teachers, Slim+ is discussed in the Appendix. I strongly advise the reader to take up this topic before proceeding to Module 3 and before tackling the first topic on implementation. Finally, the book is provided with Self-Assessment Questions (SAQs) with the solutions found in the Answers to Self-Assessment Questions (ASAQs) at the end of each module. I thank the staff of the Institute of Computer Science, University of the Philippines at Los Baños who were so well behaved while I was busy writing this book. To John Patrick VJ. Albacea and Zita VJ. Albacea who inspired me. And my gratefulness to many others who have contributed to this book. Despite my best efforts and the help of many, some errors may still have remained unspotted—typographical, grammatical, or even on the codes and the text. I will greatly appreciate your effort to bring any mistakes and lapses to my attention; that they may be corrected in future revisions of this book.
Eliezer A. Albacea, PhD. Institute of Computer Science University of the Philippines Los Baños
About the Author
Dr. Eliezer A. Albacea finished his Ph.D. in Computer Science at the Australian National University, his MSc (Honours) in Computing Science at the University of Wollongong, and his BS in Statistics (cum laude) at the University of the Philippines, Los Baños (UPLB). He is Professor of Computer Science, currently the Director of the Institute of Computer Science, UPLB and chair of the Mathematical Sciences Division of the National Research Council of the Philippines. He was the Director of the University of the Philippines System Computer Science Program from January 1996 to August 1999. He is also a member of the Technical Panel for Information Technology Education of the Commission on Higher Education (CHED), a member of the Technical Panel on Information Technology of the Department of Science and Technology (DOST), and a member of the Science and Technology Strategic Thinkers of the DOST from 1993 to 1997. He has written at least 50 technical papers in computer science published in international and national journals and in proceedings of international and national conferences. Among the awards...