Top Banner
CS 415: CS 415: Programming Programming Languages Languages Chapter 1 Chapter 1 Aaron Bloomfield Aaron Bloomfield Fall 2005 Fall 2005
20

CS 415: Programming Languages

Jan 03, 2016

Download

Documents

Clinton Walters

CS 415: Programming Languages. Chapter 1 Aaron Bloomfield Fall 2005. The first computers. Scales – computed relative weight of two items Computed if the first item’s weight was less than, equal to, or greater than the second item’s weight Abacus – performed mathematical computations - PowerPoint PPT Presentation
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: CS 415: Programming Languages

CS 415: Programming CS 415: Programming LanguagesLanguages

Chapter 1Chapter 1

Aaron BloomfieldAaron Bloomfield

Fall 2005Fall 2005

Page 2: CS 415: Programming Languages

The first computersThe first computers

Scales – computed relative weight of two itemsScales – computed relative weight of two items Computed if the first item’s weight was less than, equal to, or Computed if the first item’s weight was less than, equal to, or

greater than the second item’s weightgreater than the second item’s weight

Abacus – performed mathematical computationsAbacus – performed mathematical computations Primarily thought of as Chinese, but also Japanese, Mayan, Primarily thought of as Chinese, but also Japanese, Mayan,

Russian, and Roman versionsRussian, and Roman versions Can do square roots and cube rootsCan do square roots and cube roots

Page 3: CS 415: Programming Languages

StonehengeStonehenge

Page 4: CS 415: Programming Languages

Computer SizeComputer Size

ENIAC then…

ENIAC today…

With computers (small) size does matter!With computers (small) size does matter!

Page 5: CS 415: Programming Languages

Why study programming Why study programming languages?languages?

Become a better software engineerBecome a better software engineer Understand how to use language featuresUnderstand how to use language features Appreciate implementation issuesAppreciate implementation issues

Better background for language selectionBetter background for language selection Familiar with range of languagesFamiliar with range of languages Understand issues / advantages / disadvantagesUnderstand issues / advantages / disadvantages

Better able to learn languagesBetter able to learn languages You might need to know a lotYou might need to know a lot

Page 6: CS 415: Programming Languages

Why study programming Why study programming languages?languages?

Better understanding of implementation issuesBetter understanding of implementation issues How is “this feature” implemented?How is “this feature” implemented? Why does “this part” run so slowly?Why does “this part” run so slowly?

Better able to design languagesBetter able to design languages Those who ignore history are bound to repeat it…Those who ignore history are bound to repeat it…

Page 7: CS 415: Programming Languages

Why are there so many Why are there so many programming languages?programming languages?

There are thousands!There are thousands!

EvolutionEvolution Structured languages -> OO programmingStructured languages -> OO programming

Special purposesSpecial purposes Lisp for symbols; Snobol for strings; C for systems; Lisp for symbols; Snobol for strings; C for systems;

Prolog for relationshipsProlog for relationships

Personal preferencePersonal preference Programmers have their own personal tastesProgrammers have their own personal tastes

Expressive powerExpressive power Some features allow you to express your ideas betterSome features allow you to express your ideas better

Page 8: CS 415: Programming Languages

Why are there so many Why are there so many programming languages?programming languages?

Easy to useEasy to use Especially for teaching / learning tasksEspecially for teaching / learning tasks

Ease of implementationEase of implementation Easy to write a compiler / interpreter forEasy to write a compiler / interpreter for

Good compilersGood compilers Fortran in the 50’s and 60’sFortran in the 50’s and 60’s

Economics, patronageEconomics, patronage Cobol and Ada, for exampleCobol and Ada, for example

Page 9: CS 415: Programming Languages

Programming domainsProgramming domains

Scientific applicationsScientific applications Using the computer as a large calculatorUsing the computer as a large calculator Fortran and friends, some Algol, APLFortran and friends, some Algol, APL Using the computer for symbol manipulationUsing the computer for symbol manipulation MathematicaMathematica

Business applicationsBusiness applications Data processing and business proceduresData processing and business procedures Cobol, some PL/1, RPG, spreadsheetsCobol, some PL/1, RPG, spreadsheets

Systems programmingSystems programming Building operating systems and utilitiesBuilding operating systems and utilities C, PL/S, ESPOL, Bliss, some Algol and derivitavesC, PL/S, ESPOL, Bliss, some Algol and derivitaves

Page 10: CS 415: Programming Languages

Programming domainsProgramming domains

Parallel programmingParallel programming Parallel and distributed systemsParallel and distributed systems Ada, CSP, Modula, DP, Mentat/LegionAda, CSP, Modula, DP, Mentat/Legion

Artificial intelligenceArtificial intelligence Uses symbolic rather than numeric computationsUses symbolic rather than numeric computations Lists as main data structureLists as main data structure Flexibility (code = data)Flexibility (code = data) Lisp in 1959, Prolog in the 1970sLisp in 1959, Prolog in the 1970s

Scripting languagesScripting languages A list of commands to be executedA list of commands to be executed UNIX shell programming, awk, tcl, PerlUNIX shell programming, awk, tcl, Perl

Page 11: CS 415: Programming Languages

Programming domainsProgramming domains

EducationEducation Languages designed to facilitate teachingLanguages designed to facilitate teaching Pascal, BASIC, LogoPascal, BASIC, Logo

Special purposeSpecial purpose Other than the above…Other than the above… SimulationSimulation Specialized equipment controlSpecialized equipment control String processingString processing Visual languagesVisual languages

Page 12: CS 415: Programming Languages

Programming paradigmsProgramming paradigms

You have already seen assembly languageYou have already seen assembly language

We will study five language paradigms:We will study five language paradigms: Top-down (Algol 60 and Fortran)Top-down (Algol 60 and Fortran) Functional (Scheme and/or OCaml)Functional (Scheme and/or OCaml) Logic (Prolog)Logic (Prolog) Object oriented (Smalltalk)Object oriented (Smalltalk) Aspect oriented (AspectJ)Aspect oriented (AspectJ)

Page 13: CS 415: Programming Languages

Programming language historyProgramming language history

Pseudocodes (195X) – ManyPseudocodes (195X) – Many

Fortran (195X) – IBM, BackusFortran (195X) – IBM, Backus

Lisp (196x) – McCarthyLisp (196x) – McCarthy

Algol (1958) – Committee (led to Pascal, Ada)Algol (1958) – Committee (led to Pascal, Ada)

Cobol (196X) – HopperCobol (196X) – Hopper

Functional programming – FP, Scheme, Haskell, MLFunctional programming – FP, Scheme, Haskell, ML

Logic programming – PrologLogic programming – Prolog

Object oriented programming – Smalltalk, C++, Python, Object oriented programming – Smalltalk, C++, Python, JavaJava

Aspect oriented programming – AspectJ, AspectC++Aspect oriented programming – AspectJ, AspectC++

Parallel / non-deterministic programmingParallel / non-deterministic programming

Page 14: CS 415: Programming Languages

Compilation vs. TranslationCompilation vs. Translation

Translation: does a ‘mechanical’ translation of the source Translation: does a ‘mechanical’ translation of the source codecode

No deep analysis of the syntax/semantics of the codeNo deep analysis of the syntax/semantics of the code

Compilation: does a thorough understanding and Compilation: does a thorough understanding and translation of the codetranslation of the code

A compiler/translator changes a program from one A compiler/translator changes a program from one language into anotherlanguage into another

C compiler: from C into assemblyC compiler: from C into assemblyAn assembler then translates it into machine languageAn assembler then translates it into machine language

Java compiler: from Java code to Java bytecodeJava compiler: from Java code to Java bytecodeThe Java interpreter then runs the bytecodeThe Java interpreter then runs the bytecode

Page 15: CS 415: Programming Languages

Compilation stagesCompilation stages

ScannerScanner

ParserParser

Semantic analysisSemantic analysis

Intermediate code generationIntermediate code generation

Machine-independent code improvement (optional)Machine-independent code improvement (optional)

Target code generationTarget code generation

Machine-specific code improvement (optional)Machine-specific code improvement (optional)

For many compilers, the result is assemblyFor many compilers, the result is assembly Which then has to be run through an assemblerWhich then has to be run through an assembler

These stages are machine-independent!These stages are machine-independent! The generate “intermediate code”The generate “intermediate code”

Page 16: CS 415: Programming Languages

Compilation: ScannerCompilation: Scanner

Recognizes the ‘tokens’ of a programRecognizes the ‘tokens’ of a program Example tokens: ( 75 main int { return ; fooExample tokens: ( 75 main int { return ; foo

Lexical errors are detected hereLexical errors are detected here More on this in a future lectureMore on this in a future lecture

Page 17: CS 415: Programming Languages

Compilation: ParserCompilation: Parser

Puts the tokens together into a patternPuts the tokens together into a pattern void main ( int argc , char ** argv ) {void main ( int argc , char ** argv ) { This line has 11 tokensThis line has 11 tokens It is the beginning of a methodIt is the beginning of a method

Syntatic errors are detected hereSyntatic errors are detected here When the tokens are not in the correct order:When the tokens are not in the correct order: int int foo ;int int foo ; This line has 4 tokensThis line has 4 tokens After the type (int), the parser expects a variable After the type (int), the parser expects a variable

namenameNot another typeNot another type

Page 18: CS 415: Programming Languages

Compilation: Semantic analysisCompilation: Semantic analysis

Checks for semantic correctnessChecks for semantic correctness

A semantic error:A semantic error:foo = 5;foo = 5;

int foo;int foo;

In C (and most languages), a variable has to be In C (and most languages), a variable has to be declared before it is useddeclared before it is used Note that this is syntactically correctNote that this is syntactically correct

As both lines are valid lines as far as the parser is concernedAs both lines are valid lines as far as the parser is concerned

Page 19: CS 415: Programming Languages

Compilation: Intermediate code Compilation: Intermediate code generation (and improvement)generation (and improvement)

Almost all compilers generate intermediate codeAlmost all compilers generate intermediate code This allows part of the compiler to be machine-This allows part of the compiler to be machine-

independentindependent

That code can then be optimizedThat code can then be optimized Optimize for speed, memory usage, or program Optimize for speed, memory usage, or program

footprintfootprint

Page 20: CS 415: Programming Languages

Compilation: Target code Compilation: Target code generation (and improvement)generation (and improvement)

The intermediate code is then translated into the The intermediate code is then translated into the target codetarget code For most compilers, the target code is assemblyFor most compilers, the target code is assembly For Java, the target code is Java bytecodeFor Java, the target code is Java bytecode

That code can then be further optimizedThat code can then be further optimized Optimize for speed, memory usage, or program Optimize for speed, memory usage, or program

footprintfootprint