472,960 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,960 software developers and data experts.

Creating a symbol table in c++

13
This is for a class assignment, and I need some help getting my head wrapped around the problem.

The problem is to create a symbol table for a c++ program. I know what a symbol table is, but figuring out how to create one is my difficulty.

The only way I can think to create a symbol table is to have a list of valid keywords which I then use to search through the source code. This would enable me to find the declarations of variables, however, it would require me to:
1) search through the entire file for every keyword

2) To search through any header files for classes which would need to be added to the list of keywords

3)I would have to create a list of all keywords from the header files or I would need to have a list of all keywords in the c++ language. (or just have a keyword list tailored to the program I parse for identifiers)


I have to write a program which creates a symbol table of a c++ program, so I want to make sure i'm approaching this problem in the right way before I create a detailed algorithm.

Any ideas/help or comments are appreciated.
Mar 21 '08 #1
3 12862
weaknessforcats
9,208 Expert Mod 8TB
This is a simple word search problem where you build a tree that has a leaf for each different word in a text file. At the end of the text file the tree contains all of the words used in the file.

Just do the same thing with your C++ program. The only difference is that you will start out with a tree of C++ keywords to determine iof the token read from the program is a symbol. Like == is not a symbol.

There is an article in the HowTos forum about the State Design pattern that uses a parser as the example. There is code there also.

I would start off by ignoring include files. Do that as a second step after you get the program itself parsed.

Be careful not to bite off too much or you will be writing a full-blown C++ parser and you will be there for a very long time, and worse, it's already been done.
Mar 21 '08 #2
rolan
13
Thanks for your guidance. Just one question, which may be laziness speaking, is there somewhere I could find a list of the commonly used keywords for c++? (or at least the standard keywords) Or will I just have to tailor the list of keywords to the program I try to parse?
Apr 1 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Just about any C++ textbook will have this. Probably, you can get the same thing from Google.
Apr 2 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Thomas Korimort | last post by:
Hi, how can i visualize the content of the symbol table in Python? Sometimes i want to know which symbols are imported from apackage and such kind of things Greetings, THomas Korimort
1
by: linq936 | last post by:
Hi, This might be off topic a little. In using gdb to debug my code I can not use "print" command to examine the value, gdb returns me "incomplete type". But "ptype ClassName" does return me a...
1
by: s88 | last post by:
Howdy: I'm searching an avaliable symbol table library for my C-like parser project. Does anyone have good suggestions? Thanx!!! Dave.
4
by: curious | last post by:
It will be great if some one can explain in detail about structure of process in memory...where is symbol table etc..located?
0
by: moumita | last post by:
Hi, I am new to VB.net.I am trying to develop an application.I have to plot a xy axis graph depending on the coordiantes mentioned in a MS Access database table .Secondly the things that I have to...
2
by: ygao | last post by:
when a function or method is called,how can get the module global symbol table from which it is called,not the module where it is defined(this is easy). thanks!
2
by: chandanlinster | last post by:
Hello everybody, I am using gcc 4.1.1. Is there a way to view the contents of the symbol table (while compiling a program and after compilation).
3
by: cgable2003 | last post by:
I copied this code fragment from http://www.gnu.org/software/libc/manual/html_node/Backtraces.html #include <execinfo.h> #include <stdio.h> #include <stdlib.h> /* Obtain a backtrace and print...
1
by: kaushikvishal | last post by:
Give me the code in c++ to create symbol table?
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.