400 likes | 409 Views
Welcome to Programming Languages!. http://flic.kr/p/ eGNyq. Why take Programming Languages?. Make me a better ________________. Why take Programming Languages?. Make be a better creator of PLs Design PLs Implement PLs Make me a better user of PLs Write better code
E N D
Welcome to Programming Languages! http://flic.kr/p/eGNyq
Why take Programming Languages? Make me a better ________________
Why take Programming Languages? • Make be a better creator of PLs • Design PLs • Implement PLs • Make me a better userof PLs • Write better code • Choose right PL for job
Deep questions • What makes a good PL design? • What types of PL designs are there? • How do you implement a PL?
Can you guess what this is? It’s a program! • Machine language – x86 (Pentium) • Expressed as hex • Calculates greatest common divisor (GCD)
What are the pros/cons of machine language? Pros Cons Unreadable Not portable More??? • Close to machine • Performance
Can you guess what this is? • Assembly language version of GCD program • 1-to-1 mnemonic mapping to machine language
What are the pros/cons of assembly language? • Pretty much same as machine language, but more human readable
Can you guess what this is? • High-level language (C/C++) version of GCD
What are the pros/cons of high-level language? • Pros: More comprehendible, scalable, and portable • Cons: Farther from the machine (poorer performance)
But there are thousands(?) of high-level langs – what makes one better than another? C/C++ Scheme/Lisp Prolog
What makes one lang better than another? • Expressive power • What computations can you express? • Usability • Learnability • Ease of use (create/read/modify) • Ease of implementation • Performance • Tool support • Familiarity/expertise???
Deep questions • What makes a good PL design? • What types of PL designs are there? • How do you implement a PL?
Declarative versus Imperative Declarative Imperative Say how to compute Implementers point of view Closer to machine Dominant • Say what to compute • Programmers point of view • Higher level • Up and coming
(Fuzzy) Categories of languages • Declarative • functional (Lisp/Scheme, ML, Haskell) • dataflow (Id, Val) • logic, constraint-based (Prolog, spreadsheets) • template-based (XSLT) • Imperative • von Neumann (C, Ada, Fortran, …) • scripting (Perl, Python, PHP, …) • object-oriented (Smalltalk, Eiffel, Java, …)
Functional versus von Neuman von Neumann - C/C++ Recursive definition of functions, refining from more complex to simpler(no variables/state!) Functional - Scheme/Lisp Declaration and sequential modification of variables
Deep questions • What makes a good PL design? • What types of PL designs are there? • How do you implement a PL?
Finish this dataflow diagram for high-level languages Don’t let the namesconfuse you. Theseare all translators
Architectural pattern*:Translate through many intermediate representations * Called pipeline orpipes and filters architecture
But there’s another way! Can you explain this diagram?
Translators Versus Interpreters • Translator: Program that reads “sentences” in one language and converts them to another • See also compilers, assemblers • Interpreter: Program that reads sentences in some language and “executes” them • May or may not be interactive
What language uses this translator/interpreter hybrid architecture? aka Compiler aka Interpreter Why, Java, of course
How do you read/analyze/process code? … What happensin here?
Two big concerns • Syntax: The form in which sentences are expressed • What syntactic elements do parts of the source map to? • Is the source syntactically valid? • Semantics: The meaning of the sentences • What semantic elements do parts of the source map to? • Is the source semantically valid?
Split input into bite-size tokens C/C++ token examples: What next?
Map tokens to syntactic elements C/C++ parse treeexample: What next?
Represent program in terms of semantic elements AST example What next?
And all the rest… And all the rest…
Fortunately, there are tools to help you! • Compiler Compilers • aka Compiler Generators • aka Parser Generators • aka… • Examples: • Lex/Yacc • Flex/Bison • ANTLR
Course Goals • Learn to create your own language translators/interpreters • Using ANTLR • Survey issues and features in PL design • Try programming in sampling of different languages
Course Structure • Three parts (4-5 weeks each) • Follows structure of PLP book • Each ends in an exam • Homeworks throughout (~7) • Readings + quizzes throughout
Grading • 51% exams (3 x 17%) • 39% homeworks and quizzes • 10% participation
Some key policies • No cheating! • I use plagiarism detection system! • Participate! (lest you lose a participation point) • Be here at beginning of class, stay until the end • Pop quizzes at beginning of class common • Be engaged! • Expect seating chart • Bring laptops, but…
http://www.cbc.ca/news/technology/story/2013/08/14/technology-laptop-grades.htmlhttp://www.cbc.ca/news/technology/story/2013/08/14/technology-laptop-grades.html
What’s next? • Take Java proficiency instrument • In class today • Do Homework 0 • Due Tuesday by 2:40