File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes symbol table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "symbol table" Watch "symbol table" New topic
Author

symbol table

Brandi Love
Ranch Hand

Joined: Sep 19, 2003
Posts: 133
Hi all!

I have to write a symbol table for a simple grammar in Java and I'm not sure what data structure would best represent it. I thought about using a vector of vectors but it doesn't seem to be working out the way I want it to. Any suggestions?
Svend Rost
Ranch Hand

Joined: Oct 23, 2002
Posts: 904
Hi Brandi,

I think it's hard to give you concrete advice on your problem, based on the information you provide.

I think the choice datastructure isn't that relevant in your case.. it just have to "hold" the different symbols.

it doesn't seem to be working out the way I want it to

Please be more specific..

/Svend Rost
Sidd Kulk
Ranch Hand

Joined: Feb 20, 2007
Posts: 152
In your case, if there are no synchronization issues, then Vector is not a good choice. Probably the fastest accessible data structures are Arrays, you can use an array of characters. Though, they have their own limitations. In that case, use an ArrayList.

But it would be much more easier to help if you could be more specific.

Njoy!!
Sid
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38426
    
  23
Having tried parsing grammars, I would suggest you don't write the symbol table at all. Find a tool like lex or flex (try the GNU website to download them, or get Fedora Linux on your PC and it includes lex and flex) or JFlex for scanning. I prefer JFlex.
Get a parsing tool, eg yacc, BYacc, bison, BYacc/J, CUP (all the previous tools are LALR) or ANTLR, which is top-down.

If you wish to know about symbol tables, see if you can get your hands on J P Bennett Introduction to Compiling Techniques. A first course using ANSI C lex and yacc Hemel Hempstead: McGraw-Hill 1996, or any of the other standard compiler design books (Aho or Grune are two examples). Bennett uses an array, but collisions in the array are handled by putting the symbols into a linked list.

In my opinion the more modern tools written in OO languages (Java) are more elegant and easier to use than the old tools written in C. Also in Java one doesn't have to know how to write one's own data structures, only how to write "import java.util.*;"
[edit]"Aho" misspelt.[/edit]
[ April 26, 2007: Message edited by: Campbell Ritchie ]
 
jQuery in Action, 2nd edition
 
subject: symbol table