DOC PREVIEW
Berkeley COMPSCI 164 - Lecture Notes

This preview shows page 1-2-24-25 out of 25 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 25 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Overview of MiniJavaCourse AdministrationAndrew Appel, the textbook author is at Princeton UniversityWhy the change?MJ OverviewReminscent of the novel Gadsby by Ernest WrightFrom page one of Gadsby …Anyway, Lexical matters in MJ are reasonable subsetRestrictions that are major simplifications in MJ vs JavaSemantics: what does an MJ program compute?Semantics: Is this just a cheap trick?Java and even more so, MJ, can be written in LispMJ Primitive Types, ConstructorsMJ variables live in classes or instancesMethods are really functionsInformation Hiding in MJPrint is really very weakMJ has rather simplistic object oriented stuff in itMJ TypesMJ Type Checking: any holes?Other components: Expressions, StatementsMJ Memory ManagementCourse ProjectCourse Project / IIProgramming Assignment IProf. Fateman CS 164 Lecture 4 1Overview of MiniJavaLecture 4Prof. Fateman CS 164 Lecture 4 2Course Administration•If you drop the course, please make it official•If you are on the waiting list, see Michael-David Sasson in 379 Soda Hall• I think that anyone enrolled can get ID card registered to get into Soda Hall after hours.–Go to CS reception (Soda Hall 3rd floor)•Questions about course policies?Prof. Fateman CS 164 Lecture 4 3Andrew Appel, the textbook author is at Princeton University•The first version of our text used a language named “Tiger” (the Princeton mascot). Designed by Appel for teaching about compilers.•Why is designing a new language and describing it so hard?•Why?–Except if it is trivial, there are many little details.–Describing a language: how? Axiomatically? Informally? Operationally?.Prof. Fateman CS 164 Lecture 4 4Why the change?–Except if it is trivial, there are many little details to a language that must be nailed down. •Syntax•Semantics•Pragmatics–Tiger was simple/tricky/boring.(?)–How to be formal yet readable? Definition Axiomatically? Informally? Operationally?.Prof. Fateman CS 164 Lecture 4 5MJ Overview•MJ is a language that is supposed to be strictly a subset of Java.•Designed to–Provide a useful one-semester exercise–Give a taste of implementation of modern•Abstraction•Static typing•Memory management•Object Oriented implementation of functions•How to leave out things?Prof. Fateman CS 164 Lecture 4 6Reminscent of the novel Gadsby by Ernest Wright•The entire manuscript of Gadsby was written in a subset of the English language. Namely, without the letter “e” •http://www.spinelessbooks.com/gadsby/Prof. Fateman CS 164 Lecture 4 7A child’s brain starts functioning at birth; and has, amongst its many infant convolutions, thousands of dormant atoms, into which God has put a mystic possibility for noticing an adult’s act, and figuring out its purport. Up to about its primary school days a child thinks, naturally, only of play. But many a form of play contains disciplinary factors. “You can’t do this,” or “that puts you out,” shows a child that it must think, practically or fail. Now, if, throughout childhood, a brain has no opposition, it is plain that it will attain a position of “status quo,” as with our ordinary animals. Man knows not why a cow, dog or lion was not born with a brain on a par with ours; why such animals cannot add, subtract, or obtain from books and schooling, that paramount position which Man holds today.But a human brain is not in that class. Constantly throbbing and pulsating, it rapidly forms opinions; attaining an ability of its own; a fact which is startlingly shown by an occasional child “prodigy” in music or school work. And as, with our dumb animals, a child’s inability convincingly to impart its thoughts to us, should not class it as ignorant.From page one of Gadsby …Prof. Fateman CS 164 Lecture 4 8Anyway, Lexical matters in MJ are reasonable subset•Identifiers begin with a letter•Integers and Booleans (true, false) are the only basic data types.•Binary arithmetic or logical operators are && < + - *•Additional operators are ()[]{}=.!;•NO Strings. NO floats.•Comments are /* */ or // to end of line. NOT nested, contrary to p. 484.Prof. Fateman CS 164 Lecture 4 9Restrictions that are major simplifications in MJ vs Java•There is a main class with additional class declarations at the top level.•No overloading.•No classes defined within classes.•All methods are public.•No initializers by calling <name of> class•No INPUT (all data must be literal integers in the program body).Prof. Fateman CS 164 Lecture 4 10Semantics: what does an MJ program compute?•Conditions for an alleged MJ program to be legal.1. The program must grammatically fit in the terms of the (page 485) MiniJava grammar.2. The program must be legal Java. In which caseThe meaning of the MJ program is the same as the corresponding Java program.•Why does this help?–There is a readily available reference implementation (javac, java)–There are (many) books, including some standards, that can provide informal descriptions, formal descriptions, examples.Prof. Fateman CS 164 Lecture 4 11Semantics: Is this just a cheap trick? •Yes, but you probably think you know Java, so you might not mind.•Even if you don’t know Java–There is a readily available reference implementation (javac, java) for your computer.–There are (many) books, including some standards, that can provide informal descriptions, formal descriptions, examples of Java programs.–There are examples of MJ programs in the text’s web site (also locally)Prof. Fateman CS 164 Lecture 4 12Java and even more so, MJ, can be written in Lisp•Java’s authors were influenced by Common Lisp (G.L. Steele, Jr. especially), for example, implicit pointers (like lisp, not C)•Lisp, Java, and MJ all use garbage collection: We don’t have to write one, which is what would have to be done if we implemented MJ in C.•We can implement operations in Lisp that are supersets of MJ and then cut them off at the knees if we want to be strict. E.g. Lisp can read integers of any length (or operate on them). A strict implementation would truncate them to what’s legal in Java.Prof. Fateman CS 164 Lecture 4 13MJ Primitive Types, Constructors•Integer•Boolean•No strings, characters, floats•Ways of combining•Arrays•ClassesProf. Fateman CS 164 Lecture 4 14MJ variables live in classes or instances•The value for “a” is [a pointer to] a record with a slot for each attribute. class Point {


View Full Document

Berkeley COMPSCI 164 - Lecture Notes

Documents in this Course
Lecture 8

Lecture 8

40 pages

Load more
Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?