Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource...
Transcript of Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource...
![Page 1: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/1.jpg)
Image credits: http://xkcd.com/353/
![Page 2: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/2.jpg)
CS 354: Programming Languages
Alark Joshi
Copyright © 2009 Addison-Wesley. All rights
reserved.
![Page 3: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/3.jpg)
Contact Information • Email: [email protected]
• Course Website:
o http://cs.boisestate.edu/~alark/cs354
• Office: MEC 302A
• Office Hours:
o Monday, Friday : 10-11am
o Tuesday, Thursday: 3-4pm
o Doodle poll
![Page 4: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/4.jpg)
TA Information • Teaching Assistant
• Nathan Riskey
o Graduate Student
o Work experience
• Office hours: To be announced soon
![Page 5: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/5.jpg)
Administrivia • Roll call sheet going around – Please sign
and note your team assignment
• Piazza instead of a mailing list
o https://piazza.com/boisestate/fall2012/compsc
i354
o Better at managing responses, replies, helping
each other through assignments, homework,
projects etc.
![Page 6: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/6.jpg)
Textbook & Resources • Concepts of Programming Languages by
Richard Sebesta, Addison Wesley publishing,
9th Edition, 2009.
• Course Wiki:
o cs354.pbworks.com
o Collaborative resource
o Feel free to edit and improve
![Page 7: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/7.jpg)
Why study languages/programming languages?
• Look to the person sitting next to you
• Introduce yourself
• Make the longest list of reasons you can
think of in 2 minutes
• Longest list in class wins!
• Go!!!
• I will call on you to share from your list
![Page 8: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/8.jpg)
Reasons from Sebesta 1. Increased capacity to express ideas
2. Improved background for choosing
appropriate languages
3. Increased ability to learn new languages
4. Better understanding of the significance of
implementation
5. Better use of languages that are already
known
6. Overall advancement of computing
![Page 9: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/9.jpg)
Grade Breakdown • Quizzes – 21%
• Interpreter assignment – 15%
• Programming assignments – 15%
• Homework – 14%
• Final project - 35%
o Create a website for a programming language
o Work on a project using that programming
language
![Page 10: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/10.jpg)
Final Project • P1 - Website for learning a new language:
weebly, pbworks or any other
• P2 - Create a detailed manual or YouTube
video with details regarding installation, IDE
setup and other relevant issues
• P3 - include 10/15 examples of increasing
difficulty to teach a novice about that
programming language
![Page 11: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/11.jpg)
Final Project • P4 - Update website with a comprehensive
list of relevant resources, books, tutorials,
videos, etc.
• P5 - Propose 3 projects to me (and
anonymous reviewers) - We pick one for you
to implement by the end of the semester
• P6 - 5-min presentation in the class about
your project and what you propose to do
![Page 12: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/12.jpg)
Final Project • P7 - Incorporate feedback from anonymous
reviewers to improve your website
• P8 – In-class presentation (25-mins)
• Final grade of the project based on
o Quality of the website
o Ability to follow along for reviewers
o Quality of final project
o Relevant documentation
![Page 13: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/13.jpg)
Anonymous reviewers • Each student and some external software
partners will serve as anonymous reviewers
• Code review for programs and final project
• Monthly reports on the quality of the website
and the status of the project as described
on the website
![Page 14: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/14.jpg)
Programming Assignments
• Interpreter assignments
o V1 and V2 – worth 15%
• Three language related assignments
o C# - 5%
• Assignment available – Due 10th Sept
o Python - 5%
o Scheme/ML/Haskell - 5%
![Page 15: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/15.jpg)
Team-Based Learning • Long Lectures have been shown to produce
significant reduction in understanding as the
lecture progresses
• Team-based learning
o Apply
o Question
o Reflect upon and
o Discuss content in a group
![Page 16: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/16.jpg)
TBL Quizzes • Each quiz will be taken first as an individual
• Same quiz will be taken as a team
o Instant feedback for the team
• TBL quizzes – individual vs team performance
• Quizzes – 21% of the final grade
o Quiz 1 - Chapter 1 of Sebesta on 5th Sept
![Page 17: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/17.jpg)
Team Assignments • Teams assignments are going around
• Please meet your team now!
o Buzz Lightyear
o Dory
o Merida
o Nemo
o Remy
o Sulley
o Wall-E
![Page 18: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/18.jpg)
Languages
1. Python
2. Javascript
3. CUDA
4. Lua
5. Haskell
6. C++
7. Ruby
8. Actionscript
9. Objective-C
10. Perl
11. Processing
12. Lisp
13. Matlab
14. R
Image credits: http://xkcd.com/519/
![Page 19: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/19.jpg)
Language Evaluation Criteria
• Course objective #6:
o Evaluate a language on the basis of the
various features which it supports.
• How would you evaluate a language?
• Think-pair-share (2-2-2)
o 2 mins to think of metrics you would use
o 2 mins to share it with your partner/team
o 2 mins to share with the class
![Page 20: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/20.jpg)
Language Evaluation Criteria
• Readability
• Writability
• Reliability
• Cost
![Page 21: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/21.jpg)
Readability
The ease with which programs can
be read and understood
![Page 22: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/22.jpg)
Evaluation Criteria: Readability
• Overall simplicity
o A manageable set of features and constructs
o Minimal feature multiplicity
o Minimal operator overloading
• Orthogonality
o A relatively small set of primitive constructs can
be combined in a relatively small number of
ways
o Every possible combination is legal
![Page 23: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/23.jpg)
Evaluation Criteria: Readability
• Data types o Adequate predefined data types
• Syntax considerations
o Identifier forms: flexible composition
o Special words and methods of forming
compound statements
o Form and meaning: self-descriptive constructs,
meaningful keywords
![Page 24: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/24.jpg)
Writability
The ease with which a language
can be used to create programs
![Page 25: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/25.jpg)
Evaluation Criteria: Writability
• Simplicity and orthogonality
o Few constructs, a small number of primitives, a small set of
rules for combining them
• Support for abstraction
o The ability to define and use complex structures or
operations in ways that allow details to be ignored
• Expressivity
o A set of relatively convenient ways of specifying operations
o Strength and number of operators and predefined functions
![Page 26: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/26.jpg)
Reliability
Conformance to specifications (i.e.,
performs to its specifications)
![Page 27: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/27.jpg)
Evaluation Criteria: Reliability
• Type checking o Testing for type errors
• Exception handling o Intercept run-time errors and take corrective
measures
![Page 28: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/28.jpg)
Evaluation Criteria: Reliability
• Aliasing o Presence of two or more distinct referencing
methods for the same memory location
• Readability and writability o A language that does not support “natural” ways
of expressing an algorithm will require the use of
“unnatural” approaches, and hence reduced
reliability
![Page 29: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/29.jpg)
Evaluation Criteria: Cost
• Training programmers to use the language
• Writing programs (closeness to particular
applications)
• Compiling programs
• Executing programs
• Language implementation system:
availability of free compilers
• Reliability: poor reliability leads to high costs
• Maintaining programs
Image credits - http://xkcd.com/303/
![Page 30: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/30.jpg)
Evaluation Criteria: Others
• Portability
o The ease with which programs can be moved
from one implementation to another
• Generality
o The applicability to a wide range of
applications
• Well-definedness
o The completeness and precision of the
language‟s official definition
![Page 31: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/31.jpg)
Influences on Language Design
• Computer Architecture
o Languages are developed around the
prevalent computer architecture, known as the
von Neumann architecture
• Program Design Methodologies
o New software development methodologies
(e.g., object-oriented software development)
led to new programming paradigms and by
extension, new programming languages
![Page 32: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/32.jpg)
The von Neumann Architecture
![Page 33: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/33.jpg)
The von Neumann Architecture
• Fetch-execute-cycle (on a von Neumann
architecture computer)
initialize the program counter
repeat forever
fetch the instruction pointed by the counter
increment the counter
decode the instruction
execute the instruction
end repeat
![Page 34: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/34.jpg)
Computer Architecture Influence
• Well-known computer architecture: Von Neumann
• Imperative languages, most dominant, because of
von Neumann computers
o Data and programs stored in memory
o Memory is separate from CPU
o Instructions and data are piped from memory to CPU
o Basis for imperative languages
• Variables model memory cells
• Assignment statements model piping
• Iteration is efficient
![Page 35: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/35.jpg)
Programming Methodologies Influences
• 1950s and early 1960s: Simple applications; worry
about machine efficiency
• Late 1960s: People efficiency became important;
readability, better control structures
o structured programming
o top-down design and step-wise refinement
• Late 1970s: Process-oriented to data-oriented
o data abstraction
• Middle 1980s: Object-oriented programming
o Data abstraction + inheritance + polymorphism
![Page 36: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/36.jpg)
Language Categories • Imperative
o Central features are variables, assignment statements, and iteration
o Include languages that support object-oriented programming
o Include scripting languages
o Include the visual languages
o Examples: C, Java, Perl, JavaScript, Visual BASIC .NET, C++
• Functional o Main means of making computations is by
applying functions to given parameters
o Examples: LISP, Scheme, ML, F#
![Page 37: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/37.jpg)
Language Categories • Logic
o Rule-based (rules are specified in no particular order)
o Example: Prolog
• Markup/programming hybrid oMarkup languages extended to support
some programming
o Examples: JSTL, XSLT, LaTeX
![Page 38: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/38.jpg)
Language Design Trade-Offs • Reliability vs. cost of execution
o Example: Java demands all references to array elements
be checked for proper indexing, which leads to increased
execution costs
• Readability vs. writability o Example: APL provides many powerful operators (and a
large number of new symbols), allowing complex
computations to be written in a compact program but at
the cost of poor readability
• Writability (flexibility) vs. reliability o Example: C++ pointers are powerful and very flexible but
are unreliable
2-2-2
![Page 39: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/39.jpg)
Implementation Methods • Compilation
o Programs are translated into machine language; includes JIT systems
o Use: Large commercial applications
• Pure Interpretation o Programs are interpreted by another program known as an
interpreter
o Use: Small programs or when efficiency is not an issue
• Hybrid Implementation Systems o A compromise between compilers and pure interpreters
o Use: Small and medium systems when efficiency is not the first concern
![Page 40: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/40.jpg)
Layered View of Computer
The operating system and language implementation are layered over machine interface of a computer
![Page 41: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/41.jpg)
Compilation vs. Interpretation
• Compilation vs. interpretation
o not opposites
o not a clear-cut distinction
• Pure Compilation
o The compiler translates the high-level
source program into an equivalent target
program (typically in machine
language), and then goes away:
![Page 42: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/42.jpg)
Compilation vs. Interpretation
• Pure Interpretation
o Interpreter stays around for the execution
of the program
o Interpreter is the locus of control during
execution
![Page 43: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/43.jpg)
Compilation vs. Interpretation
• Interpretation:
oGreater flexibility
o Better diagnostics (error messages)
• Compilation
o Better performance
![Page 44: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/44.jpg)
Compilation vs. Interpretation
• Common case is compilation or simple
pre-processing, followed by
interpretation
• Most language implementations - mixture
of both compilation and interpretation
![Page 45: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/45.jpg)
Compilation • Compilation does NOT have to produce
machine language for some sort of
hardware
• Compilation is translation from one
language into another, with full analysis of
the meaning of the input
![Page 46: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/46.jpg)
Compilation • Compilation entails semantic understanding
of what is being processed; pre-processing
does not • A pre-processor is a program that processes its input data to
produce output that is used as input to another program
(usually compiler)
• A pre-processor will often let errors through.
A compiler hides further steps; a pre-
processor does not
![Page 47: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/47.jpg)
Compilation vs. Interpretation
• Implementation strategies:
o Preprocessor
• Removes comments and white space
• Groups characters into tokens (keywords,
identifiers, numbers, symbols)
• Expands abbreviations in the style of a macro
assembler
• Identifies higher-level syntactic structures
(loops, subroutines)
![Page 48: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/48.jpg)
Compilation vs. Interpretation
• Implementation strategies:
o Library of Routines and Linking
• Compiler uses a linker program to merge the
appropriate library of subroutines (e.g., math
functions such as sin, cos, log, etc.) into the
final program:
![Page 49: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/49.jpg)
Compilation vs. Interpretation
• Implementation strategies:
o Post-compilation Assembly
• Facilitates debugging (assembly language
easier for people to read)
• Isolates the compiler from changes in the
format of machine language files (only
assembler must be changed, is shared by
many compilers)
![Page 50: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/50.jpg)
Compilation vs. Interpretation • Implementation strategies:
o The C Preprocessor (conditional
compilation)
• Preprocessor deletes portions of code,
which allows several versions of a program
to be built from the same source
![Page 51: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/51.jpg)
Compilation vs. Interpretation
• Implementation strategies:
o Source-to-Source Translation (C++)
• C++ implementations based on the early
AT&T compiler generated an intermediate
program in C, instead of an assembly
language:
![Page 52: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/52.jpg)
Compilation vs. Interpretation
• Implementation strategies:
oCompilation of Interpreted Languages
• The compiler generates code that makes
assumptions about decisions that won‟t be
finalized until runtime.
• If these assumptions are valid, the code runs
very fast.
• If not, a dynamic check will revert to the
interpreter.
![Page 53: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/53.jpg)
Compilation vs. Interpretation
• Implementation strategies:
oDynamic and Just-in-Time Compilation
• In some cases a programming system may
deliberately delay compilation until the last
possible moment.
o Lisp and Prolog invoke the compiler on the fly, to
translate newly created source into machine language
![Page 54: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/54.jpg)
Compilation vs. Interpretation
oDynamic and Just-in-Time Compilation
• The Java language definition defines a
machine-independent intermediate
form known as byte code. Byte code is
the standard format for distribution of
Java programs.
• The main C# compiler produces .NET
Common Intermediate Language (CIL),
which is then translated into machine
code immediately prior to execution.
![Page 55: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/55.jpg)
Compilation vs. Interpretation
• Compilers exist for some interpreted languages, but they aren't pure:
o selective compilation of compilable pieces and extra-sophisticated pre-processing of remaining source.
o Interpretation of parts of code, at least, is still necessary for reasons above.
• Unconventional compilers
o text formatters
o silicon compilers
o query language processors
![Page 56: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/56.jpg)
von Neumann Bottleneck • Connection speed between a computer‟s
memory and its processor determines the speed of a computer
• Program instructions often can be executed much faster than the speed of the connection; the connection speed thus results in a bottleneck
• Known as the von Neumann bottleneck; it is the primary limiting factor in the speed of computers
![Page 57: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/57.jpg)
Robot Programming • In groups of 2/3 select
a “robot” and a “robot
master”
• The “Dictionary”
contains a list of
commands that a
robot understands
• Invent new commands
![Page 58: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/58.jpg)
Robot Programming • The goal is for the robot to go through a
maze, move an object and reach the end
• Your sub-group will write a program that will
be followed by the robot
• Every time you write a program, you hand it
over to the robot who will follow the
instructions
• Use a blank sheet of paper for every
program
10 mins
![Page 59: Image credits: alark/cs354/lectures/Introduction.pdf · ocs354.pbworks.com oCollaborative resource oFeel free to edit and improve Why study languages/programming languages? •Look](https://reader034.fdocuments.net/reader034/viewer/2022052101/603b9195588a594da52d4e1d/html5/thumbnails/59.jpg)
Robot Game Analysis • You invented a programming language to
program a fictional robot
o The commands you used/invented are the
commands for your new programming
language
o The commands were „executed‟ by your
„robot‟
o At times you didn‟t get the expected result – which you found out by „running‟ the robot
o Debugging and Re-execute