SlideShare a Scribd company logo
1 of 25
Akhil Kaushik
Asstt. Prof., CE Deptt.,
TIT Bhiwani
Symbol Table
Introduction
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.
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.
Synthesis Part
• The synthesis part constructs the desired target
program from the intermediate representation and
the information in the symbol table.
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.
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
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.
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?
Symbol Table - Names
Symbol Table - Attributes
• Each piece of information associated with a name is
called an attribute.
• Attributes are language dependent.
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.
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).
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.
Symbol Table Capabilities
• Symbol tables typically need to support multiple
declarations of the same identifier within a program.
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
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
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)
Symbol Table Implementation
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
Symbol Table Implementation
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.
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.
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.
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
CONTACT ME AT:
Akhil Kaushik
akhilkaushik05@gmail.com
9416910303
THANK YOU !!!

More Related Content

What's hot

Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
Gerwin Ocsena
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
Mir Majid
 
Type checking
Type checkingType checking
Type checking
rawan_z
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
Nikhil Sharma
 

What's hot (20)

Top down and botttom up Parsing
Top down     and botttom up ParsingTop down     and botttom up Parsing
Top down and botttom up Parsing
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Three Address code
Three Address code Three Address code
Three Address code
 
Compiler Design
Compiler DesignCompiler Design
Compiler Design
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Type checking
Type checkingType checking
Type checking
 
Analysis of algorithm
Analysis of algorithmAnalysis of algorithm
Analysis of algorithm
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)Performance analysis(Time & Space Complexity)
Performance analysis(Time & Space Complexity)
 
Parsing
ParsingParsing
Parsing
 
Asymptotic notations
Asymptotic notationsAsymptotic notations
Asymptotic notations
 
Chapter 6 intermediate code generation
Chapter 6   intermediate code generationChapter 6   intermediate code generation
Chapter 6 intermediate code generation
 
COMPILER DESIGN
COMPILER DESIGNCOMPILER DESIGN
COMPILER DESIGN
 
Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2Lecture 11 semantic analysis 2
Lecture 11 semantic analysis 2
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Graph coloring using backtracking
Graph coloring using backtrackingGraph coloring using backtracking
Graph coloring using backtracking
 
Parse Tree
Parse TreeParse Tree
Parse Tree
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 

Similar to Symbol Table

ds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.pptds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.ppt
AlliVinay1
 

Similar to Symbol Table (20)

Symbol Table.pptx
Symbol Table.pptxSymbol Table.pptx
Symbol Table.pptx
 
Data structure
Data structureData structure
Data structure
 
Plc part 2
Plc  part 2Plc  part 2
Plc part 2
 
stack.pptx
stack.pptxstack.pptx
stack.pptx
 
098ca session7 c++
098ca session7 c++098ca session7 c++
098ca session7 c++
 
ds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.pptds 1 Introduction to Data Structures.ppt
ds 1 Introduction to Data Structures.ppt
 
SAP ABAP data dictionary
SAP ABAP data dictionarySAP ABAP data dictionary
SAP ABAP data dictionary
 
1.1 introduction to Data Structures.ppt
1.1 introduction to Data Structures.ppt1.1 introduction to Data Structures.ppt
1.1 introduction to Data Structures.ppt
 
Unit 3 - Transparent tables in the ABAP Dictionary
Unit 3 - Transparent tables in the ABAP DictionaryUnit 3 - Transparent tables in the ABAP Dictionary
Unit 3 - Transparent tables in the ABAP Dictionary
 
Introduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICSIntroduction to R _IMPORTANT FOR DATA ANALYTICS
Introduction to R _IMPORTANT FOR DATA ANALYTICS
 
Data structures
Data structuresData structures
Data structures
 
Lecture 01 Intro to DSA
Lecture 01 Intro to DSALecture 01 Intro to DSA
Lecture 01 Intro to DSA
 
Unit 1.ppt
Unit 1.pptUnit 1.ppt
Unit 1.ppt
 
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
Overview of Language Processor : Fundamentals of LP , Symbol Table , Data Str...
 
Database
DatabaseDatabase
Database
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Data Structure & Algorithm.pptx
Data Structure & Algorithm.pptxData Structure & Algorithm.pptx
Data Structure & Algorithm.pptx
 
Field symbols
Field symbolsField symbols
Field symbols
 
II B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxII B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptx
 
Data Analytics with R and SQL Server
Data Analytics with R and SQL ServerData Analytics with R and SQL Server
Data Analytics with R and SQL Server
 

More from Akhil Kaushik

More from Akhil Kaushik (20)

Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Parsing in Compiler Design
Parsing in Compiler DesignParsing in Compiler Design
Parsing in Compiler Design
 
Context Free Grammar
Context Free GrammarContext Free Grammar
Context Free Grammar
 
Lexical Analyzer Implementation
Lexical Analyzer ImplementationLexical Analyzer Implementation
Lexical Analyzer Implementation
 
NFA & DFA
NFA & DFANFA & DFA
NFA & DFA
 
Lexical Analysis - Compiler Design
Lexical Analysis - Compiler DesignLexical Analysis - Compiler Design
Lexical Analysis - Compiler Design
 
File Handling Python
File Handling PythonFile Handling Python
File Handling Python
 
Regular Expressions
Regular ExpressionsRegular Expressions
Regular Expressions
 
Algorithms & Complexity Calculation
Algorithms & Complexity CalculationAlgorithms & Complexity Calculation
Algorithms & Complexity Calculation
 
Intro to Data Structure & Algorithms
Intro to Data Structure & AlgorithmsIntro to Data Structure & Algorithms
Intro to Data Structure & Algorithms
 
Decision Making & Loops
Decision Making & LoopsDecision Making & Loops
Decision Making & Loops
 
Basic programs in Python
Basic programs in PythonBasic programs in Python
Basic programs in Python
 
Python Data-Types
Python Data-TypesPython Data-Types
Python Data-Types
 
Introduction to Python Programming
Introduction to Python ProgrammingIntroduction to Python Programming
Introduction to Python Programming
 
Compiler Design Basics
Compiler Design BasicsCompiler Design Basics
Compiler Design Basics
 
Bootstrapping in Compiler
Bootstrapping in CompilerBootstrapping in Compiler
Bootstrapping in Compiler
 
Compiler construction tools
Compiler construction toolsCompiler construction tools
Compiler construction tools
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Introduction to Compilers
Introduction to CompilersIntroduction to Compilers
Introduction to Compilers
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

Symbol Table

  • 1. Akhil Kaushik Asstt. Prof., CE Deptt., TIT Bhiwani Symbol Table
  • 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. 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. Synthesis Part • The synthesis part constructs the desired target program from the intermediate representation and the information in the symbol table.
  • 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. 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. 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. 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. Symbol Table - Names
  • 11. Symbol Table - Attributes • Each piece of information associated with a name is called an attribute. • Attributes are language dependent.
  • 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. 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. 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. Symbol Table Capabilities • Symbol tables typically need to support multiple declarations of the same identifier within a program.
  • 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. 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. 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)
  • 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
  • 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. 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. 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. Akhil Kaushik akhilkaushik05@gmail.com 9416910303 CONTACT ME AT: Akhil Kaushik akhilkaushik05@gmail.com 9416910303 THANK YOU !!!