Programming Languages

Total Page:16

File Type:pdf, Size:1020Kb

Programming Languages Programming Languages Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2002–2010 · 09/15/10 01:29:19 PM The Tower of Babel Several ways to solve a transportation problem A story about the origins of multiple languages. • [After the flood] “the whole earth was of one language and one speech.” • They built a city and tower at Babel, believing that with a single language, people will be able to do anything they imagine. • Yahweh disagrees and “confounds the language of all the earth” • Why? Proliferation of cultural differences (and multiple languages) is one basis of civilization. 3 4 Several ways to solve a programming problem Java You can write a Java program. ThreeSum.java public class ThreeSum { public static void main(String[] args) { int N = Integer.parseInt(args[0]); int[] a = new int[N]; for (int i = 0; i < N; i++) a[i] = StdIn.readInt(); for (int i = 0; i < N; i++) for (int j = i+1; j < N; j++) for (int k = j+1; k < N; k++) if (a[i] + a[j] + a[k] == 0) StdOut.println(a[i] + " " + a[j] + " " + a[k]); } } % more 8ints.txt 30 -30 -20 -10 40 0 10 5 Ex. Read N int values from standard input; % javac ThreeSum.java % java ThreeSum 8 < 8ints.txt print triples that sum to 0. 30 -30 0 30 -20 -10 [See lecture 8] -30 -10 40 -10 0 10 5 6 C A big difference between C and Java (there are many!) You can also write a C program. ThreeSum.c No data abstraction #include <stdio.h> • no objects in C #include <stdlib.h> C program is sequence of static methods main(int argc, char *argv[]) • { int N = atoi(argv[1]); int *a = malloc(N*sizeof(int)); int i, j, k; for (i = 0; i < N; i++) C++ (Stroustrup 1989) scanf("%d", &a[i]); for (i = 0; i < N; i++) • “C with classes” for (j = i+1; j < N; j++) adds data abstraction to C for (k = j+1; k < N; k++) • if (a[i] + a[j] + a[k] == 0) printf("%4d %4d %4d\n", a[i], a[j], a[k]); } % more 8ints.txt 30 -30 -20 -10 40 0 10 5 Noticable differences: % cc ThreeSum.c library conventions % ./a.out 8 < 8ints.txt array creation idiom 30 -30 0 30 -20 -10 standard input idiom -30 -10 40 -10 0 10 pointer manipulation (stay tuned) 7 8 C++ C++ You can also write a C++ program. BST.cxx template <class Item, class Key> Ex 1. Use C++ like C Ex 2. Use C++ like Java class ST ThreeSum.cxx { private: #include <iostream.h> struct node #include <stdlib.h> { Item item; node *l, *r; int N; main(int argc, char *argv[]) Challenges: node(Item x) { { item = x; l = 0; r = 0; N = 1; } int N = atoi(argv[1]); libraries/idioms }; int *a = new int[N]; pointer manipulation typedef node *link; int i, j, k; link head; for (i = 0; i < N; i++) templates (generics) Item nullItem; cin >> a[i]; for (i = 0; i < N; i++) Item searchR(link h, Key v) for (j = i+1; j < N; j++) { if (h == 0) return nullItem; for (k = j+1; k < N; k++) Key t = h->item.key(); if (a[i] + a[j] + a[k] == 0) if (v == t) return h->item; cout << a[i] << " " << a[j] << " " << a[k] << endl; if (v < t) return searchR(h->l, v); } else return searchR(h->r, v); % cpp ThreeSum.cxx % ./a.out 8 < 8ints.txt } 30 -30 0 ... Noticable differences: 30 -20 -10 } library conventions -30 -10 40 -10 0 10 standard I/O idioms 9 10 A big difference between C/C++ and Java (there are many!) Python Programs directly manipulate pointers You can write a Python program! C/C++: You are responsible for memory allocation Ex 1. Use python as a calculator • system provides memory allocation library • programs explicitly “allocate” and “free” memory for objects % python • C/C++ programmers must learn to avoid “memory leaks” Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05) Type "help" for more information. >>> 2+2 Java: Automatic “garbage collection”. 4 >>> (1 + sqrt(5))/2 Traceback (most recent call last): C code that reuses an array name File "<stdin>", line 1, in <module> Java code that reuses an array name NameError: name 'sqrt' is not defined double arr[] = >>> import math calloc(5,sizeof(double)); double[] arr = new double[5]; >>> (1 + math.sqrt(5))/2 ... ... 1.618033988749895 free(arr); arr = new double[10]; arr = calloc(10, sizeof(double)); Fundamental challenge: Code that manipulates pointers is inherently “unsafe”. 11 12 Python Compile vs. Interpret You can write a Python program! Def. A compiler translates your entire program to (virtual) machine code. Def. An interpreter simulates a (virtual) machine running your code Ex 2. Use Python like you use Java on a line-by-line basis. Noticable differences: threesum.py no braces (indents instead) import sys def main(): no type declarations threesum.c a.out N = int(sys.argv[1]) array creation idiom a = [0]*N I/O idioms C C compiler machine for i in range(N): source code code a[i] = int(sys.stdin.readline()) for (iterable) idiom for i in range(N): for j in range(i+1, N): range(8) is [0, 1, 2, 3, 4, 5, 6, 7] threesum.py for k in range(j+1, N): if (a[i] + a[j] + a[k]) == 0: Python print repr(a[i]).rjust(4), Python interpreter Another example: TOY (Lecture 11) source code print repr(a[j]).rjust(4), % python threesum.py 8 < 8ints.txt print repr(a[k]).rjust(4) 30 -30 0 main() 30 -20 -10 -30 -10 40 ThreeSum.java ThreeSum.class -10 0 10 “javac” “java” Java Java compiler JVM interpreter source code code 13 14 A big difference between Python and C/C++/Java (there are many!) Matlab No compile-time type checking Python programmers must remember You can write a Matlab program! their variable names and types • no need to declare types of variables • system checks for type errors at RUN time Ex 1. Use Matlab like you use Java. ... Implications: for i = 0:N-1 for j = i+1:N-1 • Easier to write small programs. for k = j+1:N-1 More difficult to debug large programs. if (a(i) + a(j) + a(k)) == 0: • sprintf("%4d %4d %4d\n", a(i), a(j), a(k)); end end Typical (nightmare) scenario: end end • Scientist/programmer misspells variable name ... referring to output file in large program. • Program runs for hours or days. Ex 2 (more typical). Use Matlab for matrix processing. Using Python for large problems • Crashes without writing results. is like playing with fire. A = [1 3 5; 2 4 7] B = [-5 8; 3 9; 4 0] -5 8 1 3 5 24 35 Reasonable approaches C = A*B 3 9 2 4 7 * = 30 52 C = 4 0 • Throw out your calculator; use Python. 24 35 • Prototype in Python, then convert to Java for “production” use. 30 52 15 16 Big differences between Matlab and C/C++/Java/Python (there are many!) Why Java? [revisited from second lecture] 1. Matlab is not free. Java features. 2. Most Matlab programmers use only ONE data type (matrix). • Widely used. • Widely available. • Embraces full set of modern abstractions. • Variety of automatic checks for mistakes in programs. i = 0 Ex. Matlab code “ ” “redefine the value of the complex number i to be a 1-by-1 matrix whose entry is 0” Facts of life. No language is perfect. Notes: • “There are only two kinds of programming Matlab is written in Java. • We need to choose some language. • languages: those people always [gripe] • The Java compiler and interpreters are written in C. about and those nobody uses.” [Modern C compilers are written in C.] Our approach. – Bjarne Stroustrup • Matrix libraries (written in C) accessible from C/C++/Java/Python. • Minimal subset of Java. • Develop general programming skills Reasonable approach: that are applicable to many languages • Use Matlab as a “matrix calculator” (if you own it). Convert to or use Java or Python if you want to do anything else. • It’s not about the language! 17 18 Why do we use Java in COS 126? Why learn another programming language? Good reasons to learn a programming language: full set of modern automatic widely widely offers something new (see next slide) modern libraries checks • used available abstractions and systems for bugs • need to interface with legacy code or with coworkers • better than Java for the application at hand ✓ ✓ ✗ ✗ ✓ • intellectual challenge (opportunity to learn something about computation) ✓ ✓ ✓ maybe ✓ ✓ ✓ ✓ ✓ ✓ ✓ $ maybe* ✓ ✗ ✓ ✓ maybe ✓ ✗ * OOP recently added but not embraced by most users 19 20 Something new: a few examples Programming styles 1960s: Assembly language Procedural • symbolic names • step-by-step instruction execution model • relocatable code • Ex: C 1970s: C Scripted • “high-level” language (statements, conditionals, loops) • step-by-step command execution model, usually interpreted • machine-independent code • Ex: Python, Javascript basic libraries • Special purpose optimized around certain data types 1990s: C++/Java • • Ex: Postscript, Matlab • data abstraction (object-oriented programming) • extensive libraries Object-oriented (next) • focus on objects that do things 2000s: Javascript/PHP/Ruby/Flash • Ex: Java, C++ • scripting Functional (stay tuned) • libraries for web development • focus on defining functions • Ex: Scheme, Haskell, Ocaml 21 22 Object Oriented Programming Procedural programming. [verb-oriented] Object-Oriented Programming • Tell the computer to do this. • Tell the computer to do that. A different philosophy. Software is a simulation of the real world. • We know (approximately) how the real world works.
Recommended publications
  • SJC – Small Java Compiler
    SJC – Small Java Compiler User Manual Stefan Frenz Translation: Jonathan Brase original version: 2011/06/08 latest document update: 2011/08/24 Compiler Version: 182 Java is a registered trademark of Oracle/Sun Table of Contents 1 Quick introduction.............................................................................................................................4 1.1 Windows...........................................................................................................................................4 1.2 Linux.................................................................................................................................................5 1.3 JVM Environment.............................................................................................................................5 1.4 QEmu................................................................................................................................................5 2 Hello World.......................................................................................................................................6 2.1 Source Code......................................................................................................................................6 2.2 Compilation and Emulation...............................................................................................................8 2.3 Details...............................................................................................................................................9
    [Show full text]
  • Object-Oriented Programming Basics with Java
    Object-Oriented Programming Object-Oriented Programming Basics With Java In his keynote address to the 11th World Computer Congress in 1989, renowned computer scientist Donald Knuth said that one of the most important lessons he had learned from his years of experience is that software is hard to write! Computer scientists have struggled for decades to design new languages and techniques for writing software. Unfortunately, experience has shown that writing large systems is virtually impossible. Small programs seem to be no problem, but scaling to large systems with large programming teams can result in $100M projects that never work and are thrown out. The only solution seems to lie in writing small software units that communicate via well-defined interfaces and protocols like computer chips. The units must be small enough that one developer can understand them entirely and, perhaps most importantly, the units must be protected from interference by other units so that programmers can code the units in isolation. The object-oriented paradigm fits these guidelines as designers represent complete concepts or real world entities as objects with approved interfaces for use by other objects. Like the outer membrane of a biological cell, the interface hides the internal implementation of the object, thus, isolating the code from interference by other objects. For many tasks, object-oriented programming has proven to be a very successful paradigm. Interestingly, the first object-oriented language (called Simula, which had even more features than C++) was designed in the 1960's, but object-oriented programming has only come into fashion in the 1990's.
    [Show full text]
  • Java (Programming Langua a (Programming Language)
    Java (programming language) From Wikipedia, the free encyclopedialopedia "Java language" redirects here. For the natural language from the Indonesian island of Java, see Javanese language. Not to be confused with JavaScript. Java multi-paradigm: object-oriented, structured, imperative, Paradigm(s) functional, generic, reflective, concurrent James Gosling and Designed by Sun Microsystems Developer Oracle Corporation Appeared in 1995[1] Java Standard Edition 8 Update Stable release 5 (1.8.0_5) / April 15, 2014; 2 months ago Static, strong, safe, nominative, Typing discipline manifest Major OpenJDK, many others implementations Dialects Generic Java, Pizza Ada 83, C++, C#,[2] Eiffel,[3] Generic Java, Mesa,[4] Modula- Influenced by 3,[5] Oberon,[6] Objective-C,[7] UCSD Pascal,[8][9] Smalltalk Ada 2005, BeanShell, C#, Clojure, D, ECMAScript, Influenced Groovy, J#, JavaScript, Kotlin, PHP, Python, Scala, Seed7, Vala Implementation C and C++ language OS Cross-platform (multi-platform) GNU General Public License, License Java CommuniCommunity Process Filename .java , .class, .jar extension(s) Website For Java Developers Java Programming at Wikibooks Java is a computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few impimplementation dependencies as possible.ble. It is intended to let application developers "write once, run ananywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to rurun on another. Java applications ns are typically compiled to bytecode (class file) that can run on anany Java virtual machine (JVM)) regardless of computer architecture. Java is, as of 2014, one of tthe most popular programming ng languages in use, particularly for client-server web applications, witwith a reported 9 million developers.[10][11] Java was originallyy developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems'Micros Java platform.
    [Show full text]
  • The Java® Language Specification Java SE 8 Edition
    The Java® Language Specification Java SE 8 Edition James Gosling Bill Joy Guy Steele Gilad Bracha Alex Buckley 2015-02-13 Specification: JSR-337 Java® SE 8 Release Contents ("Specification") Version: 8 Status: Maintenance Release Release: March 2015 Copyright © 1997, 2015, Oracle America, Inc. and/or its affiliates. 500 Oracle Parkway, Redwood City, California 94065, U.S.A. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. The Specification provided herein is provided to you only under the Limited License Grant included herein as Appendix A. Please see Appendix A, Limited License Grant. To Maurizio, with deepest thanks. Table of Contents Preface to the Java SE 8 Edition xix 1 Introduction 1 1.1 Organization of the Specification 2 1.2 Example Programs 6 1.3 Notation 6 1.4 Relationship to Predefined Classes and Interfaces 7 1.5 Feedback 7 1.6 References 7 2 Grammars 9 2.1 Context-Free Grammars 9 2.2 The Lexical Grammar 9 2.3 The Syntactic Grammar 10 2.4 Grammar Notation 10 3 Lexical Structure 15 3.1 Unicode 15 3.2 Lexical Translations 16 3.3 Unicode Escapes 17 3.4 Line Terminators 19 3.5 Input Elements and Tokens 19 3.6 White Space 20 3.7 Comments 21 3.8 Identifiers 22 3.9 Keywords 24 3.10 Literals 24 3.10.1 Integer Literals 25 3.10.2 Floating-Point Literals 31 3.10.3 Boolean Literals 34 3.10.4 Character Literals 34 3.10.5 String Literals 35 3.10.6 Escape Sequences for Character and String Literals 37 3.10.7 The Null Literal 38 3.11 Separators
    [Show full text]
  • Simula Mother Tongue for a Generation of Nordic Programmers
    Simula! Mother Tongue! for a Generation of! Nordic Programmers! Yngve Sundblad HCI, CSC, KTH! ! KTH - CSC (School of Computer Science and Communication) Yngve Sundblad – Simula OctoberYngve 2010Sundblad! Inspired by Ole-Johan Dahl, 1931-2002, and Kristen Nygaard, 1926-2002" “From the cold waters of Norway comes Object-Oriented Programming” " (first line in Bertrand Meyer#s widely used text book Object Oriented Software Construction) ! ! KTH - CSC (School of Computer Science and Communication) Yngve Sundblad – Simula OctoberYngve 2010Sundblad! Simula concepts 1967" •# Class of similar Objects (in Simula declaration of CLASS with data and actions)! •# Objects created as Instances of a Class (in Simula NEW object of class)! •# Data attributes of a class (in Simula type declared as parameters or internal)! •# Method attributes are patterns of action (PROCEDURE)! •# Message passing, calls of methods (in Simula dot-notation)! •# Subclasses that inherit from superclasses! •# Polymorphism with several subclasses to a superclass! •# Co-routines (in Simula Detach – Resume)! •# Encapsulation of data supporting abstractions! ! KTH - CSC (School of Computer Science and Communication) Yngve Sundblad – Simula OctoberYngve 2010Sundblad! Simula example BEGIN! REF(taxi) t;" CLASS taxi(n); INTEGER n;! BEGIN ! INTEGER pax;" PROCEDURE book;" IF pax<n THEN pax:=pax+1;! pax:=n;" END of taxi;! t:-NEW taxi(5);" t.book; t.book;" print(t.pax)" END! Output: 7 ! ! KTH - CSC (School of Computer Science and Communication) Yngve Sundblad – Simula OctoberYngve 2010Sundblad!
    [Show full text]
  • Building Useful Program Analysis Tools Using an Extensible Java Compiler
    Building Useful Program Analysis Tools Using an Extensible Java Compiler Edward Aftandilian, Raluca Sauciuc Siddharth Priya, Sundaresan Krishnan Google, Inc. Google, Inc. Mountain View, CA, USA Hyderabad, India feaftan, [email protected] fsiddharth, [email protected] Abstract—Large software companies need customized tools a specific task, but they fail for several reasons. First, ad- to manage their source code. These tools are often built in hoc program analysis tools are often brittle and break on an ad-hoc fashion, using brittle technologies such as regular uncommon-but-valid code patterns. Second, simple ad-hoc expressions and home-grown parsers. Changes in the language cause the tools to break. More importantly, these ad-hoc tools tools don’t provide sufficient information to perform many often do not support uncommon-but-valid code code patterns. non-trivial analyses, including refactorings. Type and symbol We report our experiences building source-code analysis information is especially useful, but amounts to writing a tools at Google on top of a third-party, open-source, extensible type-checker. Finally, more sophisticated program analysis compiler. We describe three tools in use on our Java codebase. tools are expensive to create and maintain, especially as the The first, Strict Java Dependencies, enforces our dependency target language evolves. policy in order to reduce JAR file sizes and testing load. The second, error-prone, adds new error checks to the compilation In this paper, we present our experience building special- process and automates repair of those errors at a whole- purpose tools on top of the the piece of software in our codebase scale.
    [Show full text]
  • SUBJECT-COMPUTER CLASS-12 CHAPTER 9 – Compiling and Running Java Programs
    SUBJECT-COMPUTER CLASS-12 CHAPTER 9 – Compiling and Running Java Programs Introduction to Java programming JAVA was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language. Writing, compiling and debugging a program is easy in java. It helps to create modular programs and reusable code. Bytecode javac compiler of JDK compiles the java source code into bytecode so that it can be executed by JVM. The bytecode is saved in a .class file by compiler. Java Virtual Machine (JVM) This is generally referred as JVM. Before, we discuss about JVM lets see the phases of program execution. Phases are as follows: we write the program, then we compile the program and at last we run the program. 1) Writing of the program is of course done by java programmer. 2) Compilation of program is done by javac compiler, javac is the primary java compiler included in java development kit (JDK). It takes java program as input and generates java bytecode as output. 3) In third phase, JVM executes the bytecode generated by compiler. This is called program run phase. So, now that we understood that the primary function of JVM is to execute the bytecode produced by compiler. Characteristics of Java Simple Java is very easy to learn, and its syntax is simple, clean and easy to understand. Multi-threaded Multithreading capabilities come built right into the Java language. This means it is possible to build highly interactive and responsive apps with a number of concurrent threads of activity.
    [Show full text]
  • Coqjvm: an Executable Specification of the Java Virtual Machine Using
    CoqJVM: An Executable Specification of the Java Virtual Machine using Dependent Types Robert Atkey LFCS, School of Informatics, University of Edinburgh Mayfield Rd, Edinburgh EH9 3JZ, UK [email protected] Abstract. We describe an executable specification of the Java Virtual Machine (JVM) within the Coq proof assistant. The principal features of the development are that it is executable, meaning that it can be tested against a real JVM to gain confidence in the correctness of the specification; and that it has been written with heavy use of dependent types, this is both to structure the model in a useful way, and to constrain the model to prevent spurious partiality. We describe the structure of the formalisation and the way in which we have used dependent types. 1 Introduction Large scale formalisations of programming languages and systems in mechanised theorem provers have recently become popular [4–6, 9]. In this paper, we describe a formalisation of the Java virtual machine (JVM) [8] in the Coq proof assistant [11]. The principal features of this formalisation are that it is executable, meaning that a purely functional JVM can be extracted from the Coq development and – with some O’Caml glue code – executed on real Java bytecode output from the Java compiler; and that it is structured using dependent types. The motivation for this development is to act as a basis for certified consumer- side Proof-Carrying Code (PCC) [12]. We aim to prove the soundness of program logics and correctness of proof checkers against the model, and extract the proof checkers to produce certified stand-alone tools.
    [Show full text]
  • Chapter 9: Java
    ,ch09.6595 Page 159 Friday, March 25, 2005 2:47 PM Chapter 9 CHAPTER 9 Java Many Java developers like Integrated Development Environments (IDEs) such as Eclipse. Given such well-known alternatives as Java IDEs and Ant, readers could well ask why they should even think of using make on Java projects. This chapter explores the value of make in these situations; in particular, it presents a generalized makefile that can be dropped into just about any Java project with minimal modification and carry out all the standard rebuilding tasks. Using make with Java raises several issues and introduces some opportunities. This is primarily due to three factors: the Java compiler, javac, is extremely fast; the stan- dard Java compiler supports the @filename syntax for reading “command-line param- eters” from a file; and if a Java package is specified, the Java language specifies a path to the .class file. Standard Java compilers are very fast. This is primarily due to the way the import directive works. Similar to a #include in C, this directive is used to allow access to externally defined symbols. However, rather than rereading source code, which then needs to be reparsed and analyzed, Java reads the class files directly. Because the symbols in a class file cannot change during the compilation process, the class files are cached by the compiler. In even medium-sized projects, this means the Java com- piler can avoid rereading, parsing, and analyzing literally millions of lines of code compared with C. A more modest performance improvement is due to the bare mini- mum of optimization performed by most Java compilers.
    [Show full text]
  • Lecture 1: Introduction to Java®
    Lecture 1: Introduction to Java MIT-AITI Kenya 2005 1 Lecture Outline • What a computer program is • How to write a computer program • The disadvantages and advantages of using Java • How a program that you write in Java is changed into a form that your computer can understand • Sample Java code and comments MIT-Africa Internet Technology Initiative ©2005 2 Computer Program vs. Food Recipe Food Recipe Computer Program A chef writes a set of A programmer writes a set of instructions called a recipe instructions called a program The recipe requires specific The program requires specific ingredients inputs The cook follows the The computer follows the instructions step-by-step instructions step-by-step The food will vary depending on The output will vary depending the amount of ingredients and on the values of the inputs and the cook the computer MIT-Africa Internet Technology Initiative ©2005 3 Recipe and Program Examples Student’s Student’s Ingredient # 1 Ingredient # 2 Name Grade Recipe Program Dinner “Bilha got an A on the exam!” MIT-Africa Internet Technology Initiative ©2005 4 What is a computer program? • For a computer to be able to perform specific tasks (i.e. print what grade a student got on an exam), it must be given instructions to do the task • The set of instructions that tells the computer to perform specific tasks is known as a computer program MIT-Africa Internet Technology Initiative ©2005 5 Writing Computer Programs • We write computer programs (i.e. a set of instructions) in programming languages such as C, Pascal, and
    [Show full text]
  • Programming Languages: Design and Implementation
    طراحی و پیادهسازی زبان های برنامهسازی Programming Languages: Design and Implementation 40364 نیمسال دوم 1400 - 1399 slide 1 اهداف درس سیر طبیعی تحوﻻت مفاهیم و روش های طراحی و پیادهسازی نسل های مختلف زبان های برنامهسازی به روشی تجربی و گام به گام مهندسی زبان های برنامه سازی )زبان های ویژه دامنه( آشنایی با پیاده سازی مفسرها به ویژه بر بستر ماشین های مجازی اصول طراحی زبان های برنامه سازی و روش ها و ساختارهای داده ای به کار رفته در پیادهسازی یا محقق کردن محیط برنامه نویسی ایجاد توانایی ارزیابی، مقایسه و انتخاب میان زبان های برنامه سازی موجود برنامه سازی تابعی معناشناسی و استدﻻل پیرامون برنامه slide 2 Grading and Other Admin affairs Your grade components: • Final Exam • Mid Term Exam • Assignments (paper based) • Assignments (programming including a final project) • Class Presentation … Class Administration Policies: slide 3 Main References Daniel P. Friedman and Mitchell Wand, Essentials of Programming Languages, 3rd Edition, MIT Press, 2008. M.Felleisen, R.Findler, M.Flatt, S.Krishnamurthi, E.Barzilay, J.McCarthy, S.Tobin-Hochstadt, A Programmable Programming Language, Communications of the ACM, Vol. 61, No. 3, Pp. 62-71, March 2018. https://racket-lang.org/ My class and Slides slide 4 Other Useful General Text Books S.Krishnamurthi, Programming Languages: Application and Interpretation, 2nd Edition, http://cs.brown.edu/courses/cs173/2012/book/b ook.pdf, 2017. Peter Sestoft, Programming Language Concepts, 2nd Edition, 2017. Michael Scott, Programming Language Pragmatics, (with its complimentary CD) slide 5 Other Useful General Text Books
    [Show full text]
  • Metaprogramming: Interpretaaon Interpreters
    How to implement a programming language Metaprogramming InterpretaAon An interpreter wriDen in the implementaAon language reads a program wriDen in the source language and evaluates it. These slides borrow heavily from Ben Wood’s Fall ‘15 slides. TranslaAon (a.k.a. compilaAon) An translator (a.k.a. compiler) wriDen in the implementaAon language reads a program wriDen in the source language and CS251 Programming Languages translates it to an equivalent program in the target language. Spring 2018, Lyn Turbak But now we need implementaAons of: Department of Computer Science Wellesley College implementaAon language target language Metaprogramming 2 Metaprogramming: InterpretaAon Interpreters Source Program Interpreter = Program in Interpreter Machine M virtual machine language L for language L Output on machine M Data Metaprogramming 3 Metaprogramming 4 Metaprogramming: TranslaAon Compiler C Source x86 Target Program C Compiler Program if (x == 0) { cmp (1000), $0 Program in Program in x = x + 1; bne L language A } add (1000), $1 A to B translator language B ... L: ... x86 Target Program x86 computer Output Interpreter Machine M Thanks to Ben Wood for these for language B Data and following pictures on machine M Metaprogramming 5 Metaprogramming 6 Interpreters vs Compilers Java Compiler Interpreters No work ahead of Lme Source Target Incremental Program Java Compiler Program maybe inefficient if (x == 0) { load 0 Compilers x = x + 1; ifne L } load 0 All work ahead of Lme ... inc See whole program (or more of program) store 0 Time and resources for analysis and opLmizaLon L: ... (compare compiled C to compiled Java) Metaprogramming 7 Metaprogramming 8 Compilers... whose output is interpreted Interpreters..
    [Show full text]