Analysis of Programming Languages

 
Analysis of Programming
Languages
 Vladimir Viies 
vladimir.viies@gmail.com
,
Lembit Jürimägi 
lembit.jyrimagi@gmail.com
 
 Tallinna Tehnikaülikool
 2020
 
Subject goals
 
A
 
s
t
u
d
e
n
t
 
h
a
s
 
t
o
 
b
e
 
a
b
l
e
:
t
o
 
a
s
s
o
c
i
a
t
e
 
t
a
s
k
s
 
w
i
t
h
 
a
 
s
u
i
t
a
b
l
e
a
l
g
o
r
i
t
h
m
i
c
 
l
a
n
g
u
a
g
e
;
t
o
 
d
e
s
i
g
n
 
a
 
s
p
e
c
i
a
l
 
p
u
r
p
o
s
e
a
l
g
o
r
i
t
h
m
i
c
 
l
a
n
g
u
a
g
e
 
a
n
d
 
c
r
e
a
t
e
a
 
c
o
m
p
i
l
e
r
 
f
o
r
 
i
t
;
 
3
 
 
Subject  contents I
 
C
l
a
s
s
i
f
i
c
a
t
i
o
n
 
o
f
 
a
l
g
o
r
i
t
h
m
i
c
 
l
a
n
g
u
a
g
e
s
.
U
n
i
v
e
r
s
a
l
 
a
n
d
 
s
p
e
c
i
f
i
c
 
l
a
n
g
u
a
g
e
s
.
C
o
m
p
a
r
i
s
o
n
 
o
f
 
t
h
e
 
p
o
s
s
i
b
i
l
i
t
i
e
s
 
o
f
 
d
a
t
a
t
y
p
e
s
,
 
s
e
n
t
e
n
c
e
s
 
a
n
d
 
i
n
t
r
a
m
o
d
u
l
a
r
 
d
a
t
a
e
x
c
h
a
n
g
e
 
i
n
 
d
i
f
f
e
r
e
n
t
 
l
a
n
g
u
a
g
e
s
 
(
F
O
R
T
R
A
N
 
,
P
L
/
1
,
 
P
A
S
C
A
L
,
 
A
s
s
e
m
b
l
e
r
 
e
t
c
.
)
.
A
s
s
e
m
b
l
e
r
.
T
r
a
n
s
l
a
t
o
r
s
,
 
t
h
e
i
r
 
c
o
m
p
o
n
e
n
t
s
 
a
n
d
 
w
o
r
k
p
r
i
n
c
i
p
l
e
s
.
A
r
t
 
o
f
 
t
r
a
n
s
l
a
t
o
r
 
d
e
s
i
g
n
.
 
 
4
 
 
 POINTS I(EXAM)
 
 
 
5
 
 
Points
 II(EXAM & PERMISSION)
 
P
r
a
c
t
i
c
e
(
T
1
+
T
2
)
 
 
m
a
x
2
0
p
H
o
m
e
w
o
r
k
 
(
t
r
a
n
s
l
a
t
o
r
)
 
 
m
a
x
1
5
p
P
r
e
s
e
n
t
a
t
i
o
n
 
(
l
a
n
g
u
a
g
e
s
)
 
 
m
a
x
1
0
p
S
e
m
i
n
a
r
 
 
m
a
x
5
p
W
r
i
t
t
e
n
 
e
x
a
m
i
n
a
t
i
o
n
 
 
m
a
x
5
0
p
P
e
r
m
i
s
s
i
o
n
 
t
o
 
e
x
a
m
i
n
a
t
i
o
n
(
3
0
p
)
 
 
m
i
n
 
1
0
p
r
a
c
t
(
m
a
x
2
0
)
 
+
 
m
i
n
 
 
2
0
t
e
s
t
 
(
m
a
x
 
3
0
)
 
6
 
 
Course structure
 
I
 
m
o
d
u
l
e
:
 
P
r
a
c
t
i
c
e
(
t
r
a
n
s
l
a
t
o
r
d
e
s
i
g
n
)
I
I
 
m
o
d
u
l
e
:
 
 
S
e
m
i
n
a
r
s
(
C
o
m
p
a
r
i
s
o
n
 
o
f
 
t
h
e
 
p
o
s
s
i
b
i
l
i
t
i
e
s
i
n
 
d
i
f
f
e
r
e
n
t
 
l
a
n
g
u
a
g
e
s
 
)
I
I
I
 
m
o
d
u
l
e
:
H
o
m
e
w
o
r
k
s
 
 
 
 
 
 
7
 
Course timetable
 
  1.
 
31.08.2020
 
Introduction
  2.
 
07.09.2020
 
Regular Languages, Regular Expressions, Flex
  3.
 
14.09.2020
 
Context Free Grammar, Bison, Postfix/Infix Calculator
  4.
 
21.09.2020
 
Practice Task 1
  5.
 
28.09.2020
 
Abstract Syntax Tree, General Purpose Language
  6.
 
05.10.2020
 
Evolution of Programming Languages
  7.
 
12.10.2020
 
Data types and conversion
  8.
 
19.10.2020
 
Test
  9.
 
26.10.2020
 
Machine Language, Assembly Language
10.
 
02.11.2020
 
Functional Language
11.
 
09.11.2020
 
Practice Task 2
12.
 
16.11.2020
 
Practice Task 2
13.
 
23.11.2020
 
Guest lecturer
14.
 
30.11.2020
 
Guest lecturer
15.
 
07.12.2020
 
Presentation
16.
 
14.12.2020
 
Exam
 
 
8
 
Subject  contents II
 
                            LET'S BUILD A COMPILER!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
B
y
 
 
J
a
c
k
 
W
.
 
C
r
e
n
s
h
a
w
,
 
P
h
.
D
.
This file contains all of the installments of Jack Crenshaw's
tutorial on compiler construction.
The intended audience is those folks who are not computer scientists,
but who enjoy computing and have always wanted to know how compilers
work. A lot of compiler theory has been left out, but the practical
issues are covered. By the time you have completed the series, you
should be able to design and build your own working compiler. It will
not be the world's best, nor will it put out incredibly tight code.
Your product will probably never put Borland or MicroSoft out of
business.  But it will work, and it will be yours
 
9
 
 
Presentation 
(analysis question list)
 
(
a
n
a
l
y
z
e
 
d
i
f
f
e
r
e
n
t
 
l
a
n
g
u
a
g
e
s
)
- field where language is used (general purpose hardware, gpu,
vm, web etc), proximity to hardware(What problem is language
meant to solve?)
...
- compiled or interpreted, comparative speed to other languages
...
- strongly typed vs weakly typed, examples, data type conversion?
- single thread vs multithread, handling of parallelism, examples
...
- memory handling, explicit memory allocation vs implicit,
examples
...
- what sort of problems would you use this language for?
- if you could improve on this language what would you add to it or
remove from it?
- extending the functionality of language, dlls, apis
...
- is the purpose of the code understandable when looking at code
(assembler - no, pascal - somewhat, scripting languages – yes)
...
- effort needed for learning the language (assembler - high, scripts
medium)
- an example program in the language from the field it is used for
..
 
 
10
 
Subject  contents III
 
 
 
 
11
 
 
COMPUTER as a MULTILEVEL MACHINE
 
 
12
 
S
Q
L
 
T
r
a
n
s
l
a
t
o
r
 
Make up a language for specific area or task of your choice. An example and a
possible choice is a language for managing library.
Create a SQL translator using GNU Bison (or any alternative) to translate your
made up language to SQL.
Write a simple database interface  for executing the translated SQL queries in a
database.
Set up a simple database to demostrate inserting and quering data in the made
up language
 
TRANSLATION VS. INTERPRETATION I
 
T
r
a
n
s
l
a
t
i
o
n
:
 
p
r
o
g
r
a
m
 
w
r
i
t
t
e
n
 
f
o
r
 
l
e
v
e
l
 
n
m
a
c
h
i
n
e
 
t
r
a
n
s
l
a
t
e
d
 
t
o
 
l
e
v
e
l
 
1
 
m
a
c
h
i
n
e
Advantages: 
  
statements decoded ONCE —
efficient  execution
Disadvantages: 
 
space consumption
I
n
t
e
r
p
r
e
t
a
t
i
o
n
:
 
p
r
o
g
r
a
m
 
w
r
i
t
t
e
n
 
f
o
r
 
l
e
v
e
l
 
n
 
+
 
1
i
s
 
e
x
e
c
u
t
e
d
 
o
n
 
l
e
v
e
l
 
n
 
m
a
c
h
i
n
e
Advantages: 
  
space conservation
Disadvantages: 
 
execution speed
 
 
14
 
TRANSLATION VS. INTERPRETATION II
 
T
R
A
N
S
L
A
T
O
R
S
Compiler: high level-> machine
Assembler: one to one, assembly ->
machine
Loader: relocatable version of machine
code -> machine code
Link editor: combines collections of
relocatable programs -> single relocatable
machine program
Pre-processor: extended language ->
standard language
 
 
15
 
TRANSLATION VS. INTERPRETATION III
 
I
N
T
E
R
P
R
E
T
E
R
Fetch op code
De-code op code
Fetch necessary operands
Branch to primitive (OP
k
)
Then repeat until the end of the program
 
 
16
 
 
 
 
 
17
 
 
LANGUAGES TREE
 
Language parts
 
I part
Alphabet   = latin characters + arabic numeral
+ special symbols(inc. punctuation marks)
II part
Lexic/vocabulary
III part
Syntax rules/Spelling
IV part
Semantics rules
 
Programmeerimine II
 
18
 
The representation of a grammar
 
The representation of a grammar is made of a
set of syntax diagrams.
Each diagram defines a non-terminal. There is a
main diagram which defines the language in the
following way:
 to belong to the language, a word must
describe a path in the main diagram.
Each diagram has an entry point and an end
point.
The diagram describes possible paths between
these two points by going through other
nonterminals and terminals.
Terminals are represented by round boxes while
nonterminals are represented by square boxes
 
 
19
 
Diagram
 
 
20
 
Meta language
 
<expression> ::= <term> | <term> "+"
<expression>
<term>       ::= <factor> | <term> "*" <factor>
<factor>     ::= <constant> | <variable> | "("
<expression> ")"
<variable>   ::= "x" | "y" | "z"
<constant>   ::= <digit> | <digit> <constant>
<digit>      ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" |
"7" | "8" | "9"
 
 
21
 
S
i
g
n
i
f
i
c
a
n
t
 
L
a
n
g
u
a
g
e
 
F
e
a
t
u
r
e
s
 
I
 
S
i
m
p
l
e
 
t
o
 
l
e
a
r
n
M
a
c
h
i
n
e
 
I
n
d
e
p
e
n
d
e
n
t
M
o
r
e
 
n
a
t
u
r
a
l
 
w
a
y
s
 
t
o
 
e
x
p
r
e
s
s
m
a
t
h
e
m
a
t
i
c
a
l
 
f
u
n
c
t
i
o
n
s
P
r
o
b
l
e
m
 
o
r
i
e
n
t
a
t
e
d
 
l
a
n
g
u
a
g
e
R
e
m
a
i
n
s
 
c
l
o
s
e
 
t
o
 
a
n
d
 
e
x
p
l
o
i
t
s
 
t
h
e
 
a
v
a
i
l
a
b
l
e
h
a
r
d
w
a
r
e
E
f
f
i
c
i
e
n
t
 
e
x
e
c
u
t
i
o
n
A
b
i
l
i
t
y
 
t
o
 
c
o
n
t
r
o
l
 
s
t
o
r
a
g
e
 
a
l
l
o
c
a
t
i
o
n
M
o
r
e
 
f
r
e
e
d
o
m
 
i
n
 
c
o
d
e
 
l
a
y
o
u
t
 
 
22
 
S
i
g
n
i
f
i
c
a
n
t
 
L
a
n
g
u
a
g
e
 
F
e
a
t
u
r
e
s
 
I
I
 
L
o
o
p
s
I
n
p
u
t
 
f
r
o
m
 
t
h
e
 
k
e
y
b
o
a
r
d
M
e
n
u
 
D
r
i
v
e
n
 
A
p
p
l
i
c
a
t
i
o
n
s
S
y
s
t
e
m
 
C
o
m
m
a
n
d
s
S
t
r
u
c
t
u
r
e
d
 
P
r
o
g
r
a
m
m
i
n
g
S
u
b
r
o
u
t
i
n
e
s
B
u
i
l
t
-
I
n
 
F
u
n
c
t
i
o
n
s
U
s
e
r
-
D
e
f
i
n
e
d
 
F
u
n
c
t
i
o
n
s
A
r
r
a
y
s
,
 
s
o
r
t
i
n
g
,
 
a
n
d
 
s
e
a
r
c
h
e
s
 
 
23
 
 
C
r
i
t
e
r
i
a
 
f
o
r
 
L
a
n
g
u
a
g
e
 
D
e
s
i
g
n
 
E
v
a
l
u
a
t
i
o
n
1.
efficiency (translation and execution)
2.
simplicity (readability and writability)
3.
orthogonality
4.
definiteness (syntax and semantics)
5.
reliability
6.
program verification (correctness)
7.
abstraction facilities (data and procedural)
8.
portability
 
 
24
 
S
i
g
n
i
f
i
c
a
n
t
 
L
a
n
g
u
a
g
e
 
F
e
a
t
u
r
e
s
 
I
I
I
 
 
 
 
 
25
 
 
Algorithmic language for describing
Processes Imperative  (most computation
work done in assignment statements)
Block & procedure
Lexical scope
         C               Algol lexical scope
 
W
h
a
t
 
i
s
 
a
n
 
"
A
l
g
o
l
-
l
i
k
e
"
 
l
a
n
g
u
a
g
e
?
 
PSEUDO LANGUAGE I
 
L
A
N
G
U
A
G
E
 
 
A
R
E
 
A
L
L
O
W
E
D
 
 
T
O
 
U
S
E
 
 
T
H
E
F
O
L
L
O
W
I
N
G
 
S
E
N
T
E
N
C
E
S
:
 
x
 
=
 
y
;
a
s
s
i
g
m
e
n
t
x
 
=
 
x
 
 
y
;
b
i
n
a
r
y
x
 
=
 
 
x
;
u
n
a
r
y
 
x
 
=
 
x
 
+
 
1
 
 
 
x
 
=
 
s
u
c
c
(
x
)
x
 
=
 
x
 
-
 
1
 
 
 
 
x
 
=
 
p
r
e
d
(
x
)
 
 
 
 
 
s
i
m
p
l
i
f
i
c
a
t
i
o
n
 
 
26
 
PSEUDO LANGUAGE II
 
G
O
T
O
 
M
 
 
 
 
 
 
 
 
B
R
 
 
M
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
J
M
P
 
M
 
I
F
 
x
y
 
T
H
E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
E
 
2
(
C
)
D
O
 
{
s
e
n
t
e
n
c
e
1
;
 
s
e
n
t
e
n
c
e
2
;
 
.
.
.
.
 
s
e
n
t
e
n
c
e
N
;
}
W
H
I
L
E
 
e
x
p
r
e
s
s
i
o
n
;
 
d
o
 
 
 
 
 
 
 
:
 
s
e
n
t
e
n
c
e
1
;
 
 
 
 
 
 
 
 
 
s
e
n
t
e
n
c
e
2
;
 
 
 
 
 
 
 
 
.
.
.
 
 
 
 
 
 
 
 
s
e
n
t
e
n
c
e
N
;
c
h
e
c
k
 
:
 
c
a
l
c
u
l
a
t
i
o
n
 
o
f
 
e
x
p
r
e
s
s
i
o
n
;
w
h
i
l
e
 
 
:
 
i
f
 
n
o
t
 
e
x
p
r
e
s
s
i
o
n
 
g
o
t
o
 
d
o
;
 
 
 
30
 
 
If-then/else or case design issues
 
 
 
 
31
 
 
·        What type of selector expression?
·        What types of case labels?
·        Can you branch to case labels from outside?
·        Mutually exclusive labels?
·        Exhaustive label case coverage?
 
 Loop design issues
 
What type of values may loop variable
assume?
Complexity of loop expression?
How often is loop variable checked
against final value?
Can loop variable be assignment inside
loop body?
When evaluate stopping expression?
Transfer permitted outside loop?
Scope of loop variable?
 
 
32
 
Excercise 3
 
 
33
 
 
Test  task example
 
 
Write an interpreter for the calculator language
defined below. You may assume that there are
no operator precedence rules if you wish.
expression::= operand [ operator operand].
operand   ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
operator  ::= + | - | * | /
You may use any language you wish to do this.
You will need to turn in a clearly commented
source listing of your program.
 
 
34
Slide Note
Embed
Share

Dive into the realm of algorithmic languages through the analysis of different types, comparison of data types, and designing special-purpose languages. Explore the art of translator design and delve into the practical aspects of building compilers. Enhance your understanding of programming languages with practical tasks, homework, exams, and seminars.

  • Programming languages
  • Compiler design
  • Algorithmic analysis
  • Data types
  • Language comparison

Uploaded on Feb 24, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Analysis of Programming Languages Vladimir Viies vladimir.viies@gmail.com, Lembit J rim gi lembit.jyrimagi@gmail.com Tallinna Tehnika likool 2020

  2. Subject goals A student has to be able: to associate tasks with a suitable algorithmic language; to design a special purpose algorithmic language and create a compiler for it; 3

  3. Subject contents I Classification of algorithmic languages. Universal and specific languages. Comparison of the possibilities of data types, sentences and intramodular data exchange in different languages (FORTRAN , PL/1, PASCAL, Assembler etc.). Assembler. Translators, their components and work principles. Art of translator design. 4

  4. POINTS I(EXAM) practice Tasks homework(inc.seminar) written examination 5

  5. Points II(EXAM & PERMISSION) Practice(T1+T2) max20p Homework (translator) max15p Presentation (languages) max10p Seminar max5p Written examination max50p Permission to examination(30p) min 10pract(max20) + min 20test (max 30) 6

  6. Course structure I module: Practice(translator design) II module: Seminars (Comparison of the possibilities in different languages) III module:Homeworks 7

  7. Course timetable 1. 2. 3. 4. 5. 6. 7. 8. 9. 31.08.2020 07.09.2020 14.09.2020 21.09.2020 28.09.2020 05.10.2020 12.10.2020 19.10.2020 26.10.2020 02.11.2020 09.11.2020 16.11.2020 23.11.2020 30.11.2020 07.12.2020 14.12.2020 Introduction Regular Languages, Regular Expressions, Flex Context Free Grammar, Bison, Postfix/Infix Calculator Practice Task 1 Abstract Syntax Tree, General Purpose Language Evolution of Programming Languages Data types and conversion Test Machine Language, Assembly Language Functional Language Practice Task 2 Practice Task 2 Guest lecturer Guest lecturer Presentation Exam 10. 11. 12. 13. 14. 15. 16. 8

  8. Subject contents II LET'S BUILD A COMPILER! By Jack W. Crenshaw, Ph.D. This file contains all of the installments of Jack Crenshaw's tutorial on compiler construction. The intended audience is those folks who are not computer scientists, but who enjoy computing and have always wanted to know how compilers work. A lot of compiler theory has been left out, but the practical issues are covered. By the time you have completed the series, you should be able to design and build your own working compiler. It will not be the world's best, nor will it put out incredibly tight code. Your product will probably never put Borland or MicroSoft out of business. But it will work, and it will be yours 9

  9. Presentation (analysis question list) (analyze different languages) - field where language is used (general purpose hardware, gpu, vm, web etc), proximity to hardware(What problem is language meant to solve?)... - compiled or interpreted, comparative speed to other languages... - strongly typed vs weakly typed, examples, data type conversion? - single thread vs multithread, handling of parallelism, examples... - memory handling, explicit memory allocation vs implicit, examples... - what sort of problems would you use this language for? - if you could improve on this language what would you add to it or remove from it? - extending the functionality of language, dlls, apis... - is the purpose of the code understandable when looking at code (assembler - no, pascal - somewhat, scripting languages yes)... - effort needed for learning the language (assembler - high, scripts medium) - an example program in the language from the field it is used for.. 10

  10. Subject contents III 11

  11. COMPUTER as a MULTILEVEL MACHINE Each level supported by the level below it: level 5 problem oriented language translated by compiler level 4 assembly language level translated by assembly level 3 operating system partial interpretation by OS level 2 conventional machine language interpreted by micro-program level 1 micro-programming directly executed by hardware level 0 digital logic gates & transistors, 12

  12. SQL Translator Make up a language for specific area or task of your choice. An example and a possible choice is a language for managing library. Create a SQL translator using GNU Bison (or any alternative) to translate your made up language to SQL. Write a simple database interface for executing the translated SQL queries in a database. Set up a simple database to demostrate inserting and quering data in the made up language

  13. TRANSLATION VS. INTERPRETATION I Translation: program written for level n machine translated to level 1 machine Advantages: statements decoded ONCE efficient execution Disadvantages: space consumption Interpretation: program written for level n + 1 is executed on level n machine Advantages: space conservation Disadvantages: execution speed 14

  14. TRANSLATION VS. INTERPRETATION II TRANSLATORS Compiler: high level-> machine Assembler: one to one, assembly -> machine Loader: relocatable version of machine code -> machine code Link editor: combines collections of relocatable programs -> single relocatable machine program Pre-processor: extended language -> standard language 15

  15. TRANSLATION VS. INTERPRETATION III INTERPRETER Fetch op code De-code op code Fetch necessary operands Branch to primitive (OPk) Then repeat until the end of the program 16

  16. LANGUAGES TREE 17

  17. Language parts I part Alphabet = latin characters + arabic numeral + special symbols(inc. punctuation marks) II part Lexic/vocabulary III part Syntax rules/Spelling IV part Semantics rules Programmeerimine II 18

  18. The representation of a grammar The representation of a grammar is made of a set of syntax diagrams. Each diagram defines a non-terminal. There is a main diagram which defines the language in the following way: to belong to the language, a word must describe a path in the main diagram. Each diagram has an entry point and an end point. The diagram describes possible paths between these two points by going through other nonterminals and terminals. Terminals are represented by round boxes while nonterminals are represented by square boxes 19

  19. Diagram 20

  20. Meta language <expression> ::= <term> | <term> "+" <expression> <term> ::= <factor> | <term> "*" <factor> <factor> ::= <constant> | <variable> | "(" <expression> ")" <variable> ::= "x" | "y" | "z" <constant> ::= <digit> | <digit> <constant> <digit> ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" 21

  21. Significant Language Features I Simple to learn Machine Independent More natural ways to express mathematical functions Problem orientated language Remains close to and exploits the available hardware Efficient execution Ability to control storage allocation More freedom in code layout 22

  22. Significant Language Features II Loops Input from the keyboard Menu Driven Applications System Commands Structured Programming Subroutines Built-In Functions User-Defined Functions Arrays, sorting, and searches 23

  23. Significant Language Features III Criteria for Language Design Evaluation 1. efficiency (translation and execution) 2. simplicity (readability and writability) 3. orthogonality 4. definiteness (syntax and semantics) 5. reliability 6. program verification (correctness) 7. abstraction facilities (data and procedural) 8. portability 24

  24. What is an "Algol-like" language? Algorithmic language for describing Processes Imperative (most computation work done in assignment statements) Block & procedure Lexical scope C Algol lexical scope 25

  25. PSEUDO LANGUAGE I LANGUAGE ARE ALLOWED TO USE THE FOLLOWING SENTENCES: assigment binary unary x = y; x = x y; x = x; x = x + 1 x = succ(x) x = x - 1 x = pred(x) simplification 26

  26. PSEUDO LANGUAGE II GOTO M BR M JMP M IF x y THEN GOTO M x,y {A} A- set of integers CMP x,y Bii M ii (NE, EQ, GT, LT, GE, LE) CMPB X,Y X,Y {C} C- set of alphabetical symbols Bcc M cc (NE, EQ, ..........) special functionality 27

  27. PSEUDO LANGUAGE III If you compare the form of the IF statement above with the assembler code that must be produced, you can see that there are certain actions associated with each of the keywords in the statement: IF: First, get the condition and issue the code for it. Then, create a unique label and emit a branch if false. ENDIF: Emit the label. These actions can be shown very concisely if we write the syntax this way: IF <condition> { Condition; L = NewLabel; Emit(Branch False to L); } <block> ENDIF { PostLabel(L) } 28

  28. PSEUDO LANGUAGE IV EXAMPLE 1(Pascal) IF ( condition) THEN sentence1; ELSE sentence2; if then : sentence1; goto endif; else : sentence2; endif : program will continue : if !(condition) then goto else; 29

  29. PSEUDO LANGUAGE V EXAMPLE 2(C) DO {sentence1; sentence2; .... sentenceN;} WHILE expression; do : sentence1; sentence2; ... sentenceN; check : calculation of expression; while : if not expression goto do; 30

  30. If-then/else or case design issues What type of selector expression? What types of case labels? Can you branch to case labels from outside? Mutually exclusive labels? Exhaustive label case coverage? 31

  31. Loop design issues What type of values may loop variable assume? Complexity of loop expression? How often is loop variable checked against final value? Can loop variable be assignment inside loop body? When evaluate stopping expression? Transfer permitted outside loop? Scope of loop variable? 32

  32. Excercise 3 What language(s) was describe with below characteristics : - data types, data objects, and procedure specifications can be encapsulated into a package. This supports the program design of data abstraction. - has very good exception handling capabilities which allow the program to handle its own run- time errors. - it is possible to write a procedure (for example, a sorting procedure) which does not require a data type to be specified. - supports parallel and concurrent execution of tasks. - support for object-oriented programming - more flexible libraries - better control mechanisms for shared data 33

  33. Test task example Write an interpreter for the calculator language defined below. You may assume that there are no operator precedence rules if you wish. expression::= operand [ operator operand]. operand ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 operator ::= + | - | * | / You may use any language you wish to do this. You will need to turn in a clearly commented source listing of your program. 34

More Related Content

giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#giItT1WQy@!-/#