Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prof Fateman CS 164 Lecture 371 Review: Programming Languages and Compilers CS164 9-10AM MWF 10 Evans.

Similar presentations


Presentation on theme: "Prof Fateman CS 164 Lecture 371 Review: Programming Languages and Compilers CS164 9-10AM MWF 10 Evans."— Presentation transcript:

1

2 Prof Fateman CS 164 Lecture 371 Review: Programming Languages and Compilers CS164 9-10AM MWF 10 Evans

3 Prof Fateman CS 164 Lecture 372 Aministrivia Sample final questions will be posted Projects (rather than exams) will probably be weighted more for grades. Final Exam is Dec 18, morning We agreed that it should be closed book, but 3 pages, (6 sides) of your handwritten notes can be taken to the exam.

4 Prof Fateman CS 164 Lecture 373 Review: Why Should you Study Compilers/ Programming Languages? Increased capacity to express ideas Improved background for choosing appropriate tools / languages Increased ability to learn “new” languages or design new ones Better understanding of the interchange between implementation and design Appreciation of the beauty of relevant material from CS 61a/b/c CS170, Math 55

5 Prof Fateman CS 164 Lecture 374 What can you do with your new skills? Understand/ be a TA/ for CS61a/b/c Or a reader for CS164 Appreciate CS188 (since you know Lisp better!) Take graduate courses CS 264, 263 Take graduate course CS282 (W,F, 9:30) taught by Prof. Fateman: Algebraic Algorithms: need some math, CS164, Lisp helps Get a high-paying job

6 Prof Fateman CS 164 Lecture 375 Recall: The Course Project A big project. Written in Common Lisp. … in several easy parts Why Lisp? –Typical JAVA/C++ project code size: 5,000 lines –Typical Lisp code size: 2000 lines. –You are given 1000 lines in “skeletons” either way, so the ratio is about 4:1 in favor of Lisp –You all know Scheme; CL is a superset.

7 Prof Fateman CS 164 Lecture 376 Important: how did the pieces fit together? You must know the form of the input for each module You must know the form of the output for each module We didn’t ask you to write an interpreter, but we could have… What was the point of the interpreter? –Defined the language –Allowed us to TEST TIGER PROGRAMS –Could be used to resolve disputes, ambiguities

8 Prof Fateman CS 164 Lecture 377 Recall: How are Languages Implemented? Two major strategies: –Interpreters (simple, general, faster setup) –Compilers (complex, popular, faster runtime) Interpreters run programs with only modest processing; often easily portable to many hosts. Compilers do extensive preprocessing, some of it to target specific machine architectures.

9 Prof Fateman CS 164 Lecture 378 Interpreters and Compilers Both: Read in “source code” Construct some model of the program Provide error messages Adhere to some “execution model” of the programming language.

10 Prof Fateman CS 164 Lecture 379 Language Implementations Batch compilation systems dominate many production environments; Optimizes for fast runtime. Some languages are primarily interpreted –Java bytecode Lisp provides both –Interpreter for fast development/debugging –Typechecking compiler for faster running

11 Prof Fateman CS 164 Lecture 3710 The Structure of a Typical Compiler 1.Lexical Analysis 2.Parsing 3.Semantic Analysis 4.Optimization 5.Code Generation

12 Prof Fateman CS 164 Lecture 3711 Lexical Analysis (The “lexer” or “scanner”) First step: recognize words. –Smallest unit above letters –Some relation to finite state machines and regular expressions. (We could still ask questions about these on the final) let type tt={foo:int,bar:int} var xx:tt:=nil in 3 end (let let (1. 3)) (type type (1. 8)) (id tt (1. 11)) (= = (1. 12)) ({ { (1. 13)) (id foo (1. 16)) (|:| |:| (1. 17)) (id int (1. 20)) (|,| |,| (1. 21)) (id bar (1. 24)) (|:| |:| (1. 25)) (id int (1. 28)) (} } (1. 29)) …

13 Prof Fateman CS 164 Lecture 3712 Parsing Once words are understood, the next step is to understand sentence structure as we saw in CS61a Parsing = producing AST. –3 ways Recursive descent, seat of the pants programming LL (also top down parsing), more systematic LR (bottom up) especially LALR

14 Prof Fateman CS 164 Lecture 3713 Typechecking = Static Semantic Analysis Scramble over the tree –Build up a symbol table Structured in lexical levels Observe all the details Maybe make some changes. E.g. X.foo  x[1]

15 Prof Fateman CS 164 Lecture 3714 Interpretation = Dynamic (Runtime) Analysis Scramble over the tree –Execute it

16 Prof Fateman CS 164 Lecture 3715 OR…Compiling = code generation Scramble over the tree –Expand pieces of the AST into straight line sequences of Assembly code

17 Prof Fateman CS 164 Lecture 3716 then… Assemble the generated code Run the “binary” code on a computer –Simulated computer –Actual computer (think of it as a hardware simulation of the “architecture” which is, after all, a formal system.)

18 Prof Fateman CS 164 Lecture 3717 then… Celebrate if your code worked.

19 Prof Fateman CS 164 Lecture 3718 What else? Other ways of thinking about Programming Languages (We did not do…) prolog The Lambda calculus Macro expansion Object-orientation

20 Prof Fateman CS 164 Lecture 3719 Is there more to this subject? –Lots more. And its not just about programming, but about user interfaces, theorem proving, mathematics, (also politics, standards, economics). –At least 3 graduate courses here (more like 5 or 6 if you count “closely related”) –Many books (not counting “Java for dummies” etc.) –Magazines and Journals –Just a few web pages

21 Prof Fateman CS 164 Lecture 3720

22 Prof Fateman CS 164 Lecture 3721 Time for questions?

23 Prof Fateman CS 164 Lecture 3722 I hope you found this course challenging & fun. –Good luck on all your finals –Have a good vacation

24 Prof Fateman CS 164 Lecture 3723

25 Prof Fateman CS 164 Lecture 3724


Download ppt "Prof Fateman CS 164 Lecture 371 Review: Programming Languages and Compilers CS164 9-10AM MWF 10 Evans."

Similar presentations


Ads by Google