Programming Language Language Evaluation Criteria



Download 181.29 Kb.
Page3/5
Date28.01.2017
Size181.29 Kb.
#10755
1   2   3   4   5

Program Translation

Implementation methods


  1. 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



  1. 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.

  2. Sample primitives: system resource management, input and output operations, a file management system, program editors, etc.

Compiler


  1. 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.

  2. Linking may be necessary to connect the user code to the system programs.

  3. The user and system code together was sometimes called a load module.

Pure Interpreter


  1. 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


    1. On a von Neumann architecture computers, programs resides in memory but are executed in the processor.

    2. Here’s the fetch-decode-execute cycle

repeat forever

fetch the next instruction

decode the instruction

execute the instruction



    1. 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


  1. 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.



  2. 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.

Lexical analysis


  1. 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.

  1. The strings of characters representing the source program are broken up into small chunks, called token.

  2. 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.

  3. 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.

  4. 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.

  5. Typically entries in the symbol table will show

    1. the identifier or keyword;

    2. the kind of item (variable, array, procedure, keyword, etc.);

    3. the type of item (integer, real, char, etc.);

    4. the run-time address of the item, or its value if it is a constant; and

    5. a pointer to accessing information (e.g. for an array, the bounds of the array, or for a procedure, information about each of parameters).

  6. 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.

  7. 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

(?)

(?)

.
















.

















Download 181.29 Kb.

Share with your friends:
1   2   3   4   5




The database is protected by copyright ©ininet.org 2024
send message

    Main page