Upload
melissa-williams
View
279
Download
2
Embed Size (px)
Citation preview
Programming LanguageProgramming Language
Prelim PeriodPrelim Period
Programming LanguageProgramming Language
A A programming languageprogramming language is a is a standardized standardized communication technique for describing instructions technique for describing instructions for a for a computer. .
Each programming language has a Each programming language has a set of set of syntactic and and semantic rules rules used to define used to define computer programs..
A language enables a programmer A language enables a programmer to precisely specify (but see to precisely specify (but see Genetic Programming) what data a ) what data a computer is to act upon, how these computer is to act upon, how these data are to be stored/transmitted, data are to be stored/transmitted, and what and what actions are to be taken are to be taken under various circumstances. under various circumstances.
Programming languages are a type of Programming languages are a type of computer languages, excluding , excluding pseudocode which is exclusively for human which is exclusively for human communication.communication.
Reasons Why Study Reasons Why Study Programming LanguagesProgramming Languages
1. Increased capacity to 1. Increased capacity to express programming express programming conceptsconcepts
2. Improved background for 2. Improved background for choosing appropriate choosing appropriate languageslanguages
3. Increased ability to learn 3. Increased ability to learn new languagesnew languages
4. Understanding the significance 4. Understanding the significance of implementationof implementation
5. Increased ability to design new 5. Increased ability to design new languageslanguages
6. Overall advancement of 6. Overall advancement of computingcomputing
Language of a ComputerLanguage of a Computer
1.)1.) Machine languageMachine language: the most basic : the most basic language of a computerlanguage of a computer
• • A sequence of 0s and 1sA sequence of 0s and 1s• • Every computer directly understands Every computer directly understands
its own machine languageits own machine language• • A bit is a binary digit, 0 or 1A bit is a binary digit, 0 or 1• • A byte is a sequence of eight bitsA byte is a sequence of eight bits
• • Early computers programmed in machine Early computers programmed in machine languagelanguage
2.) Low level Language2.) Low level Language - a - a programming language that is close programming language that is close to a machine languageto a machine language
Example:Example:• • Assembly languages Assembly languages
• • In assembly language, an instruction In assembly language, an instruction is an easy-to-remember form called a is an easy-to-remember form called a mnemonic, where syntax and mnemonic, where syntax and semantics is closer to the hardwaresemantics is closer to the hardware
Assembler: Assembler: translates assembly translates assembly language instructions into language instructions into machine languagemachine language
3.) High-level languages3.) High-level languages make make programming easierprogramming easier
• • Closer to spoken languagesCloser to spoken languages Examples:Examples:
– – BasicBasic– – FORTRANFORTRAN– – COBOLCOBOL– – C/C++C/C++– – JavaJava
Programming DomainsProgramming Domains
1.1. Scientific applicationsScientific applications
performs arithmetic performs arithmetic computation with large computation with large numbers of floating points.numbers of floating points.
efficiency is the primary efficiency is the primary concernconcern
first language for scientific first language for scientific applications are FORTRAN applications are FORTRAN ((ForFormula mula TranTranslator/slator/TranTranslationslation ) )and and ALGOL ALGOL (ALGOrithmic Language) (ALGOrithmic Language)
2. Business applications 2. Business applications
characterized according to the needs characterized according to the needs of the application, by elaborate input of the application, by elaborate input and output facilities and decimal data and output facilities and decimal data types.types.
The first successful high level The first successful high level language for business was COBOL language for business was COBOL
( Common Business Oriented ( Common Business Oriented Language)Language)
3. Artificial intelligence3. Artificial intelligence
characterized by the characterized by the absence of exact algorithm absence of exact algorithm and the use of symbolic and the use of symbolic computation rather than computation rather than numeric computationnumeric computation
• requires more flexibility requires more flexibility rather than more rather than more algorithmic programming.algorithmic programming.
• The first functional The first functional Language for AI is LISP Language for AI is LISP
( LISt Processing)( LISt Processing)
4. Systems programming 4. Systems programming
• these are the operating systems and all these are the operating systems and all of the programming support tools of a of the programming support tools of a computer systemcomputer system
• used almost continuously and therefore used almost continuously and therefore must have execution efficiencymust have execution efficiency
• must have low-level features that allows must have low-level features that allows software interface to externalsoftware interface to external
5. Scripting languages/ Very High 5. Scripting languages/ Very High Level Languages (VHLLs) Level Languages (VHLLs)
A scripting language is one that is A scripting language is one that is used by putting a list of commands, used by putting a list of commands, called script, in a file to be executed.called script, in a file to be executed.
Fourth Generation languages that Fourth Generation languages that were developed in 1970’s are were developed in 1970’s are sometimes considered to be VHLLssometimes considered to be VHLLs
6. Special purpose languages6. Special purpose languages
• Used to produce business reports, Used to produce business reports, for instructing programmable for instructing programmable machine tools and simulations.machine tools and simulations.
Language Evaluation Language Evaluation CriteriaCriteria
ReadabilityReadability WritabilityWritability ReliabilityReliability CostCost
ReadabilityReadability
The most important criteriumThe most important criterium
1.1 1.1 Overall SimplicityOverall Simplicity
A language with a large number of A language with a large number of components is more difficult to components is more difficult to learn than one with fewer learn than one with fewer componentscomponents
Feature multiplicityFeature multiplicity
Incrementation in C: x++; ++x; Incrementation in C: x++; ++x; x=x+1; x+=1;x=x+1; x+=1;
Operator overloading can reduce Operator overloading can reduce readability if users don’t do it readability if users don’t do it sensiblysensibly
Simplicity can be carried too far, Simplicity can be carried too far, as is the case with assembly as is the case with assembly languagelanguage
1.2 Orthogonality1.2 Orthogonality
A relatively small set of primitive A relatively small set of primitive constructs can be combined in a constructs can be combined in a relatively small number of ways to relatively small number of ways to build the control and data structures build the control and data structures of the languageof the language
Every possible combination of Every possible combination of primitives is legal and meaningfulprimitives is legal and meaningful
Example: Suppose a language Example: Suppose a language hashas
4 data types: int, float, double, char4 data types: int, float, double, char 2 type operators: array and pointer2 type operators: array and pointer If the 2 type operators can be applied If the 2 type operators can be applied
to themselves and the 4 data types, a to themselves and the 4 data types, a large number of data structures is large number of data structures is possiblepossible
The more orthogonal the design, The more orthogonal the design, the fewer exceptions the language the fewer exceptions the language rules requirerules requireExample of lack of orthogonality in Example of lack of orthogonality in C CThere are 2 kinds of structured There are 2 kinds of structured data types, arrays and data types, arrays and structs;structs can be returned from structs;structs can be returned from functions, but arrays cannotfunctions, but arrays cannot
Parameters are passed by value, Parameters are passed by value, except for arrays, which are passed except for arrays, which are passed by referenceby referenceAn array element can be any data An array element can be any data type except type except void void or a functionor a function
1.3 Control Statement1.3 Control Statement
The relatively recent introduction The relatively recent introduction of control constructs was a of control constructs was a reaction to the indiscriminate use reaction to the indiscriminate use of the of the goto goto statementstatement
FORTRAN 77 had no FORTRAN 77 had no while while looploop To implement a while construct, an IF To implement a while construct, an IF
statement and a restricted GOTO were statement and a restricted GOTO were used:used:
20 20 IF (X .LT. 10) GOTO 30IF (X .LT. 10) GOTO 30
--statements inside “loop”--statements inside “loop”
GOTO 20GOTO 20
30 --first statement after loop30 --first statement after loop
1.4 Data Types and Structures1.4 Data Types and Structures
Features for user-defined data types Features for user-defined data types enhance readabilityenhance readability
Record types for storing employee info Record types for storing employee info vs. a collection of related arrays (a la vs. a collection of related arrays (a la FORTRAN 77)FORTRAN 77)
CHARACTER (LEN=30) NAME(100)CHARACTER (LEN=30) NAME(100) INTEGER AGE(100)INTEGER AGE(100) INTEGER EMPLOYEE_NUMBER(100)INTEGER EMPLOYEE_NUMBER(100) REAL SALARY(100)REAL SALARY(100)
1.5 Syntax considerations1.5 Syntax considerations
Identifier formsIdentifier forms FORTRAN 77 (at most 6 chars, blanks FORTRAN 77 (at most 6 chars, blanks
ignored)ignored) Original ANSI Basic (a single letter Original ANSI Basic (a single letter
possibly followed by a single digit)possibly followed by a single digit)
Special wordsSpecial words Method for forming compound Method for forming compound
statementsstatements Pascal:begin..endPascal:begin..end
C:{ .. }C:{ .. } Ada:if .. end ifloop .. end loopAda:if .. end ifloop .. end loop Form and meaningForm and meaning
––Semantics should follow Semantics should follow from syntaxfrom syntax
WritabilityWritability
Simplicity and orthogonalitySimplicity and orthogonality
Support for abstractionSupport for abstraction Process abstractionProcess abstraction Data abstractionData abstraction
ExpressivityExpressivity
APL has powerful operators which APL has powerful operators which make it easy to accomplish a lot of make it easy to accomplish a lot of computation in a small programcomputation in a small program
forforstatements for counting loops statements for counting loops (instead of while) and then (instead of while) and then Boolean operator in AdaBoolean operator in Ada
ReliabilityReliability
Type CheckingType Checking
Subscript ranges in Adavs. CSubscript ranges in Adavs. C Static vs. dynamic type Static vs. dynamic type
checkingchecking
ReliabilityReliability
Exception HandlingException Handling
intercept run-time errors, intercept run-time errors, take corrective measures, take corrective measures, and continue processingand continue processing
PL/I, C++, Ada, JavaPL/I, C++, Ada, Java
AlisiangAlisiang
2 or more ways to reference the same 2 or more ways to reference the same memory cellmemory cell
Examples: pointers and unionsExamples: pointers and unions
Readability and writabilityReadability and writability
CostCost
Cost of training programmersCost of training programmers Cost of writing programsCost of writing programs Cost of compiling programsCost of compiling programs Cost of execution programsCost of execution programs Cost of the language Cost of the language
implementation systemimplementation system Cost of poor reliabilityCost of poor reliability Cost of maintaining programsCost of maintaining programs
Influences on Language Influences on Language DesignDesign
Computer architectureComputer architecture Imperative languages model the Imperative languages model the
von Neumann architecturevon Neumann architecture Functional programming Functional programming
languages (FPLs) will unlikely languages (FPLs) will unlikely displace imperative languages displace imperative languages until a non-von Neumann until a non-von Neumann architecture is developed which architecture is developed which implements them efficientlyimplements them efficiently
Programming methodologiesProgramming methodologies Top-down design and stepwise Top-down design and stepwise
refinementrefinement Data-oriented design vs. process-Data-oriented design vs. process-
oriented designoriented design Object-oriented designObject-oriented design Concurrency (process-oriented)Concurrency (process-oriented)
Language CategoriesLanguage Categories
ImperativeImperative FunctionalFunctional LogicLogic Object-orientedObject-oriented
Logic LanguageLogic Language
logic programming contributes logic programming contributes non-determinism, inversion and non-determinism, inversion and partial data structures partial data structures
OBJECT ORIENTED OBJECT ORIENTED PROG’GPROG’G Object-Oriented Programming (OOP) Object-Oriented Programming (OOP) is is
an approach to program organization and an approach to program organization and development that attempts to eliminate development that attempts to eliminate some of the pitfalls of the conventional some of the pitfalls of the conventional programming methods by incorporation the programming methods by incorporation the best of structured programming features best of structured programming features with several powerful new concepts. It is a with several powerful new concepts. It is a new way of organizing and developing new way of organizing and developing programs and has nothing to do with any programs and has nothing to do with any particular language. However, not all particular language. However, not all languages are suitable to implement the languages are suitable to implement the OOP concepts easily.OOP concepts easily.
Language Design Trade Language Design Trade OffsOffs
Reliability vs. cost of Reliability vs. cost of executionexecution
Ada’s runtime type checking Ada’s runtime type checking contributes to the cost of contributes to the cost of executionexecution
Readability vs. writabilityReadability vs. writability CC APLAPL
Flexibility vs. safetyFlexibility vs. safety Pascal variant record is a flexible Pascal variant record is a flexible
way to view a data object in way to view a data object in different ways, but no type different ways, but no type checking is donechecking is done
Implementation MethodsImplementation Methods
Compilation – programs are Compilation – programs are translated to machine translated to machine languagelanguage
The Compilation Process:The Compilation Process:
Source Program
optimization
Lexical units
Input Data
LexicalAnalyzer
SyntaxAnalyzer
Intermediate Code generator
Symbol Table
Code Generator
Computer
Parse Trees
Intermediate Code
Machine Language
Results
Pure Interpretation- programs Pure Interpretation- programs are interpreted by another are interpreted by another program called an interpreter program called an interpreter with no translation.with no translation.
Source ProgramSource Program
interpreter
Results
Input data
Hybrid implementation Hybrid implementation systems – source language systems – source language are decoded onceare decoded once
Example: Java appletsExample: Java applets Intermediate form is called byte Intermediate form is called byte
codecode Applets are downloaded in byte Applets are downloaded in byte
code form, then interpreted by code form, then interpreted by byte code interpreterbyte code interpreter
Source Program
LexicalAnalyzer
SyntaxAnalyzer
Intermediate Code generator
interpreter
Results
Intermediate Code
Lexical units
Parse tree
Programming EnvironmentsProgramming Environments
collection of tools used in collection of tools used in software developmentsoftware development
UNIXUNIX Borland C++Borland C++ SmalltalkSmalltalk Microsoft Visual C++ and Visual Microsoft Visual C++ and Visual
BasicBasic
Evolution of Major Evolution of Major Programming LanguageProgramming Language Zuse’s Plankalkul - 1945Zuse’s Plankalkul - 1945
By Konrad ZuseBy Konrad Zuse Means Program CalculusMeans Program Calculus It has integer, floating points, arraysIt has integer, floating points, arrays Allows selection but no elseAllows selection but no else Includes mathematical expressions showing Includes mathematical expressions showing
relationships between program variablesrelationships between program variablesExample Assignment Statement :Example Assignment Statement :
Statement : A(5) = A(4) + 1 Statement : A(5) = A(4) + 1 | A+ 1 => 1| A+ 1 => 1
V V | 4 5| 4 5 SS | 1.n 1.n| 1.n 1.n
The row labeled V is for subscript and the The row labeled V is for subscript and the row labeled S is for data type, 1.n means an row labeled S is for data type, 1.n means an integer of n bits.integer of n bits.
FORTRAN FORTRAN
is a statically typed, compiled is a statically typed, compiled imperative computer programming imperative computer programming language originally developed in the language originally developed in the 1950s and still heavily used for 1950s and still heavily used for scientific computing and numerical scientific computing and numerical computation half a century later. computation half a century later.
stands for Formula stands for Formula Translator/Translation. Translator/Translation.
Although originally a procedural Although originally a procedural language, recent versions of Fortran language, recent versions of Fortran have included some features to have included some features to support object-oriented programmingsupport object-oriented programming
Sample programsSample programs A simple Hello World program to A simple Hello World program to
be compiled and run with any be compiled and run with any Fortran 90 or 95 compiler.Fortran 90 or 95 compiler.
program helloprogram hello
print*,"Hello World!"print*,"Hello World!"
end program helloend program hello
LISPLISP
Lisp is a reflective, functional programming Lisp is a reflective, functional programming language language
Originally developed as a practical Originally developed as a practical computation model (in comparison to Alan computation model (in comparison to Alan Turing's), it later became the favored Turing's), it later became the favored artificial intelligence .artificial intelligence .
The language pioneered the use of tree The language pioneered the use of tree structures (S-expressions), automatic structures (S-expressions), automatic storage management, interpreters, and storage management, interpreters, and functional programming.functional programming.
Today, Lisp languages are used in many Today, Lisp languages are used in many fields, from web development to finance fields, from web development to finance [1], and are also common in computer [1], and are also common in computer science education.science education.
Lisp derives from "List Processing". Lisp derives from "List Processing". Linked lists are one of Lisp languages' Linked lists are one of Lisp languages'
major data structures, and identical basic major data structures, and identical basic list operations work in all Lisp dialects. list operations work in all Lisp dialects.
Other common features in Lisp dialects Other common features in Lisp dialects include dynamic typing, functional include dynamic typing, functional programming support, and the ability to programming support, and the ability to manipulate source code as data.manipulate source code as data.
ALLOWS metaprogramming – creating ALLOWS metaprogramming – creating programs which write other programs. programs which write other programs.
Today, the most widely-known general-Today, the most widely-known general-purpose Lisp dialects for programming are purpose Lisp dialects for programming are Common Lisp and Scheme.Common Lisp and Scheme.
Sample PROGRAM:Sample PROGRAM: Evaluate a number's factorial:Evaluate a number's factorial:
(defun factorial (n)(defun factorial (n)
(if (<= n 1)(if (<= n 1)
11
(* n (factorial (- n 1)))))(* n (factorial (- n 1)))))
ALGOLALGOL
short for ALGOrithmic Languageshort for ALGOrithmic Language is a family of imperative computer is a family of imperative computer
programming languages originally programming languages originally developed in the mid 1950sdeveloped in the mid 1950s
It was designed to avoid some of the It was designed to avoid some of the perceived problems with FORTRAN and perceived problems with FORTRAN and eventually gave rise to many other eventually gave rise to many other programming languages (including Pascal).programming languages (including Pascal).
ALGOL uses bracketed statement blocks ALGOL uses bracketed statement blocks and was the first language to use begin and was the first language to use begin end pairs for delimiting them. Fragments of end pairs for delimiting them. Fragments of ALGOL-like syntax are sometimes still ALGOL-like syntax are sometimes still used as a notation for algorithms, so-called used as a notation for algorithms, so-called Pidgin Algol.Pidgin Algol.
Sample Program from Sample Program from ElliottAlgolElliottAlgol
program HiFolks;program HiFolks;
beginbegin
print "Hello world";print "Hello world";
end;end;
COBOLCOBOL
is a third-generation programming is a third-generation programming language. Its name is an acronym, language. Its name is an acronym, for COmmon Business Oriented for COmmon Business Oriented Language, defining its primary Language, defining its primary domain in business, finance, and domain in business, finance, and administrative systems for administrative systems for companies and governments.companies and governments.
The COBOL 2002 standard includes The COBOL 2002 standard includes support for object-oriented support for object-oriented programming and other modern programming and other modern language features. However, most of language features. However, most of this article is based on COBOL 85.this article is based on COBOL 85.
Hello world* IDENTIFICATION DIVISION. * IDENTIFICATION DIVISION. Program-Id. Hello-World. Program-Id. Hello-World.
* ENVIRONMENT DIVISION. * ENVIRONMENT DIVISION. * DATA DIVISION. * DATA DIVISION.
* PROCEDURE DIVISION. * PROCEDURE DIVISION.
Para1. DISPLAY "Hello, world.".Para1. DISPLAY "Hello, world.".
* Stop Run. * Stop Run.
BASICBASIC
is a family of high-level programming is a family of high-level programming languages. Originally devised as an easy-languages. Originally devised as an easy-to-use programming language, ito-use programming language, i
BASIC's name, coined in classic, computer BASIC's name, coined in classic, computer science tradition to produce a nice science tradition to produce a nice acronym, stands for Beginner's All-purpose acronym, stands for Beginner's All-purpose Symbolic Instruction Code, tied to the Symbolic Instruction Code, tied to the name of an unpublished paper by the name of an unpublished paper by the language's co-inventor, Thomas Kurtz (the language's co-inventor, Thomas Kurtz (the name thus having no relation to C.K. name thus having no relation to C.K. Ogden's series "Basic English").Ogden's series "Basic English").
The eight design principles of BASIC The eight design principles of BASIC were:were:
Be easy for beginners to use Be easy for beginners to use Be a general-purpose programming language Be a general-purpose programming language Allow advanced features to be added for Allow advanced features to be added for
experts (while keeping the language simple experts (while keeping the language simple for beginners) for beginners)
Be interactive Be interactive Provide clear and friendly error messages Provide clear and friendly error messages Respond fast for small programs Respond fast for small programs Not require an understanding of computer Not require an understanding of computer
hardware hardware Shield the user from the operating system Shield the user from the operating system
The Basic Family:The Basic Family: MS-DOS/PC-DOS : BASICA, GW-BASIC Quick BASIC. Turbo BASIC MS-DOS/PC-DOS : BASICA, GW-BASIC Quick BASIC. Turbo BASIC Window Based: Visual Basic, Visual Basic for Applications (VBA) , VBScript Window Based: Visual Basic, Visual Basic for Applications (VBA) , VBScript
VB.NET. VB.NET. Sample Program:Sample Program:
10 PRINT "Hello, world!“10 PRINT "Hello, world!“20 END 10 INPUT "What is your name: "; U$ 20 END 10 INPUT "What is your name: "; U$ 20 PRINT "Hello "; U$ 20 PRINT "Hello "; U$ 25 REM 25 REM 30 INPUT "How many stars do you want: "; N 30 INPUT "How many stars do you want: "; N 35 S$ = "" 35 S$ = "" 40 FOR I = 1 TO N 40 FOR I = 1 TO N 50 S$ = S$ + "*" 50 S$ = S$ + "*" 55 NEXT I 60 PRINT S$ 55 NEXT I 60 PRINT S$ 65 REM 65 REM 70 INPUT "Do you want more stars? "; A$ 70 INPUT "Do you want more stars? "; A$ 80 IF LEN(A$) = 0 THEN GOTO 70 80 IF LEN(A$) = 0 THEN GOTO 70 90 A$ = LEFT$(A$, 1)90 A$ = LEFT$(A$, 1)100 IF (A$ = "Y") OR (A$ = "y") THEN GOTO 30100 IF (A$ = "Y") OR (A$ = "y") THEN GOTO 30110 PRINT "Goodbye ";110 PRINT "Goodbye ";120 FOR I = 1 TO 200120 FOR I = 1 TO 200130 PRINT U$; " ";130 PRINT U$; " ";140 NEXT I140 NEXT I150 PRINT 150 PRINT