Unit1 cd

649 views

Published on

unit I two marks and answers - compiler design

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
649
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
29
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Unit1 cd

  1. 1. UNIT –1 2 Marks and Answers1. Define Compiler. Compiler is a program which takes one language (Source program) as input and translates itinto an equivalent another language (Target program). Input Output Compiler Source program Target program During this process if some errors are encountered then compiler displays them as errormessages.2. Describe the analysis-synthesis model of compiler. In the analysis part the source program is read and broken down into constituent pieces. Thesyntax and the meaning of the source program is determined and then the intermediate code iscreated. In the synthesis part this intermediate form of the source program is taken and converted intoa equivalent target program. Compiler Source Target program Analysis synthesis program3. Define a symbol table. The task of symbol table is to store identifiers used in the program. It also stores informationabout attributes of each identifier such as its type, its scope, and storage allocated for it. It also stores information about the subroutines used in the program. In this case the attributesmay be name of the subroutine, number of arguments passed to it, its type and the method ofpassing these arguments (call by value or call by reference) and the return type. Basically it is a data structure which stores information about all tokens.
  2. 2. 4. What are the functions of pre-processor? Pre-processor allow users to use macros in the program. Macros are some set of instructions which can be repeatedly used in the program. Macro is a small set of instruction, whenever a macro name is defined. The macro names which are used in the program are expanded by the macro definition. Example for macro definition #define PI 3.14 The PI value wherever used in the program are replaced by 3.14 during compilation by the preprocessor. #include <stdio.h> - this code will include the header file stdio.h before execution.5. What is CFG? Give an example. Context free grammar is a notations used to specify the syntax of programming language andit consists of 1) Terminals 2) Non-terminals 3) Start symbols 4) Productions Example- Expr  expr op expr Expr id Op  + Op  - Terminlas  id, +, - Non-terminals  expr, op Start symbols  expr Productions  4 productions (given)
  3. 3. 6. List out any two compiler construction tools. 1) Scanner generators 2) Parser generators 3) Syntax directed translation engines 4) Data flow engines 5) Automatic code generators7. Mention some of the cousins of the compiler. 1) Compiler 2) Interpreter 3) Assembler 4) Preprocessor 5) Loader & Linker8. Define Pre processor. It is a program which performs some preliminary functions such as macros and file inclusion. Macros are small programs that are executed frequently. The macro names which are used in the program are expanded by the macro definition. Example for macro definition #define PI 3.14 The PI value wherever used in the program are replaced by 3.14 during compilation by the preprocessor. #include <stdio.h> - this code will include the header file stdio.h before execution. Preprocessor Skeleton program source program9. Define Tokens, Lexeme and Attributes. Token - The meaningful collection of characters over the character set of the programminglanguage is called as the token. Lexeme - A lexeme is a sequence of tokens in the source program that is matched by the rulefor a token. Attributes – attributes specify the properties of tokens. The lexical analyzer collectsinformation about tokens and stores them as their attributes.
  4. 4. 10. Define Translator and give example. A translator is one kind of program that takes one form of program that takes one form ofprogram as the input and converts it into another form. The input program is called sourcelanguage and the output program is called target language. Source target Translator language language11. Draw the transition diagram for a*/b*. a a S1 S0 b S2 b12. What is the function of a loader? Loader is a program which performs two functions: loading and link editing. Loading is aprocess in which the relocatable machine code is read and the relocateable addresses are altered.Then that code with altered instructions and data is placed the memory at proper location. Thejob of link editor is to make a single program from several files of relocatable machine code. Ifcode in on file refers the location in another file then such a reference is called externalreference.13. What is regular expression? Give an example. Regular expressions are mathematical symbolisms which describe the set of strings oflanguage. It provides convenient and useful notation for representing tokens.Example- A regular expression (R.E) for a language containing the strings of length two over∑={0,1}. R.E = (0/1) (0/1)
  5. 5. 14. Check whether the input string abab is accepted by the given production. S  aSbS/bSaS/d Productions S  aSbS, S  bSaS, S  d To get the input string abab the derivation maybe S  aSbS S  abSabS S  abaSbS S ababS S  ababThe input string abab is accepted.15. Difference between Pass and Phase. PHASE PASSThe process of compilation is carried out in Various phases are logically grouped togethervarious steps. to form a pass.These steps are referred as phases. The process of compilation can be carried out in single pass or in multiple passes.The phases of compilation are lexical analysis,syntax analysis, intermediate code,Generation, code generation, codeoptimization.16. Write short notes on transition table and transition diagram with suitable example.Transition table- This is a tabular representation of finite automata. For transition table the transitionfunction is used. states A b q0 q1 - q1 - q2 q2 q2 -Transition diagram- A transition diagram or transition graph can be defined as collection of
  6. 6. 1) Finite set of states k 2) Finite set of symbols ∑ 3) A non empty set states S of k. It is called start symbol. 4) A set F≤K of final 5) A transition function K*AK with K as states and A as input from ∑*. Example : The transition diagram for the input abb is a b b S0 S1 S2 S317. Write any 3 difference between compiler and interpreter. INTERPRETER COMPILERDemerit: Merit: The source program gets interpreted In the process of compilation the programevery time it is to be executed, and every time is analyzed only once and then the code isthe source program is analyzed. Hence, generated. Hence compiler is efficient thaninterpretation is less efficient than compiler. interpreter.The interpreter s do not produce object code. The compilers produce object code.Merit: Demerits: The interpreters can be made portal The compiler has to present on the hostbecause they do not produce object code. machine when particular needs to be compiled.Merits: Demerits: Interpreters are simpler and give us The compiler is a complex program andimproved debugging environment. it requires large amount of memory.18. Mention some of the issues of lexical analyzer.The various issues in lexical analysis are 1) The lexical analysis and syntax analysis are separated out for simplifying the task of one or other phases. This separation reduces the burden on parsing phase. 2) Compiler efficiency gets increased if the lexical analyzer is separated. This is because a large amount of time is spent on reading the source file. And it would be inefficient if each phase has to read the source file. Lexical analyzer uses buffering techniques for efficient scan of source file. The tokens obtained can be stored in input buffer to increase performance of compiler.
  7. 7. 3) Input alphabet peculiarities and other device specific anomalies can be restricted to the lexical analyzer can be isolated in lexical analyzer. For example, in pascal, ↑ can be isolated in lexical analyzer.19. What do you meant by sentinel?The ‘eof’’ character, which is introduced at the end of the buffer is called sentinel. It is used toidentify the end of the buffer. Buffer 1 bp i n t i = i + 1 ; J = 1 eof fp buffer 2 sentinal20. Define book keeping. ‘Symbol table’ is also called as Book keeping. All the information about the tokens are in the symbol table. The task of symbol table is to store identifiers used in the program. It also stores informationabout attributes of each identifier such as its type, its scope, and storage allocated for it. It also stores information about the subroutines used in the program. In this case the attributesmay be name of the subroutine, number of arguments passed to it, its type and the method ofpassing these arguments (call by value or call by reference) and the return type.Basically it is a data structure which stores information about all tokens

×