I gather the idea is to parse some code, and you end up using a stack while doing that. For something like this, an algorithm might be:
Here, the things being pushed and popped off the stack are simply integers - in
Java using a Stack or other Collection, you're probably using Integer objects. It's also possible you might be pushing and popping some more complex structure, a class containing information representing a syntax structure of some kind. There are many ways to do this depending on how much detail you want or need to get into. I would recommend just using integers initially, until you have a good handle on how this works. Then you can consider modifications to add functionality if necessary.
[ May 24, 2006: Message edited by: Jim Yingst ]