Implementation methods -
The software that provides the high-level language interface to a computer can take several different forms compilers, interpreters and impure interpreters.
High-level language program
High-level language
implementation
Operating system
Bare machine
(machine language
interface
Figure 1
The layered interfaces,
or virtual computers,
provided by a typical
computer system
-
The software depends not only on the computer’s machine language, but also on a large collection of programs called the operating system that supplies higher-level primitives than those of the machine language.
-
Sample primitives: system resource management, input and output operations, a file management system, program editors, etc.
Compiler -
It goes through all the stages of translation and generates all the user source program codes into machine codes before the program is being executed.
-
Linking may be necessary to connect the user code to the system programs.
-
The user and system code together was sometimes called a load module.
Pure Interpreter -
It allows easy implementation of many source-level debugging operations, because all run-time error message can refer to the source-level units.
Source Source
program program
Lexical Lexical
analyzer analyzer
Lexical units Lexical units
Syntax Syntax
analyzer analyzer
Parse trees Parse trees
Intermediate Intermediate
code code
generator generator
Intermediate Intermediate
code code
Input
Code Interpreter data
Generator
Machine Computer
code Input data
Computer
Results Results
Figure 2 The compilation Figure 3 Impure interpretation
** von Neumann bottleneck
-
On a von Neumann architecture computers, programs resides in memory but are executed in the processor.
-
Here’s the fetch-decode-execute cycle
repeat forever
fetch the next instruction
decode the instruction
execute the instruction
-
The speed of the connection between a computer’s memory and its processor usually determines the speed of computer, because instructions often can be executed faster than they can be moved to the processor for execution. von Neumann bottleneck
Impure interpretation -
They translate high-level language programs to an intermediate language designed to allow easy interpretation. It is faster than pure interpretation because the source language statements are decoded only once.
-
Source
Program
Interpreter
Computer
Results
Figure 4 Pure interpretation
From fig. 3, there are three stages of compilation including lexical analysis, syntax analysis and code generation.
-
It breaks up the input source codes to the compiler into chunks that are in a form suitable to be analysed by the next stage of the compilation process.
-
The strings of characters representing the source program are broken up into small chunks, called token.
-
It is usual to remove all redundant parts of the source code (such as spaces and comments) during this tokenisation phase. It is also likely in many system that keywords such as END or PROCEDURE will be replaced by a more efficient, shorter token.
-
It is the job of the lexical analyser to check that all the keywords used are valid and to group certain symbols with their neighbours so that they can form larger units to be presented in the next stage of the compilation process.
-
A symbol table for programmer-defined identifiers would be created during lexical analysis and would contain details of attributes such as data types. As part of this standardized format, the tokens may be replaced by pointers to symbol tables.
-
Typically entries in the symbol table will show
-
the identifier or keyword;
-
the kind of item (variable, array, procedure, keyword, etc.);
-
the type of item (integer, real, char, etc.);
-
the run-time address of the item, or its value if it is a constant; and
-
a pointer to accessing information (e.g. for an array, the bounds of the array, or for a procedure, information about each of parameters).
-
Since the lexical analyser spends a great proportion of its time looking up the symbol table, the symbol table must be organised in such a way that entries can be found as quick as possible. Thus, binary search tree may be used.
-
Sample symbol table:
|
item name
|
kind of item
|
type of item
|
run-time address or value
|
pointer
|
1
|
read
|
keyword
|
|
|
|
2
|
pi
|
constant
|
real
|
3.14159
|
|
3
|
radius
|
variable
|
real
|
(?)
|
|
4
|
begin
|
keyword
|
|
|
|
5
|
writeln
|
keyword
|
|
|
|
6
|
no_sides
|
array
|
integer
|
(?)
|
(?)
|
.
|
|
|
|
|
|
.
|
|
|
|
|
|
Share with your friends: |