Compiler Design Question List | Solve

What is a DAG for basic blocks? Construct the DAG for the following basic blocks

DAG(Directed acyclic graph):
 A Directed acyclic graph is a graph with no cycles which gives a picture of how the value computed by each statement in a basic block is used in subsequent statement in the block . That is,  a DAG has node for every sub-expression of the expression. An interior node represents n operator & its child represents an operand.

DAG is mainly used to identify the same expression.

Example:  Let us the following expression-
       a + a*(b-c)+(b-c)*d.

DAG for the expression is shown

Here given the basic block-
a := b+c   c : = b+c
b : = a-d   d : = a-d

So, the DAG is -

Describe the main problem in code generation

The main problem in code generation:
  There are three main  problems occur in code generation. They are- 

    Deciding what machine instructions to generate.
    Deciding in what order the computations should be done.
    Deciding which register to use.

What instructions should we generate?

Most machines permit certain computations to be done in a variety of ways.

For Example: The target machine has an "add-one-to-storage" instruction (AOS), then for the three-address statement A : = A+1. We might generate the signal instruction AOS A.
rather than the more obvious sequence-

ADD# 1

In what order should we perform computation?-
Some computation orders require fewer registers to hold intermediate results than others. Picking the best order is a very difficult problem in general.

What register  should we use?
The register assignment problem occurs when the code generation.

What are the types of errors found in different phases of compiler?

The types of errors found in  different phases of compiler-

    The lexical analyzer may be unable to proceed because the next token in the source program is misspelled.
    The syntaxb analyzer may be unable to infer structure for its input because a syntatic error such as a missing parenthesis has occured.
    The intermediate code generation detects an operator whose operands have incompatible types.
    The code optimizer, doing control flow analysis, may detect that certain statements can never be reached.
    The code generator may find a compiler - created control that is too large to fit in a word of the target machine.
    While entering information into the symbol table, the bookkeeping routine may discover an identifier.

What is intermediate code?

Intermediate Code :
After syntax & semantic analysis the compiler generates an explicit intermediate representation of the source program. thsi, intermediate representation as a program for an abstract machine. It has two properties- It should be easy to produce & Easy to translate into the target program.

Why it is necessary in compiler?

Necessary in compiler:
To generate machine/assembly language To create stream of simple instructios after syntax analysis.

Write some advantages & limitations of parses

Some advantages & limitations of parses :
  Pass: When one or more phases are combined into a module then the module is referred as pass. A pass is  read the source program to the output of the previous pas, makes the transformations specified by its phases & writes output into an intermediate file.

Advantages : 

    Reduced memory space.
    Requires less time.

Limitations of parses :- 

    The interface between the lexical & syntactic analyzer can often be limited to a single token.
    It is very hard to perform code generation until the intermediate representation has been completely generated.


Write the necessary/motive of compiler

The necessary/motive of compiler :
  A compiler is a program that reads a program written in one language - the source language & translates it into an equivalent program in another language - the target language.

So, the main motive of compiler that if reports to its user the presence of errors in the source program.

A compiler can also assist in producing reliable program. For Example, a compiler could check that the types of operands are compatible.

Compiler can also acts as index by using symbol table.

Some compiler makes the use of an assembler as an appendage.

Write the advantages of high -level language

The advantages of high -level language :
These are the advantages of high level language-

    Ease of understanding
    Portability &
    Efficiency of use

Ease of understanding : - A high level language program is generally easier to read. Write & prove correct than is an assembly language program.

Naturalness : Much of the understanding of a high - level programming language comes from the ease with which one can express an algorithm in that language.

Portability : - User often be able to run their programs on a variety of machine. Language such as FROTAN or COBOL has relatively is well-defined "standard versions" & programs conforming to the standards should run on any machine.

Efficiency of use : - High level language is very efficient.

From a compiler a designer point of view, what are the source of errors in compiler?

From a compiler a designer point of view, the source of errors in compiler :
There are many sources to occur error. These are the source of errors in compiler-
    At the very onset, the design specifications for the program may be inconsistent or faulty.
    The algorithms are incorrect or inadequate (algorithmic errors).
    The programmer may introduce error in implementing the algorithm - such as logical errors or coding error.
    Key punching or transcription errors can occur when the program is types on to cards or into a file.
    The program may exceed a compiler or machine limit not impiled by the definition of the programming language.
    Compiler can inserts errors as it translates source program into an object program.This error is referred compiler errors.

What are the properties that good error detection & diagnostic should have?

The properties that good error detection & diagnostic should have :
Good error diagnostic can significantly help reduce debugging & maintenance effort. These are the properties of good error detection & diagnostic - 
    The message should pinpoint the errors  of the original source program. Rather than in terms of some internal representation that is totally mysterious to the user.
    The error message should be tasteful & understandable by the user.

What is Assembler?

Assembler :
Assembly code is passed to an assembler for further processing that is, if the source language is assembly language language & the target language is machine language, Then the translator is called assembler.

What is Interpreter?

Interpreter :
Interpreter is kinds of translator that translates & execute each source language statement before translating & executing next one but don't produce an object program. Interpreter are frequently used to execute command language. Since each operator executed in a command language is usually an invocation of a complex routine such as high level language.

Using suitable block diagram shows the different phases of a compiler & briefly describes the phases.

  Using suitable block diagram shows the different phases of a compiler & briefly describes the phases.
Or,Describe the function of the five main component of compiler.

A compiler operates in phases, each of which transform the source program from one representation to another. Generally, these are six types of phases in compiler. These are -

    Lexical Analysis
    Syntax Analysis
    Semantic Analysis
    Intermediate code generation
    Code Optimization
    Code Generation

Lexical Analysis : Linear Analysis  is called lexical analysis or scanning. Linear analysis reads the character in the source program & groups them into tokens in which each token represents a logically cohesive sequence of characters such as identifier. A key words(if, while etc.). A punctuation character or multi-character operator like : =.

Syntax Analysis : Hierarchical analysis is called syntax analysis or parsing. in the syntax analysis, the character or tokens are grouped hierarchically into nested collection with collective meaning.

Semantic Analysis :  The semantic analysis phase checks the source program for semantic errors & gathers type information for the sub-sequent code generation phase. It uses the hierarchical structure determined by the syntax - analysis phase to identify the operators & operands of expression & statements. An important component of semantic analysis is type checking. 

Intermediate Code Generation : After syntax & semantic analysis the compiler generates an explicit intermediate representation of the source program. This, intermediate representation as a program for an abstract machine. It have two properties -

What is Regular Expression?

Regular Expression :
The language accepts by finite automata are easily described by simple expression called regular expression. Regular expression operators are union , concatenation & closure/star.

Properties of regular expression

Properties of regular expression :
Faka Set is a regular expression & denotes the empty set. Epsilon is regular expression & denotes the set {Epsilon} For each a in . a is a regular expression & denotes the set {a}.If r & s are regular expressions denoting the language R & S. respectively, then (r+s). (rs) & (r*) are regular expressions that denotes the sets RUS, RS & R* respectively.

© Copyright & reserved CSE Solve