CS:3820 Programming Language Concepts€¦ · – Dataflow} focus of this course 2 Paradigms. ... ,...

Preview:

Citation preview

CS:3820ProgrammingLanguageConcepts

Fall2016

IntroductionandOverview

Copyright 2016, Cesare Tinelli and others.Parts of these notes were originally developed by Allen Tucker, Robert Noonan and Peter Sestoft and are used with permission. They are copyrighted materials and may not be used in other course settings outside of the University of Iowa in their current form or modified form without the express written permission of one of the copyright holders. During this course, students are prohibited from selling notes to or being paid for taking notes by any person or commercial firm without the express written permission of one of the copyright holders.

Distinguishingprogramminglanguagesproperties:– Syntax– Names– Types– Abstractions– Semantics

Foranylanguage:– Itsdesignersmustdefinetheseproperties– Itsprogrammersmustmastertheseproperties

1Principles

Thesyntax ofaprogramminglanguageisaprecisedescriptionofallitsgrammaticallycorrectprograms

Whenstudyingsyntax,weaskquestionslike:– Whatisthegrammarforthelanguage?– Whatisthebasicvocabulary?– Howaresyntaxerrorsdetected?

Syntax

Variouskindsofentitiesinaprogramhavenames:variables,types,functions,parameters,classes,objects,…

Namedentitiesareboundinarunningprogramto:– Scope– Visibility– Type– Lifetime

Names

Atype isacollectionofvaluesandofoperationsonthosevalues

• Simpletypes– numbers,characters,Booleans,…

• Structuredtypes– Strings,lists,trees,hashtables,…

• Alanguage’stypesystem canhelp:– determinelegaloperations– detecttypeerrors– optimizecertainoperations

Types

Mechanismsforgeneralizingcomputationsordata:– Procedures/functions– Modules– Abstractdatatypes– Classes– Memorymodels

Abstractions

ThemeaningofaprogramiscalleditssemanticsInstudyingsemantics,weaskquestionslike:– Whenaprogramisrunning,whathappenstothevaluesofthevariables?

– Whatdoeseachconstructdo?– Whatunderlyingmodelgovernsrun-timebehavior,suchasfunctioncall?

– Howarevariablesandobjectsallocatedtomemoryatrun-time?

Semantics

Aprogrammingparadigm isapatternofproblem-solvingthoughtthatunderliesaparticulargenreofprogramsandlanguages

Thereareseveralmainprogrammingparadigms:– Imperative– Object-oriented– Functional– Logic– Dataflow

} focus of this course

2Paradigms

FollowstheclassicvonNeumann-Eckertmodel:– Programanddataareindistinguishableinmemory– Program=sequenceofcommandsmodifyingcurrentstate– State=valuesofallvariableswhenprogramruns– Largeprogramsuseproceduralabstraction

Exampleimperativelanguages:– Cobol,Fortran,C,Ada,Perl,…

ImperativeParadigm

AnOOProgramisacollectionofobjectsthatinteractbypassingmessagesthattransformlocalstate

Majorfeatures:– EncapsulatedState– Messagepassing– Inheritance– SubtypePolymorphism

ExampleOOlanguages:Smalltalk,Java,C++,C#,Python,…

Object-oriented(OO)Paradigm

Functionalprogrammingmodelsacomputationasacollectionofmathematicalfunctions– Input=domain– Output=range

Majorfeatures– Functionalcomposition– Recursion– Referentialtransparency

Examplefunctionallanguages:– Lisp,Scheme,ML,Haskell,F#,…

FunctionalParadigm

Functionalprogrammingmodelsacomputationasacollectionofmathematicalfunctions– Input=domain– Output=range

Notablefeaturesofmodernfunctionallanguages:– Functionsasvalues– Symbolicdatatypes– Patternmatching– Sophisticatedtypesystemsandmodulesystems

FunctionalParadigm

Logicprogrammingdeclareswhatoutcomeoftheprogramshouldbe,ratherthanhowitshouldbeachieved

Majorfeatures:– Programsassetsofconstraintsonaproblem– Computationofallpossiblesolutions– Nondeterministiccomputation

Examplelogicprogramminglanguages:– Prolog,Datalog

LogicParadigm

Howandwhendidprogramminglanguagesevolve?

Whatcommunitieshavedevelopedandusedthem?– ArtificialIntelligence– ComputerScienceEducation– ScienceandEngineering– InformationSystems– SystemsandNetworks– WorldWideWeb– …

3ABriefHistory

ML

SASL HASKELL

LISP

COBOL

VISUAL BASIC

GJ

JAVA

2000

C#

BASIC

CCPL BBCPL

FORTRAN77

BETA

2010

Java 5

C# 2 C# 4

STANDARD MLOCAMLCAML LIGHT

VB.NET 10

Go

F#

Scala

FORTRAN90

ADA ADA95 ADA2005

FORTRAN2003

FORTRAN

ALGOL

PASCAL

C++ALGOL 68

SIMULA

SMALLTALK

PROLOG

1956 1970 1980 19901960

SCHEME

LanguageGenealogy

ML

SASL HASKELL

LISP

COBOL

VISUAL BASIC

GJ

JAVA

2000

C#

BASIC

CCPL BBCPL

FORTRAN77

BETA

2010

Java 5

C# 2 C# 4

STANDARD MLOCAMLCAML LIGHT

VB.NET 10

Go

F#

Scala

FORTRAN90

ADA ADA95 ADA2005

FORTRAN2003

FORTRAN

ALGOL

PASCAL

C++ALGOL 68

SIMULA

SMALLTALK

PROLOG

1956 1970 1980 19901960

SCHEME

LanguageGenealogyMostly

academic

Old mainstream

Modernmainstream

DesignConstraints– Computerarchitecture– Technicalsetting– Standards– Legacysystems

DesignOutcomesandGoals

4OnLanguageDesign

Keycharacteristics:– Simplicityandreadability– Reliability– Support– Abstraction– Orthogonality– Libraries– Efficientimplementation– Community

Whatmakesasuccessfullanguage?

• Smallinstructionset– E.g.,JavavsScheme

• Simplesyntax– E.g.,C/C++/JavavsPython

• Benefits:– Easeoflearning– Easeofprogramming

SimplicityandReadability

• Programbehavior isthesameondifferentplatforms• E.g.,earlyFortran,C

• Typeerrorsaredetected• E.g.,CvsHaskell

• Semanticerrorsareproperlytrapped• E.g.,CvsC++

• Memoryleaksareprevented• E.g.,CvsJava

Reliability

• Accessible(publicdomain)compilers/interpreters• Goodtextsandtutorials• Widecommunityofusers• Integratedwithdevelopmentenvironments(IDEs)

LanguageSupport

Alanguageisorthogonal ifitsfeaturesarebuiltuponasmall,mutuallyindependentsetofprimitiveoperations.

• Fewerexceptionalrules=conceptualsimplicity– E.g.,restrictingtypesofargumentstoafunction

• Tradeoffs withefficiency

Orthogonality

• Embeddedsystems– Real-timeresponsiveness(e.g.,navigation)– FailuresofearlyAdaimplementations

• Webapplications– Responsivenesstousers(e.g.,Googlesearch)

• Corporatedatabaseapplications– Efficientsearchandupdating

• AIapplications– Modeling humanbehaviors

EfficiencyIssues

by the Trento people by the Trento people

Compiler– producesmachinecodeInterpreter– executesinstructionsonavirtualmachine• Somecompiledlanguages:– Fortran,C,C++,Rust,Swift

• Someinterpretedlanguages:– Scheme,Python,Javascript

• Hybridcompilation/interpretation– JavaVirtualMachine(JVM)languages(Java,Scala,Clojure)– .NETlanguages(C#,F#)

5CompilersandInterpreters

Compilation

Interpretation

• AbriefintrotofunctionalprogrammingwithF#• Lexicalanalysis,regularexpressions,finiteautomata,lexer generators• Syntaxanalysis,top-downversusbottom-upparsing,LLversusLR,

parsergenerators• Expressionevaluation,stackmachines,Postscript• CompilationofasubsetofCwith*p,&x,pointerarithmetic,arrays• Typechecking,typeinference,staticallyanddynamicallytyped

languages• ThemachinemodelofJava,C#,F#:stack,heap,garbagecollection• TheintermediatebytecodelanguagesoftheJavaVirtualMachine

and.NET• Garbagecollectiontechniques,dynamicmemorymanagement• Continuations,exceptions,alanguagewithbacktracking• Selectedadvancedtopics

27

6 CourseContents