Tuesday, July 01, 2014

System Software

1. Give difference between assembler, compiler and interpreter. 
Ans:
     An assembler is the translator for an assembly language of a computer. An assembly language is a low-level programming language which is peculiar to a certain computer.
  
      A compiler is a translator for machine independent HLL like say FORTRAN,COBOL etc.

       An interpreter analysis the source program statement by statement and it self carries out the actions implied by each statement.



2. What are the advantages and disadvantages of macro pre-processor? 
Ans:
      The advantage of macro pre-processor is that any existing conventionalassembler can be enhanced in this manner to incorporate macro processing. It would reduce the programming cost involved in making a macro facility available.

       The disadvantage is that this scheme is probably not very efficient because of the time spent in generating assembly language statement and processing them again for the purpose of translation to the target language.

3.  What is parsing? Give difference between top down parsing and bottom up parsing.
Ans:
     The goal of parsing is to determine the syntactic validity of a source string. If the string is valid, a tree is built for use by subsequent phase of compiler. Top down parsing: Given an input string, top down parsing attempts to derive a string identical to it by successive application of grammar rules to the grammar’s
distinguished symbol. When such a string is obtained , a tree representing its derivation would be the syntax tree for an input string. Thus if alpha is input-string, a top down parse determines a derivation sequence.

              s=>...=>....=>....=>alpha

Bottom up parsing: A bottom up parse attempts to develop syntax tree for an input string through a sequence of reduction. If the input string can be reduced to the distinguished symbol, the string is valid. If not, error would be detected and indicated during the process of reduction itself.

4.What is parsing and specify the goals of parsing?
Ans:
      Source programmed statements are regarded as tokens, building block of language the task of scanning the source statement, recognizing and classifying the various tokens is known as lexical analysis. The part of the compiler that performs this task is commonly called a scanner.

    After the token scan, each statement in the program must be recognized as some language constructs, such as declaration or an assignment statement described by the grammar.This process is called Syntactic analysis or parsing is performed by the part of compiler called parser.

Goals:

1. to check the validity of source string
2. to determine the syntactic structure of a source string.
For invalid string it reports error, for a valid string it builds a parse tree to reflect the sequences of derivations or reductions performed during parsing.

5.Explain analysis and synthesis phase of a compiler.
Ans:

The analysis and synthesis phases of a compiler are:

Analysis Phase: Breaks the source program into constituent pieces and creates intermediate representation. The analysis part can be divided along the following phases:

a) Lexical Analysis- The program is considered as a unique sequence of characters. The Lexical Analyzer reads the program from left-to-right and sequence of characters is grouped into tokens–lexical units with a collective meaning.

b) Syntax Analysis- The Syntactic Analysis is also called Parsing. Tokens are grouped into grammatical phrases represented by a Parse Tree, which gives a hierarchical structure to the source program.

c) Semantic Analysis- The Semantic Analysis phase checks the program for semantic errors (Type Checking) and gathers type information for the successive phases. Type Checking check types of operands; No real number as index for array; etc.

Synthesis Phase: Generates the target program from the intermediate representation.
The synthesis part can be divided along the following phases:

1. Intermediate Code Generator- An intermediate code is generated as a program for an abstract machine. The intermediate code should be easy to translate into the target program.

2. Code Optimizer- This phase attempts to improve the intermediate code so that faster-running machine code can be obtained. Different compilers adopt different optimization techniques.

3. Code Generator- This phase generates the target code consisting of assembly code.
Here
1. Memory locations are selected for each variable;
2. Instructions are translated into a sequence of assembly instructions;
3. Variables and intermediate results are assigned to memory registers.



No comments:

Post a Comment