Solved

Need explanation on Symbol table

Posted on 2007-03-29
5
714 Views
Last Modified: 2012-06-27
Hi experts,

      Can anybody explain me the concept on symbol tables in detail with a small c program example?
I need the explation to address the following questions:
+ Why it is needed ? what is the use of it?

I know  I may be asking a silly question , but I need  an excellet answers from the experts.


Thanks

0
Comment
Question by:expertblr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 51

Accepted Solution

by:
Steve Bink earned 500 total points
ID: 18819280
Symbol tables have no real simple explanation.  

Say you're building a program.  Inside that program, you are assigning variables like 'x' or 'y'.  When you create the variable, the computer sets aside a section of memory for it (in the stack or heap...more terms!  yay!).  The amount of space reserved depends on the variable.  For example, a single character takes up one byte, integers take 4 (or more) bytes, etc.  The amount of space is OS-dependent as well; different systems use different data types.

So now you have variables 'x' and 'y'.  But the computer does not understand x or y...it understands 1's and 0's.  At this point, the computer knows what you're calling it, and it knows where it is holding the value.  It creates a table in memory to match the two - the symbol table.  Now every time you look up 'x', the computer goes to the symbol table and finds the address it gave to that variable, then goes to that address and returns the value you stored.  

Symbol tables are necessary as part of the translation from our language to the computer's.  As mentioned earlier, these are very OS-dependent and can vary widely in format, usage, and purpose.  In a compiler, the symbol table is created as a manifest for all declared variables.  As the compiler executes passes over the code it is compiling, it replaces plain-language variable references with the segment:offset pair for that variable's address.  In PHP, the symbol table is the global scope...just a place to hold variables.

I hope this explains well enough.  I have not dealt directly with symbol tables since assembler in 1984 or something, and I'm sure they have evolved tremendously over the years.
0
 
LVL 14

Expert Comment

by:kenfcamp
ID: 18819296
[I need the explation to address the following questions:
  Why it is needed ?
   what is the use of it?]


Sounds more like a home work assignment to me
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 18819567
That it does, but I didn't need any code so....  :)  Understanding concept is what homework is all about.
0
 
LVL 84

Expert Comment

by:ozo
ID: 18820486
#include <stdio.h>
main(){
  int i=1;
  printf("%d\n",i);
}
the compiler need to know that the first i refers to the same variable as the second i
it also needs to know what printf is.
To keep track of these things, it uses a symbol table
0
 

Author Comment

by:expertblr
ID: 18882553
Thanks routinet.  I appricate  your help  without listening to others for whom it may look as an homework assignment.  Full pioints to you routinet.
0

Featured Post

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question