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

compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
nadarmispapaulraj
 
Access to non local names
Access to non local namesAccess to non local names
Access to non local names
Varsha Kumar
 

What's hot (20)

Loop optimization
Loop optimizationLoop optimization
Loop optimization
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Compiler design syntax analysis
Compiler design syntax analysisCompiler design syntax analysis
Compiler design syntax analysis
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
 
COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
 
Type Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLikeType Checking(Compiler Design) #ShareThisIfYouLike
Type Checking(Compiler Design) #ShareThisIfYouLike
 
compiler ppt on symbol table
 compiler ppt on symbol table compiler ppt on symbol table
compiler ppt on symbol table
 
Recognition-of-tokens
Recognition-of-tokensRecognition-of-tokens
Recognition-of-tokens
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Access to non local names
Access to non local namesAccess to non local names
Access to non local names
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Chapter 5 Syntax Directed Translation
Chapter 5   Syntax Directed TranslationChapter 5   Syntax Directed Translation
Chapter 5 Syntax Directed Translation
 
Lp 2
Lp 2Lp 2
Lp 2
 
Code optimization
Code optimizationCode optimization
Code optimization
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Searching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data StructureSearching and Sorting Techniques in Data Structure
Searching and Sorting Techniques in Data Structure
 

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
 
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
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
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

Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
MateoGardella
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 

Recently uploaded (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.Gardella_Mateo_IntellectualProperty.pdf.
Gardella_Mateo_IntellectualProperty.pdf.
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
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
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 

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 !!!