Compiler Construction 95.3002 Compiler Construction
My Background Introduced “Regular Right Part Grammars” in my PhD thesis from Univ. Waterloo in 1975. Google it. Smalltalk expert, co-author of 3 books, Inside Smalltalk, Vols. 1 and 2, and Smalltalk/V: Practice and Experience, and sole author of Discovering Smalltalk, 32 refereed papers, 89 “Smalltalk Column” articles in JOOP (Journal of Object-Oriented Programming) Game engine expert. Published a game (MultiWorld Racing) on the iPhone and Android (racing/exploration in an infinite but small world; no longer available). Had employees working with me building a PC game which became the basis for mobile version. A number of my former employees working for Silicon Knights (Jeff Giffen) and Rock Star Games (Nan Ma, Adriaan Blaauw) Previous courses taught – “Advanced Shaders” and other 4th year gaming courses.
Marking Scheme Assignments 60% Exam 40% Assignments To ensure we really understand Letter grades only Exam 40% To force review and retention Assignments Actual assignments and how many is a work in progress More assignments than last year but less complex. #0: Setting up Unmarked #1: Implementing Scanners and Parsers #2: Implementing Finite State Machines #3: Building Scanner/Parsing Tables (First half) #4: Building Readback Tables (Second half) #5: Simple Code Generation
Times Class: Tues/Thurs 8:30am (1.5 hours) 202 Tory Building Help sessions: Mon/Thurs 6pm 5345 Herzberg Also, Saturday 9am Totally voluntary Help with programming details. Watch others work. See status of other people’s work… I will be there. I will also stay as late as you do. I can be there on other days if you want. seminar room (no computers) If you don’t have your own computer, I can look in on you periodically in labs that have machines Few assignments can be done in 1 lab session, many in 2, some need 3.
Implementation Language 2 Years ago – Required Smalltalk Privately Allowed 3 people using Java + 1 Person using Ruby Only Ruby implementor finished Last Year – Allowed other languages but recommended Smalltalk 2 people using Java + 1 Person using Python All finished but Java group switched to Smalltalk after first assignment Usually get a handful of people dropping out because of the heavy workload (only early dropouts, no late dropouts)
What the Course Aimed to Teach Compiler technology. Compiler constructor technology. What the Assignments Aimed to Do To end up with your own tool that could be used for developing a real compiler of your own (for your portfolio of achievements) None of the assignments were independent (each needed the previous one to be able to work)
What’s Different This Year Compiler technology. Compiler constructor technology. What the Assignments Aim to Do To develop subsets of the code needed to build a compiler constructor When done, you’ll understand how to build the tool but won’t have a working tool. If you really want to have a complete working tool, I can provide extra help for you to do it if you want.
What Else is Different More encouragement for other languages but … some of the notes are in Smalltalk You have to at least be able to translate from Smalltalk to your language choice. Since the assignments are more standalone, they can be done in any language. We’ll provide 2 assignments paths (the standalone path and the tools path where each assignment requires the previous one). I consider the tool path to be more work but more rewording.
Why Do I Recommend Smalltalk More object-oriented than Java Java: A number like 123 is an int (a primitive value). It is not an object. Java: Each slot in the array can hold an object or a primitive value but you can’t mix them. You can’t have an array of Apples OR ints. Smalltalk, Ruby, Python: allow collections of anything; including ints, Dogs, and even classes. Classes are not objects in C++. They are in Java. More object-oriented than Java or Ruby Java or Ruby: Control structures are built-in. There is no method corresponding to a for-loop. Smalltalk: allow you to reimplement existing control structures and to define new one. It’s the reason we call Smalltalk a “fast prototyping” language.
Why Do I Recommend Smalltalk More object-oriented than Java or C++ Smalltalk: Objects have instance methods and class methods both of which uses inheritance. Java and C++ have static methods. It supports inheritance but not generally. The internet struggles to explain how static methods work. The answer is that it supports “compile time” inheritance only. Friendlier meta-level facilities than Java You have the name of a method in a variable. How do you execute it. Java has a syntax that says “I don’t want you to do this” but I will allow you if you really really really want to.
What is Smalltalk Most Known For? Keyword based messages Java: object1 . between (object2, object3) Smalltalk: object1 between: object2 and: object3 No dot Keywords The name of the method is between:and: Smalltalk: 100 factorial No colon if there are no parametters Note that it’s CONSISTENTLY receiver first, message (i.e., selector and parameters) second Smalltalk: Array new: 10 Java: new int [10] Implication: More bracket needed (sometimes) Smalltalk: object1 between: (3 raisedTo: 3.14) and: object3 Means what it says Smalltalk: object1 between: 3 raisedTo: 3.14 and: object3 Selector is between:raisedTo:and:
What’s Annoying About Smalltalk Uses := for assignment and . for end of statement. But a = b is equality comparison, == is identity comparison, a := 5. is an assignment statement Uses square brackets [ and ] instead of braces { and }, single quotes for strings instead of double quotes, and “;” is also used. ‘this is a string’ versus character $a 1 to: 10 do: [:k | Transcript space; << k.] Send a second message to the same receiver Since square brackets are taken, you can’t subscript with them. Other languages: a [p] = b [q] Smalltalk: a at: p put: (b at: q) The Smalltalk we use for the course is old. Not supported natively on Macs Some people used virtual machines to get around the problem. The School is willing to put Smalltalk on some lab machines if you want it. There are other courses that need virtual machines too.
Knowing Java Knowing Smalltalk Helps you program in non-object oriented languages Java programmers structure C programs better than those who don’t understand object oriented programming Knowing Smalltalk Helps you program in other object oriented languages like Ruby or Python Smalltalk programmers structure Ruby and Python programs better than those who just know Java. They can also use their meta-level facilities better since they get used to doing it in Smalltalk.