CSC 150 UNGRADED QUIZ - Concordia University Wisconsin

Download Report

Transcript CSC 150 UNGRADED QUIZ - Concordia University Wisconsin

PROGRAMMING
LANGUAGES
(1) Review.
(2) Types of programming language.
(3) How are programs translated to
binary?
(4) Diversity of languages.
1. Review.




Review: Why can’t we program in English?
1) Too vague (“several,” “most,” “a few”)
2) Ambiguous (“bat,” “glasses,” “trunk”)
3) Too powerful (can make statements no
computer can execute e.g. “Fall in love!”
 “Repent!” “Have a nice day!”).
Review: What are programming
languages?
 Definition.
 A programming language is a formal,
symbolic language, which is:
 (1) Unambiguous,
 (2) Precise,
 (3) Limited to operations a CPU can
perform (input, calculate, compare, output).
2. Types of programming
language.
 A. LOW-LEVEL.
 Assembly is called a low-level language
because its statements directly manipulate
the hardware (e.g. registers used for
calculation). It is really just symbolic
shorthand for machine language.
 e.g. MOV AX, 0
 [move 0 to the AX register]
Assembly continued.
 Because Assembly is so close to the
hardware, it is “machine specific” or
“non-portable”: you cannot expect an
Assembly program to work on a computer
with a different internal architecture.
 Assembly is written for specific families of
processors e.g. for 80X86 processors.
Assembly continued.
 Assembly is also very hard to understand.
To program in Assembly you need to
understand the internal architecture of the
machine and how it works.
 Analogy: like needing to know how the
engine works to tune it.
Types of programming language.
 B. HIGH-LEVEL.
 For business and scientific purposes,
Assembly is a nuisance because
 (a) it is not portable
 (b) only experts can use it.
 To make programming more accessible and
portable, high-level languages were
developed.
High-level languages cont.
 High-level languages use humanly
understandable verbs and variable names,
and then a compiler takes care of translating
them into machine language.
 The same source code can then be compiled
differently for many different machines,
allowing portability.
 Eg.s. COBOL, PASCAL, FORTRAN, C,
 C++.
3. How are programs translated
to binary?
 Like any language, programming languages
have a syntax:
 GRAMMAR, VOCABULARY,
SPELLING, PUNCTUATION.
 We type in source code e.g. in C++.
 All of this source code has to be translated
into object code (in binary machine
language).
How programs are translated to
binary continued.
 Translation to binary is performed by three
types of systems software:
 (1) an ASSEMBLER, used to translate lowlevel Assembly to machine code;
 (2) an INTERPRETER, used to translate a
high-level language one line at a time
(correct lines get translated and executed
even if there are errors later);
How programs are translated to
binary continued.
 (3) A COMPILER is used to translate an
entire high-level program into machine
language. It is “all or nothing”: if the
source code contains even one syntax error
no object code is produced. If the source
code contains no errors, object code is
produced and can be loaded into RAM and
executed.
How programs are translated to
binary continued.
 ANALOGY FOR A COMPILER
 The compiler is like God’s Law: it sets a
standard of perfection.
 However, whereas we cannot save ourselves
(we need the Gospel) we can save a
program, through….
 Editing and fixing our errors.
How does the compiler work?
 A. Variable names are translated into the
addresses of storage in memory.
 A symbol table keeps track of the
correlation between the identifier and the
storage location.
 B. A dictionary is used to translates each
High-Level Language (HLL) instruction to
its Machine Language (ML) equivalent.
4. Diversity of languages.
 Why are there so many different HLLs?
 A. Different kinds of application (e.g. for
engineering, use FORTRAN, for operating
systems, use C, for business, use COBOL).
 B. Different problem-solving paradigms.
 There are 5 main ways of conceiving how
to solve a problem.
Language Paradigms.





1. Procedural/imperative paradigm:
need to specify each step, show HOW to
solve it, e.g. Pascal, C, FORTRAN
2. Functional paradigm:
devise functions which solve the
problem e.g. LISP
Language Paradigms.
 3. Logic / declarative paradigm:
 Use logic to define rules and facts, solution
is then proved e.g. PROLOG.
 Brother (X, Y) : = Mother (Z, X)

AND Mother (Z, Y) AND Male (X)
 Mother (Jane, Fiona). Mother (Jane, John)
 Male (John) , so logically.......?
Language Paradigms.
 . 4. Object-oriented language:
 Bundles data and tools to manipulate data
into reusable components (“objects”).
 Used in modern Windows programming.
 E.g. C++.
 E.g. A basic window is viewed as an object,
consisting of attributes of the window and
functions for changing those attributes.
Language Paradigms.
 5. Structured query language for
databases.
 Here we need only specify WHAT we want
to obtain it (we don’t have to know HOW it
is retrieved):
 FIND EMPLOYEE

WITH SALARY = 83000
 Professor Locklair!