01 introduction

56
Nature of Programming Languages Introduction Nguyn Hu Đc Faculty of Information Technology Hanoi University of Technology

Upload: trk2012

Post on 23-Jun-2015

56 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: 01 introduction

Nature of Programming LanguagesIntroduction

Nguyễn Hữu Đức

Faculty of Information TechnologyHanoi University of Technology

Page 2: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Contents I

1 Introduction

2 What is a Programming Language?

3 Abstractions in Programming Languages

4 Computational Paradigms

5 Language Definition

6 Language Translation

7 Language Design

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 2 / 54

Page 3: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Goal of this course

There are over 2500 programming languages

We shall not study any special programming language

We are going to study major principles and concepts of programminglanguages.

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 3 / 54

Page 4: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Computers and Programming Languages

Before 1940s: “hard-wired” computers“Special purpose” computing

After 1940s: John Von Neumann’s computersseries of codes could be stored as data and would be executed by CPU“General purpose” computing

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 4 / 54

Page 5: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

John Von Neumann’s Machine

developed in 1940’s so that a series of codes could be stored in memoryas data and would be executed by CPU.

“memory” : where programs and data are stored

“CPU” : sequentially executes instructions

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 5 / 54

Page 6: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

What is a Programming Language?

binary instructionslow-level languages (i.e. assembly)

machine-dependentdifficult to write and to understand programslow-level of abstraction

high-level languages (i.e. C, Java,...)higher-level of abstractioncode does not change (or little change) from machine to machineeasier to write and to understand

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 6 / 54

Page 7: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

What is a Programming Language?

DefinitionA programming language is a notational system for describing computation inmachine-readable and human-readable form.

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 7 / 54

Page 8: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Computation

Turing machineA mathematical model of computationHigh precisionCan carry out any computation that any current computer can carry out

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 8 / 54

Page 9: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Computation

Church’s thesisIt is not possible to build a machine more powerful than a Turing machine

Practical aspect of this courseincluding mathematical computation, text processing, information storageand retrieval,...concentrating on “general purpose” programming languages (“specialpurpose” languages exist)

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 9 / 54

Page 10: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Machine readability

Machine-readable language can be translated efficially by a computerinto a form that can be executed by the target computer.

There must be an algorithm that translates the languageThis step-by-step process is unambiguous and finiteThe algorithm mus be able to translate in time proportional to the size ofthe program

O(n) complexity

Machine readability is ensured by restricting the structure of aprogramming language to that of “context-free languages”

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 10 / 54

Page 11: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Human readability

Require that a programming language provide abstractions of the actionsof computers that are easilly understood

By someone who is not familiar with the details of the underlyingcomputerProgramming languages should tend to resemble natural languages

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 11 / 54

Page 12: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Human readability

Require suitable mechanisms for reducing the amount of detail requiredfor understanding the whole program

A small change to one part of a program should not require major changesto the entire programRequires collection of local information in one place

Programming language is part of the software development environmentMany people involved in software development

We will not study PLs from software engineering point of view

We will focus on languages themselves

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 12 / 54

Page 13: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Two Categories of Abstraction

Data abstractionabstract properties of data (strings, numbers, ...) which is the subject ofcomputation

Control abstractionabstract properties of the transfer of controlEx. loops, conditional statements, procedure calls

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 13 / 54

Page 14: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Three Levels of Abstraction

Basic abstractionscollect together the most localized machine information

Structured abstractionscollect more global information about the structure of the program

Unit abstractioncollect information about entire pieces of a program

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 14 / 54

Page 15: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Data Abstractions - Basic Abstraction

Abstract internal representation of the common data valuesEx. integers are often stored in computer using a two’s complementrepresentationEx. floating point values are stored using IEEE 754 standard

Locations in memory are abstracted by a name – a variable

Kind of data values is given a name – data type

Examplevar x : integer; // PASCALint x; // C

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 15 / 54

Page 16: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Data Abstractions - Structured Abstraction

Data structures abstract collection of data that are relatedArrayRecord in Pascal or struct in Cdatatype in ML

Exampleint a[10]; // Array in C

struct Tree { // struct in Cstruct Tree *left, *right;void *data;

}

datatype ’a tree = // datatype in MLNil

| Node of {left : ’a tree, right : ’a tree, data : ’a}

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 16 / 54

Page 17: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Data Abstractions - Unit Abstraction

Collect related code into specific locations in the programData encapsulation and Information Hiding

Ex. modules in ML, classes in object-oriented languages, packages in Javaclass is also considered as a structured abstraction

ReusabilityAbility of reuse data abstration in different parts of a programSave writing code from scratchComponents : Operationally complete pieces of programsContainers : Data structures containing other user-defined data

Basis for language library

Many interface standards (COM, CORBA)

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 17 / 54

Page 18: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Control Abstractions - Basic Abstraction

Statements in a programming languagecombine a few machine instruction into a more understandable abstractstatementEx. “x := x + 3” fetches, adds and stores valuesEx. “GOTO 10” abstracts the jump instruction

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 18 / 54

Page 19: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Control Abstractions - Structured Abstraction

Divide a program into groups of instructions that are nested within teststhat govern their execution

Selection statement (“if”, “case”)

They can be nested

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 19 / 54

Page 20: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Control Abstractions - Structured Abstraction

Selection statement in Cif (x > 0) {numSols = 2;r1 = sqrt(x);r2 = - r1;

} else {numSols = 0;

}

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 20 / 54

Page 21: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Control Abstractions - Structured Abstraction

Selection statement in MLcase numSols(x) of0 => []2 => [sqrt(x), - sqrt(x)]

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 21 / 54

Page 22: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Control Abstractions - Structured Abstraction

Looping mechanisms: for, while, repeat ... until,loop

Subroutines (procedures)Allows programmer to consider sequence of actions as one actionSubroutines must be declaredSubroutines must be called (they have point of invocation or activation)Formal parameters are defined in declarationArguments or actual parameters are passed when subroutine calledInformation about subroutine must be saved at the point of invocation andrestored when subroutine finishes

Runtime environment or operational stack

A subroutine can return a value or does not need to return a value whenfinished

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 22 / 54

Page 23: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Control Abstractions - Structured Abstraction

Loop and subroutine in Cint gcd(int u, int v) {

int x = u;int y = v;int t;while ( y != 0) {

t = y;y = x % yx = t;

}return x;

}

Loop and subroutine in MLfun gcd(x, 0) = x| gcd(x, y) = gcd(y, x mod y)

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 23 / 54

Page 24: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Control Abstractions - Unit Abstraction

Procedures can be collected into a package or a program unitCarefully controlled interfacesCan be understood without knowing the detailsReusability and library buiding are the same as data unit abstraction

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 24 / 54

Page 25: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Parallel Programming Mechanism

Programming languages that are capable of executing parts of a programsimultaneously

They also have mechanism for synchronization and communicationamong programs or parts of a program

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 25 / 54

Page 26: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Abstraction Mechanism

All abstractions are provided for human readability

They should also provide all mechanisms to do any computation that aTuring machine can do

Turing completeA programming language is Turing complete provided it has integer variablesand arithmetic and sequentially executes statements, which include asignment,selection (if) and loop (while) statement.

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 26 / 54

Page 27: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Computational Paradigms

Most of programming languages are designed based on Von Neumannmodel

Sequential execution of instructionsVariables represent memory locationsAsignment allows program to operate on these memory variables

Programming languages characterized by these properties are calledimperative (or procedural) programming languagesIt is not neccessary for a programming language to be imperative

Von Neumann model restricts parallel computation, non-deterministiccomputation, or computation that does not depend on order (VonNeumann Bottleneck)

Computational paradigmsImperative paradigmFunctional paradigmLogic paradigmObject-oriented paradigm

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 27 / 54

Page 28: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Computational Paradigms - Imperative Paradigm

Properties of imperative programming languagesSequential execution of instructionsVariables represent memory locationsAsignment allows program to operate on these memory variablesSequentially execution of statementsAlso called “procedural” programming languages

Most PLs today based on this model

Deterministic computation

Can’t use this to describe parallel computation

Typical examples: FORTRAN, PASCAL, C

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 28 / 54

Page 29: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Imperative Paradigm

Example of gcd in Cint gcd(int u, int v) {

int x = u;int y = v;int t;while ( y != 0) {

t = y;y = x % yx = t;

}return x;

}

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 29 / 54

Page 30: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Computational Paradigms - Functional Paradigm

Based on description of computation on the evaluation of functions orthe application of functions to known values

Also called “applicative” languagesFunctional call

Passing the values as parametersActual evaluation of functionReturning values

No notion of variable or assignment

Repetitive operation can be done with recursion instead of loops

Typical examples: LISP, SCHEME, ML, HASKEL

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 30 / 54

Page 31: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Functional Paradigm

Example of gcd in MLfun gcd(x, 0) = x| gcd(x, y) = gcd(y, x mod y)

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 31 / 54

Page 32: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Computational Paradigms - Logic Paradigm

Based on symbolic logic

Program is a set of statements that describe what is true about a desiredresult

No loops or selections

Control is suplied by the underlying program

Also called “descritive” language

Typical example: PROLOG

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 32 / 54

Page 33: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Logic Paradigm

Example of gcd in PROLOGgcd(U, V, U) :- V = 0gcd(U, V, X) :- not(V = 0),

Y is U mod V,gcd(V, Y, X)

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 33 / 54

Page 34: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Computational Paradigms - Object-oriented Paradigm

Based on notion of an object which can be loosely described as acollection of memory locations together with all the operations that canchange the values of these memory locations

Objects are grouped into classes that represent all the objects with thesame properties

Object can be created as an instance of a class

Members represent memory locations

Methods represent operations on these memory locations

Provide data encapsulation and information hiding

Typical example: C++, JAVA

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 34 / 54

Page 35: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Object-oriented Paradigm

Example of gcd in JAVApublic class IntWithGcd {public IntWithGcd(int val) {value = val;}public int intValue() { retuen value; }public int gcd(int v) {

int z = value;int y = v;while ( y != 0) {

int t = y;y = z % y;z = t;

}return z;

}

private int value;};

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 35 / 54

Page 36: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Definition

A complete, precise description is neededTo know precisely what a computation does

Even today, most PLs are described informally by the so-call “referencemanual”

Reference manual is not preciseWith these definitions, it is possible to reason mathematically aboutprograms

formal verification, proof of behavior

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 36 / 54

Page 37: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Definition

Formal definition of a language leads to standadizationLanguage becomes independent of hardware platform, OS, ...

ANSI (American National Standards Institute) and ISO (InternationalOrganization for Standardization) standards

definitions of many languages including PASCAL, FORTRAN, C, C++,Ada, PROLOG

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 37 / 54

Page 38: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Definition

From practical point of view, formal definition neededbecause question about program’s behavior may ariseto provide discipline during the design of the language

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 38 / 54

Page 39: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Definition

Two parts of language definitionSyntax : structure of the languageSemantics : Meaning of the language

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 39 / 54

Page 40: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Syntax

Language syntax is like the grammar of a natural languageLanguage syntax can be given in context free grammar form

<if-statement> ::= if (<expression>) <statement>[else <statement>]

Language syntax can be given in form using special character andformatting

if-statement ::= if (expression) statement [else statement]

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 40 / 54

Page 41: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Syntax

Lexical structureSimilar to spelling in a natural languageprovide structure of words or token in the language

if, else are token“+”, “<=” are token“;”, “.” are token

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 41 / 54

Page 42: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Semantics

Semantics describes the meaning of the languageeffect of execution of a piece of codemuch more complex and difficult to describe precisely

C if-statement, Kernighan and Richie [1988]An if-statement is executed by first evaluating its expression, which must havearithmetic or pointer type, including all side effects, and if it comparesunequal to 0, the statement following the expression is executed. If there is anelse part, and the expression is 0, the statement following the “else” isexecuted.

What’s happen if there is no else part?

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 42 / 54

Page 43: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Semantics

Usin formal methods to describe the language semanticsNo generally accepted methodThere are several methods

operational semanticsdenotational semanticsaxiomatic semantics

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 43 / 54

Page 44: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Translation

There must be a translator that accepts a program written in theprogramming language and

either executes the program directly (interpreter)or transforms into a form in which it can be executed (compiler)

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 44 / 54

Page 45: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Interpretation

Source code

input outputinterpreter

one-step process that simulates the underlying machine

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 45 / 54

Page 46: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Compilation

Executable code

input outputprocessor

Source code

targetcode

Executablecodecompile further

transtaltion

two-step process that simulates the underlying machineoutput of the compiler is called the target codemost common target language is assembler languageassembler program is then generated to object code of the underlyingmachine and then linked with other object codes by a linker and loadedinto memory by a loader

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 46 / 54

Page 47: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Compilation

Pseudo-translatertranslates a source program into an intermediate codeinterpreter will execute the intermediate code

A language is different from a translator for that languageSome translators may or may not adhere closely to the language definition

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 47 / 54

Page 48: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Phases of a Translator

Lexical Analyzer (or scanner) converts source code (in text form) intosequence of tokens representing keywords, identifiers, constants,...

Syntax Analyzer (or parser) determines structure of the sequence oftoken

Semantic Analyzer must determine enough of the meaning of theprogram to allow the execution of the target code

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 48 / 54

Page 49: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Operations Performed by a Translator

Translater must maintain a run-time environment which has suitablememory for program data and record the progress of execution

Interpreter itself maintains a run-time environmentCompiler maintains run-time environment indirectly through target code

Language may require a pre-processor which is run to make the programsuitable for translation

Example#define PI 3.14

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 49 / 54

Page 50: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Static and Dynamic Properties

Static propetiesDetermined prior to executionStatic memory allocation: all variables located in a fixed possitions duringthe execution

Dynamic propetiesDetermined during the executionDynamic memory allocation

Static properties are useful for compilers

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 50 / 54

Page 51: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Static and Dynamic Properties

Language with large amount of static properties more suitable forcompilation

Language with large amount of dynamic properties more suitable forinterpretation

Imperative languages tend to be compiled

Functional and logic languages tend to be interpreted

Languages like C have both aspects

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 51 / 54

Page 52: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Efficiency

Interpreted language generally less efficient than compiled language

Compiler efficiency can be boosted by optimization

Interpreters are better than compilers if interactive input and outputrequired

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 52 / 54

Page 53: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Error-handling

Translators should try to fix errors or provide meaningful error messages

Translators should be able to find more errors after the first one caughtErrors can be caught by

scanner: use illegal charactersparser: syntax error (Ex. x = 2 +* 6)semantic analyser: undefined variables, incompatible type

Semantic error can be found during the executionIndex out-of rangeDivide by zero

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 53 / 54

Page 54: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Error-handling

Not all logic error can be found by the language translator (Ex. infiniteloops)Language specification often specifies

What error must be caught at compile timeWhat error must be generated at run timeWhat error go undetected

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 54 / 54

Page 55: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Debugging

Translator must provide option for debugging, for interfacing with OSand with IDE

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 55 / 54

Page 56: 01 introduction

Introduction What is a Programming Language? Abstractions in Programming Languages Computational Paradigms Language Definition Language Translation Language Design

Language Design

Machine readability and Human readability are main requirements

Data abstractions and control abstractions

Complexity control

Nature of programming Languages N.H. Đức FACULTY OF INFORMATION TECHNOLOGY 56 / 54