With the B.Tech AKTU Quantum Book, you can learn about the complexities of Compiler Design. Access important notes, repeated questions, and valuable insights for mastering this critical area. Unit-4 Symbol Tables
Dudes 🤔.. You want more useful details regarding this subject. Please keep in mind this as well. Important Questions For Compiler Design: *Quantum *B.tech-Syllabus *Circulars *B.tech AKTU RESULT * Btech 3rd Year * Aktu Solved Question Paper
Q1. Discuss symbol table with its capabilities ?
Ans.
- 1. A symbol table is a data structure used by a compiler to keep track of scope, life and binding information about names.
- 2. These information are used in the source program to identify the various program elements, like variables, constants, procedures, and the labels of statements.
- 3. A symbol table must have the following capabilities:
- a. Lookup: To determine whether a given name is in the table.
- b. Insert: To add a new name (a new entry) to the table.
- c. Access: To access the information related with the given name.
- d. Modify: To add new information about a known name.
- e. Delete: To delete a name or group of names from the table.
Q2. How names can be looked up in the symbol table ? Discuss.
Ans.
- 1. The symbol table is searched (looked up) every time a name is encountered in the source text.
- 2. When a new name or new information about an existing name is discovered, the content of the symbol table changes.
- 3. Therefore, a symbol table must have an efficient mechanism for accessing the information held in the table as well as for adding new entries to the symbol table.
- 4. In any case, the symbol table is a useful abstraction to aid the compiler to ascertain and verify the semantics, or meaning of a piece of code.
- 5. It makes the compiler more efficient, since the file does not need to be re-parsed to discover previously processed information.
For example: Consider the following outline of a C function:
The symbol table could be represented by an upwards growing stack as:
i. Initially the symbol table is empty.
ii. After the first three declarations, the symbol table will be
iii. After the second declaration of Level 2.
iv. As the control come out from Level 2.
v. When control will enter into Level 3.
vi After entering into Level 4.
vii. On leaving the control from Level 4.
viii. On leaving the control from Level 3.
ix. On leaving the function entirely, the symbol table will be again empty.
Q3. Discuss how the scope information is represented in a symbol table.
Ans.
- 1. Scope information characterizes the declaration of identifiers and the portions of the program where it is allowed to use each identifier.
- 2. Different languages have different scopes for declarations. For example, in FORTRAN, the scope of a name is a single subroutine, whereas in ALGOL, the scope of a name is the section or procedure in which it is declared.
- 3. Thus, the same identifier may be declared several times as distinct names, with different attributes, and with different intended storage locations.
- 4. The symbol table is thus responsible for keeping different declaration of the same identifier distinet.
- 5. To make distinction among the declarations, a unique number is assigned to each program element that in return may have its own local data.
- 6. Semantic rules associated with productions that can recognize the beginning and ending of a subprogram are used to compute the number of currently active subprograms.
- 7. There are mainly two semantic rules regarding the scope of an identifier:
- a. Each identifier can only be used within its scope.
- b. Two or more identifiers with same name and are of same kind cannot be declared within the same lexical scope.
- 8. The scope declaration of variables, functions, labels and objects within a program is shown below:
Scope of variables in statement blocks:
Scope of formal arguments of functions:
Scope of labels:
Q4. Draw the format of activation record in stack allocation and explain each field in it.
Ans. 1. Activation record is used to manage the information needed by a single execution of a procedure.
2. An activation record is pushed into the stack when a procedure is called and it is popped when the control returns to the caller function.
Format of activation records in stack allocation:
Fields of activation record are:
- 1. Return value: It is used by calling procedure to return a value to calling procedure.
- 2. Actual parameter: It is used by calling procedures to supply parameters to the called procedures.
- 3. Control link: It points to activation record of the caller.
- 4. Access link: It is used to refer to non-local data held in other activation records.
- 5. Saved machine status: It holds the information about status of machine before the procedure is called.
- 6. Local data: It holds the data that is local to the execution of the procedure.
- 7. Temporaries: It stores the value that arises in the evaluation of an expression.
Q5. How to sub-divide a run-time memory into code and data areas ? Explain.
Ans. Sub-division of run-time memory into codes and data areas is shown in Fig.
- 1. Code: It stores the executable target code which is of fixed size and do not change during compilation.
- 2. Static allocation:
- a. The static allocation is for all the data objects at compile time.
- b. The size of the data objects is known at compile time.
- c. The names of these objects are bound to storage at compile time only and such an allocation of data objects is done by static allocation.
- d. In static allocation, the compiler can determine amount of storage required by each data object. Therefore, it becomes easy for a compiler to find the address of these data in the activation record.
- e. At compile time, compiler can fill the addresses at which the target code can find the data on which it operates.
- 3. Heap allocation: There are two methods used for heap management
- a. Garbage collection method :
- i. When all access path to a object are destroyed but data object continue to exist, such type of objects are said to be garbaged.
- ii. The garbage collection is a technique which is used to reuse that object space.
- iii. In garbage collection, all the elements whose garbage collection bit is ‘on’ are garbaged and returned to the free space list.
- b. Reference counter:
- i. Reference counter attempt to reclaim each element of heap storage immediately after it can no longer be accessed.
- ii. Each memory cell on the heap has a reference counter associated with it that contains a count of number of values that point to it.
- iii. The count is incremented each time a new value point to the cell and decremented each time a value ceases to point to it.
- 4. Stack allocation:
- a. Stack allocation is used to store data structure called activation record.
- b. The activation records are pushed and popped as activations begins and ends respectively.
- c. Storage for the locals in each call of the the activation procedure is contained in record for that call. Thus, locals are bound to fresh storage in each activation, because a new activation record is onto the stack when call pushed is made.
- d. These values of locals are deleted when the activation ends.
Q6. Explain in detail the error recovery process in operator precedence parsing method.
Ans. Error recovery in operator precedence parsing:
- 1. There are two points in the parsing process at which an operator precedence parser can discover syntactic error :
- a. If no precedence relation holds between the terminal on top of the stack and the current input.
- b. If a handle has been found, but there is no production with this handle as a right side.
- 2. The error checker does the following errors:
- a. Missing operand
- b. Missing operator
- c. No expression between parentheses
- d. These error diagnostic issued at handling of errors during reduction.
- 3. During handling of shift/reduce errors, the diagnostic’s issues are:
- a. Missing operand
- b. Unbalanced right parenthesis
- c. Missing right parenthesis
- d. Missing operators
Important Question with solutions | AKTU Quantums | Syllabus | Short Questions
Compiler Design Btech Quantum PDF, Syllabus, Important Questions
Label | Link |
---|---|
Subject Syllabus | Syllabus |
Short Questions | Short-question |
Question paper – 2021-22 | 2021-22 |
Compiler Design Quantum PDF | AKTU Quantum PDF:
Quantum Series | Links |
Quantum -2022-23 | 2022-23 |
AKTU Important Links | Btech Syllabus
Link Name | Links |
---|---|
Btech AKTU Circulars | Links |
Btech AKTU Syllabus | Links |
Btech AKTU Student Dashboard | Student Dashboard |
AKTU RESULT (One VIew) | Student Result |