Solved

Need explanation on Symbol table

Posted on 2007-03-29
5
710 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 50

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 50

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
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…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

749 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