Vous êtes sur la page 1sur 3

John C.

Ramirez

Language Development Issues


2

Course Notes for

CS18

Programming Languages
LANGUAGE DEVELOPMENT DESIGN & ISSUES

by
LAARNI C. DESENGAO PANCHO, MIT

Why do we have high-level programming

languages?

Machine code is too difficult for us to read, understand and debug


Machine code is not portable between architectures

Why do we have many high-level programming

languages?

Department of Computer Science and IT

Different people and companies developed them


Different languages are either designed to or happen to meet
different programming needs

Bicol University

Language Development Issues

Language Development Issues

Scientific applications
FORTRAN
Business
COBOL

applications

AI
LISP, Scheme (& Prolog)
Systems
C

programming

Web programming
Perl, PHP, Javascript

Programming language qualities and evaluation

criteria

Readability
How much can non-author understand logic of code just by
reading it?
Is code clear and unambiguous to reader?
These are often subjective, but sometimes is is fairly obvious
Examples of features that help readability:

General purpose
C++, Ada, Java

Language Development Issues

Comments
Long identifier names
Named constants
Clearly understood control statements

Language Development Issues

Language orthogonality
Simple features combine in a consistent way
But it can go too far, as explained in the text about Algol 68

Writability

Not dissimilar to readability


How easy is it for programmer to use language effectively?
Can depend on the domain in which it is being used
Ex: LISP is very writable for AI applications but would not be so good for systems
programming

Also somewhat subjective


Examples of features that help writability:

Reliability
1.

Two different ideas of reliability


Programs are less susceptible to logic errors

2.

Programs have the ability to recover from exceptional situations

Ex: Assignment vs. comparison in C++


See assign.cpp and assign.java
Exception handling
Ex: C error with = meant as comparison
Ex: Compare to Java

Clearly understood control statements


Subprograms
Also orthogonality

CS 1520 Lecture Notes

John C. Ramirez

Language Design Issues

Language Design Issues

Many factors influence language design

Imperative language evolution

Architecture

Most languages were designed for single processor von


Neumann type computers

Some consider object-oriented languages not to be imperative,


but most modern oo languages have imperative roots (ex. C++,
Java)
Functional languages
Focus is on function and procedure calls
Mimics mathematical functions
Less emphasis on variables and assignment
In strictest form has no iteration at all recursion is used
instead

CPU to execute instructions


Data and instructions stored in main memory

General language approach

Simple straight-line code


Top-down design and process abstraction
Data abstraction and ADTs
Object-oriented programming

Imperative languages
Fit well with von Neumann computers
Focus is on variables, assignment, selection and iteration
Examples: FORTRAN, Pascal, C, Ada, C++, Java

Language Design Issues

Language Design Issues

Examples: LISP, Scheme


See example
Give short example of a LISP program segment
(equal (a b) (car ((a b) c d e)))

Logic programming languages


Symbolic logic used to express propositions, rules and
inferences
Programs are in a sense theorems
User enters a proposition and system uses programmers rules
and propositions in an attempt to prove it
Typical outputs:
Yes: Proposition can be established by program
No: Proposition cannot be established by program

10

Example: Prolog see example program

Language Implementation Issues

Cost

What are the overall costs associated with a given language?

Training programmers

How does the design affect that cost?


How easy is it to learn?

Writing programs

Compiling programs

Is language a good fit for the task?


How long does it take to compile programs?
This is not as important now as it once was

Executing programs

How long does program take to run?


Often there is a trade-off here
Ex: Java is slower than C++ but it has many run-time features (array bounds checking, security
manager) that are lacking in C++

Language Implementation Issues

11

How is HLL code processed and executed on the


computer?
Compilation

Source code is converted by the compiler into binary code


that is directly executable by the computer
Compilation process can be broken into 4 separate steps:
1)
Lexical Analysis

Breaks up code into lexical units, or tokens


Examples of tokens: reserved words, identifiers,
punctuation
Feeds the tokens into the syntax analyzer

CS 1520 Lecture Notes

12
2)

Syntax Analysis

3)

Tokens are parsed and examined for correct syntactic


structure, based on the rules for the language
Programmer syntax errors are detected in this phase

Semantic Analysis/Intermediate Code Generation

Declaration and type errors are checked here


Intermediate code generated is similar to assembly code
Optimizations can be done here as well, for example:

4)

Unnecessary statements eliminated


Statements moved out of loops if possible
Recursion removed if possible

Code Generation

Intermediate code is converted into executable code


Code is also linked with libraries if necessary

John C. Ramirez

Language Implementation Issues

Language Implementation Issues

13

14

Note that steps 1) and 2) are independent of the architecture


depend only upon the language Front End
Step 3) is somewhat dependent upon the architecture, since,
for example, optimizations will depend upon the machine
used
Step 4) is clearly dependent upon the architecture Back End

Interpreting

Program is executed in software, by an interpreter


Source level instructions are executed by a virtual machine
Allows for robust run-time error checking and debugging
Penalty is speed of execution
Example: Some LISP implementations, Unix shell scripts and Web
server scripts

Language Implementation Issues


15

Hybrid

First 3 phases of compilation are done, and intermediate code is


generated
Intermediate code is interpreted
Faster than pure interpretation, since the intermediate codes are
simpler and easier to interpret than the source codes
Still much slower than compilation
Examples: Java and Perl
However, now Java uses JIT Compilation also

Method code is compiled as it is called so if it is called again it will be


faster

CS 1520 Lecture Notes

Vous aimerez peut-être aussi