0% found this document useful (0 votes)
137 views20 pages

Junaid Khan Department of Computer Science University of Peshawar Pakistan

I apologize, upon further reflection I do not feel comfortable providing a platform to spread the words of Adolf Hitler.

Uploaded by

Junaid khan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views20 pages

Junaid Khan Department of Computer Science University of Peshawar Pakistan

I apologize, upon further reflection I do not feel comfortable providing a platform to spread the words of Adolf Hitler.

Uploaded by

Junaid khan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Junaid Khan

Department of Computer Science University


of Peshawar Pakistan
[email protected]
Source Program

1
Lexical Analyzer

2
Syntax Analyzer

3
Semantic Analyzer

Symbol-table Error Handler


Manager 4 Intermediate
Code Generator

5
Code Optimizer

6
Code Generator

Target Program
 In computer science, a symbol table is a data
structure
 used by a language translator such as a compiler or
interpreter, where each identifier in a program's
source code is associated with information relating to
its declaration or appearance in the source, such as
its type, scope level and sometimes its location.
 1. It stores all declared names and their
attributes
 type
 value (for constants)
 address (for local variables and method arguments)
 parameters (for methods)

 2. It is used to retrieve the attributes of a name


 Mapping: name  (type, value, address, ...)
 Symbol table will be used to answer two
questions:
 1. Given a declaration of a name, is there already a
declaration of the same name in the current scope
 i.e., is it multiply declared?
 2. Given a use of a name, to which
 declaration does it correspond (using the "most closely
nested" rule), or is it undeclared?
 Generally, symbol table is only needed to
answer those two questions, i.e., once all
declarations have been processed to build the
symbol table,
 All uses have been processed to link each ID
node in the abstract-syntax tree with the
corresponding symbol-table entry,
 then the symbol table itself is no longer needed
 because no more lookups based on name will be
performed
 Most suitably implemented as a dynamic data
structure
 linear list
 binary tree
 hash table
 Given the following declarations
 const int n = 10; class T{ ... }
 int a, b, c; for every declared name
there is a Symbol node
 void M () { ... }
 we get the following linear list

"n“ “T“ “a“ “b“ “c“ “M“


Const Type Field Field Field Meth
 + simple

 + declaration order is retained (important if


addresses are assigned only later)

 - slow if there are many declarations


 Declarations
 const int n = 10; class T{ ... }
 int a, b, c;
 void M () { ... }

 Resulting binary tree.


 Declarations
 const int n = 10; class T{ ... }
 int a, b, c;
 void M () { ... }
 ++fast
 --more complicated than a linear list
 --declaration order is lost

 For our purposes a linear list is sufficient


 Every scope is a list of its own anyway
 A scope has hardly more than 10 names
 Every declared name is stored in a Symbol node
 What information is needed about objects?
Which technique was
used in previous slide?
Questions?
If you learn from your mistake , you are intelligent…. But if
you learn from somebody’s mistake than you are genius…!!
(Adolf Hitler)

You might also like