Sie sind auf Seite 1von 9

1 System ProgrammingUnit-2 Overview of Language Processors

1) Explain following terms :


System software, semantic, semantic gap, application domain, execution domain, specification gap,
execution gap, language processor, language translator, detranslator, preprocessor, language
migrator, interpreter, source language, target language, problem oriented language, procedure
oriented language.

• Semantic:
It represents the rules of the meaning of the domain.

• Semantic gap:
It represents the difference between the semantic of two domains.

• Application domain:
o  
A user does not wish to interact with the computer on terms of machine language
o It is easier to describe the computation by using the terms related to entities and operations in the
 
application domain of the software
o  
The designer expresses the ideas in terms related to application domain of the software.
o .. i.e. designer of airline reservation application would like to think of how the reservation data

would be used by the query, book and cancel operations,
o  
rather than how it should be implemented in the machine language.
o The description of the reservation data and the query, book and cancel operations forms a
specification of the application.

• Execution domain:
o To implement the ideas of designer, their
  description has to be interpreted in terms related to the
execution domain of computer system.
o For e.g. The system software has to implement this specification of application domain in the

execution domain of the computer system.
o The entities in execution domain are cells in memory and registers in the CPU, and the operations are the

instructions of the CPU

Compiled by: Ruhi Viroja


2 System ProgrammingUnit-2 Overview of Language Processors

• Specification gap:
The gap between application and PL domain is called specification and design gap or simply
specification gap. Specification gap is the semantic gap between two specifications of the same
task.
• Execution gap:
The gap between the semantic of programs written in different programming language.

• Language processor:
Language processor is software which bridges a specification or execution gap.
• Language translator:
Language translator bridges an execution gap to the machine language of a computer system.
• Detranslator:
It bridges the same execution gap as language translator, but in the reverse direction.
• Preprocessor:
It is a language processor which bridges an execution gap but is not a language translator.
• Language Migrator:
It bridges the specification gap between two programming languages.
• Interpreter:
An interpreter is a language processor which bridges an execution gap without generating a
machine language program.
• Source language: The program which forms the input to a language processor is a source program.
The language in which the source program is written is known source language.
• Target language: The output of a language processor is known as the target program. The
language, to which the target program belongs to, is called target language.

2) What is specification gap? What is Semantic gap? Who can bridge the specification gap? How?
How can we reduce the semantic gap?

Refer above answer.

3) Explain language processing activity.

There are two categories of language processing :

1) Program generation activity

 Program
 generation activity aims an automatic generation of a program.

Compiled by: Ruhi Viroja


3 System ProgrammingUnit-2 Overview of Language Processors

 Program generator is a software, which accepts the specification of a program in some specification
language and generates a program in the target language, which is typically a procedure oriented
programming
 language.
 Program generator introduces a new domain between the application and programming language
domain
 is called program generator domain.
 Thus, program generation bridges the specification gap.

2) Program execution activity

Two popular models for program execution are translation and interpretation.

(1) Program translation:

 Bridges the execution gap by translating a program written in a programming language, called
source program, into an equivalent program in the machine or assembly language of computer
system,
 called the target program.
If target program is machine program – executed straight away

 If target program is an assembly language program – it would have to be further translated by an


assembler

Characteristics of program translation model:

 A
 program must be translated before it can be executed

Compiled by: Ruhi Viroja


4 System ProgrammingUnit-2 Overview of Language Processors

 A machine language program generated by the translator may be saved in a file so that it can be
loaded
 into computer’s memory and executed whenever desired.
 If source program is modified , must be translated before it can be executed , we call it retranslation
following a modification

(2) Program Interpretation:

 The Interpreter reads the source program and its data and stores it in its memory. It executes
program
 without generating target program.
 Let us understand how it works by considering similarities between interpretation of a program and
execution
 of a machine language program by CPU
 Interpreter is a system program not hardware unit. It maintains Program Counter to hold statement
number
 of source program that is to be interpreted next.
 The statement would be subjected to the interpretation cycle, consists of following steps.

1. Fetch the statement whose no is in PC


2. Analyze the statement and determine what operations are to be performed and what their operands
are. Detect and indicate errors if any
3. Perform the operations. In case of branching and looping statement, the operation may replace the
statement number contained in PC by a new one. For all other statements, incremented to point to
next statement in source program

Characteristics of interpretation:

 The
 source program is retained in the source form itself, i.e. it is not converted to a target form
 A statement is analyzed during its interpretation. Thus , a statement need not be analyzed before it is
interpreted.
 This feature is beneficial if a program is modified between executions, as in the program
development environment.
However, it also makes interpretation of a statement slower than execution of machine language
instructions that a compiler would have generated for the statement.

4) Explain phases and passes of a language processor. (or toy compiler) OR


List various phases of Language Processor.

Language processor pass: A language processor pass is the processing of every statement in a source
program, to perform language processing function.

Compiled by: Ruhi Viroja


5 System ProgrammingUnit-2 Overview of Language Processors

• Pass I: Perform analysis of the source program and note deduced information.
• Pass II: Perform synthesis of target program.

The classic two-pass schematic of language processor is shown in the figure.

• The first pass performs analysis of the source program and reflects its results in the intermediate
representation.

• The second pass reads and analyzes the intermediate representation to perform synthesis of the
target program.

Phases of Language processor (Toy compiler)

Front end :

1. Lexical Analysis (Scanning)


• Lexical analysis identifies the lexical unit in a source statement. Then it classifies the units into
different lexical classes. E.g. id’s, constants, keyword etc...And enters then into different tables.
• The most important table is symbol table which contains information concerning all identifiers used
in the SP.
• The symbol table is built during lexical analysis.
• Lexical analysis builds a descriptor, called a token. We represent token as
where Code can be Id or Op for identifier or operator respectively and no indicates the entry for the
identifier or operator in symbol or operator table.
• Consider following code
i: integer;
a, b: real;
a= b + i;
• The statement a=b+i is represented as a string of token

2. Syntax analysis (parsing)


• Syntax analysis processes the string of token to determine its grammatical structure and builds an
intermediate code that represents the structure.
• The tree structure is used to represent the intermediate code.
• Consider the statement a = b + i can be represented in tree form as

Compiled by: Ruhi Viroja


6 System ProgrammingUnit-2 Overview of Language Processors

3. Semantic Analysis

• Semantic analysis determines the meaning of a statement by applying the semantic rules to the
structure of the statement.
• While processing a declaration statement, it adds information concerning the type, length and
dimensionality of a symbol to the symbol table.
• While processing an imperative statement, it determines the sequence of actions that would have to
be performed for implementing the meaning of the statement and represents them in the
intermediate code.
• Considering the tree structure for the statement a = b + i

o If node is operand, then type of operand is added in the description field of operand.
o While evaluating the expression the type of b is real and i is int so type of i is converted
to real i*.

• The analysis ends when the tree has been completely processed.

Intermediate representation
• IR contains intermediate code and symbol table.
• Symbol table

Compiled by: Ruhi Viroja


7 System ProgrammingUnit-2 Overview of Language Processors

• Intermediate code
1. Convert(id1#1) to real, giving (id#4)
2. Add(id#4) to (id#3), giving (id#5)
3. Store (id#5) in (id#2)

Back End:

Memory allocation
• The memory requirement of an identifier is computed from its type, length and
dimensionality and memory is allocated to it.
• The address of the memory area is entered in the symbol table

Code generation
• The synthesis phase may decide to hold the value of i* and temp in machine registers
and may generate the assembly code
CONV_R AREG, I
ADD_R AREG, B
MOVEM AREG, A

5) Explain symbol tables. Explain linear and non-linear symbol table organization. OR What is
Symbol table? Explain how one can organize Symbol table using Linear Data Structure?

Symbol Tables: An Identifier used in source program called symbol . Names of variables, functions
and procedures are symbols. A Language processor uses the symbol table to maintain information
about attributes of symbols used in a source program

Four kinds of operations are performed on symbol table by language processor:

1. Add a symbol and its attributes : Make a new entry in the symbol table

2. Locate a symbol’s entry : Find a symbol’s entry in the symbol table

3. Delete a symbol’s entry : Remove the symbol’s information from the table

4. Access a symbol’s entry : Access the entry and set, modify or copy its attribute information.

 Add
 and Locate operations take a symbol as a parameter e.g. ADD(s1)

Compiled by: Ruhi Viroja


8 System ProgrammingUnit-2 Overview of Language Processors

 The Add operation indicates an error if an entry already exists for the symbol, Otherwise , it makes a
new
 entry
 The Locate operation returns a pointer to the symbol’s entry in the table if one exists,
Otherwise, it returns a null pointer. E.g. int *p; p = Locate(s1);
 The delete and access operations may either take a symbol or the pointer to a symbol’s entry returned by
the locate operation as parameters. Delete (s1) or Delete (p)

Two kinds of data structures can be used for organizing its entries:
 Linear data structure: Entries in the symbol table occupy adjoining areas of memory. This property
issued to facilitate search.
o Use of linear – single contiguous area of memory that can accommodate all entries. This
requirement forces designer to allocate memory for the largest number of entries the symbol table
may contain. However, it is wasteful because some part of the allocate memory may not be used.

 Nonlinear data structure: Entries in the symbol table do not occupy contiguous areas of memory.
The
 entries are searched and accessed using pointers
o Nonlinear avoids the problem because it allows memory to be allocated in entry- by – entry manner

Symbol table entry formats:


 Each entry in the symbol table comprised of fields that accommodate the attributes of one symbol.
The symbol field stores the symbol.
 The symbol field is key field which forms basis for search in the table.

Compiled by: Ruhi Viroja


9 System ProgrammingUnit-2 Overview of Language Processors

The following entry formats can be used for accommodating the attributes:

1. Fixed length entries


 Each entry in the Symbol Table has fields for all attributes in the Programming language
2. Variable-length entries
 The entry occupied by a symbol has fields only for the attributes specified for symbols of its class

 Here in (a) each entry has 8 attribute fields, When class=label, all attribute fields except the field for
storing
 its statement number are redundant.(useless)
 (b) shows variable length entry format for a symbol that is used as a label. It has only one attribute
field

3. Hybrid entries
 Combines search efficiency of fixed length and memory efficiency of variable length
 Each entry is split into two halves , fixed part and variable part
 Pointer field is added to fixed part , It points to variable part of an entry
 Fixed
 part of all entries are organized into linear data structures
 As it has pointer to a variable part, Variable part does not need to be located through search
 Hence it could be put into a linear or non linear data structure

Compiled by: Ruhi Viroja

Das könnte Ihnen auch gefallen