StackHandler.java

Go to the documentation of this file.
00001 package plp.expressions2.memory;
00002 
00003 import java.util.Map;
00004 import java.util.Stack;
00005 
00006 import plp.expressions2.expression.Id;
00007 
00013 public class StackHandler {
00014         
00015         private StackHandler() {
00016         }
00017         
00018         
00027         public static Object getFromId (Stack stack, Id id) throws IdentificadorNaoDeclaradoException {
00028                 Object result = null;
00029                 Stack auxStack = new Stack();
00030                 while (result == null && !stack.empty()) {
00031                         Map aux = (Map) stack.pop();
00032                         auxStack.push(aux);
00033                         result = aux.get(id);
00034                 }
00035                 while (!auxStack.empty()) {
00036                         stack.push(auxStack.pop());
00037                 }
00038                 if (result == null) {
00039                         throw new IdentificadorNaoDeclaradoException();
00040                 } 
00041                 
00042                 return result;
00043         }
00044 
00045                         
00054         public static void mapIdObject (Stack stack, Id id, Object object) throws IdentificadorJaDeclaradoException {
00055                 Map aux = (Map) stack.peek();
00056         if (aux.put(id, object) != null) {
00057                 throw new IdentificadorJaDeclaradoException();
00058         }
00059         
00060         }
00061 
00062 }

Generated on Tue Sep 12 21:36:02 2006 for PLP by  doxygen 1.4.7