O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Carregando em…3
×

Confira estes a seguir

1 de 25 Anúncio
Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (20)

Semelhante a Symbol Table (20)

Anúncio

Mais de Akhil Kaushik (20)

Mais recentes (20)

Anúncio

Symbol Table

  1. 1. Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani Symbol Table
  2. 2. Introduction
  3. 3. Analysis Part • Breaks up the source program into constituent pieces and imposes a grammatical structure on them. • It then uses this structure to create an intermediate representation of the source program. • If the analysis part detects that the source program is either syntactically ill formed, then it must provide informative messages, so the user can take corrective action.
  4. 4. Analysis Part • The analysis part also collects information about the source program and stores it in a data structure called a symbol table. • It is passed along with the intermediate representation to the synthesis part.
  5. 5. Synthesis Part • The synthesis part constructs the desired target program from the intermediate representation and the information in the symbol table.
  6. 6. Role of Symbol Table Vital functions of a compiler – • Record the variable names used in the source program. • Collect information about various attributes of each name.
  7. 7. Role of Symbol Table • These attributes may provide information about:- – the storage allocated for a name, – its type and its scope, – procedure names, – number and types of its arguments, – the method of passing each argument and – the type returned
  8. 8. Symbol Table Definition • Symbol tables are data structures that are used by compilers to hold information about source-program constructs. • A symbol table is a necessary component due to:- – Declaration of identifiers appears once in a program. – Use of identifiers may appear in many places of the program text.
  9. 9. Symbol Table - Names Symbol Table provides following info:- • Which Identifier or name are used? • What information is to be associated with a name? • How do we access this information?
  10. 10. Symbol Table - Names
  11. 11. Symbol Table - Attributes • Each piece of information associated with a name is called an attribute. • Attributes are language dependent.
  12. 12. Symbol Table - Attributes • Identifiers and attributes are entered by the analysis phases when processing a declaration of an identifier. • In block-structured languages with scopes and explicit declarations:- – The parser and/or semantic analyzer enter identifiers and corresponding attributes. – For every symbol, scanner can enter an identifier into a symbol table if it is not already there.
  13. 13. Symbol Table - Entries • Name and each entry in the symbol table is associated with attributes that support the compiler in different phases: – The name (as a string). – Size and Dimension – The data type. – Its scope (global, local, or parameter). – Its offset from the base pointer (for local variables and parameters only).
  14. 14. Symbol Table Capabilities The capabilities of Symbol Table are:- • Checking (determine whether the given information is in the table). • Adding or delete new Information. • Access the information of Name. • Generate intermediate or target code. • Type checking - for verifying expressions & assignments are semantically correct.
  15. 15. Symbol Table Capabilities • Symbol tables typically need to support multiple declarations of the same identifier within a program.
  16. 16. Symbol Table Implementation A symbol table can be implemented in one of the following ways:- • Linear (sorted or unsorted) list • Binary Search Tree • Hash table
  17. 17. Symbol Table Implementation • Required to make n-entries and m-inquiries. Advantages:- • It is easy to implement. • Addition & retrieve information is easy • Minimum space is required Disadvantages:- Higher Access time
  18. 18. Symbol Table Implementation • Use linear Array of records ,one record per name. • Entries of S.T are not uniform. • So to make it uniform, some information is kept outside the table and pointer to this information stored in S.T. • Record (consist known no. of consecutive words of memory, so names stored in record)
  19. 19. Symbol Table Implementation
  20. 20. Symbol Table Implementation • If there is modest upper bound on the length of the name, then the name can be stored in the symbol table record itself. • But If there is no such limit or the limit is already reached then an indirect scheme of storing name is used. • A separate array of characters called a ‘string table’ is used to store the name and a pointer to the name is kept in the symbol table record
  21. 21. Symbol Table Implementation
  22. 22. Symbol Table Implementation • Binary Search Tree: Efficient approach to organize S.T with two fields: left & right. • Algorithm for searching name in B.S.T – P= initially a pointer to root – 1) If Name = Name (P) then Return /* success */ – 2) Else if Name < Name (P) then – P:= left(P) /* visit left child */ – 3) Else Name (P) < Name then – P:= Right (P) /* visit right child */ • Addition: Firstly search, then add if not present.
  23. 23. Symbol Table Implementation Hash Table:- Consists K words [0….k-1] • Pointers into the storage table (linked list) Searching Name in S.T:- • Apply hash function to name • h(Name) -> {0…..k-1 (integer) } Addition new Name:- • Create a record at available space in storage table and link that record to h(Name)th list.
  24. 24. Symbol Table Implementation Why use hashing:- • Commonly used data structure. • Must be organized for quicker search. • keyword or identifier is 'hashed' to produce an array subscript.
  25. 25. Akhil Kaushik akhilkaushik05@gmail.com 9416910303 CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 THANK YOU !!!

×