1 2 3 package com.genimen.djeneric.tools.scriptengine.core; 4 5 class JJTDjScriptParserEngineState 6 { 7 private java.util.Stack nodes; 8 private java.util.Stack marks; 9 10 private int sp; private int mk; private boolean node_created; 13 14 JJTDjScriptParserEngineState() 15 { 16 nodes = new java.util.Stack (); 17 marks = new java.util.Stack (); 18 sp = 0; 19 mk = 0; 20 } 21 22 25 boolean nodeCreated() 26 { 27 return node_created; 28 } 29 30 32 void reset() 33 { 34 nodes.removeAllElements(); 35 marks.removeAllElements(); 36 sp = 0; 37 mk = 0; 38 } 39 40 42 Node rootNode() 43 { 44 return (Node) nodes.elementAt(0); 45 } 46 47 48 void pushNode(Node n) 49 { 50 nodes.push(n); 51 ++sp; 52 } 53 54 56 Node popNode() 57 { 58 if (--sp < mk) 59 { 60 mk = ((Integer ) marks.pop()).intValue(); 61 } 62 return (Node) nodes.pop(); 63 } 64 65 66 Node peekNode() 67 { 68 return (Node) nodes.peek(); 69 } 70 71 73 int nodeArity() 74 { 75 return sp - mk; 76 } 77 78 void clearNodeScope(Node n) 79 { 80 81 closeNodeScope(n, true); 82 83 } 88 89 void openNodeScope(Node n) 90 { 91 marks.push(new Integer (mk)); 92 mk = sp; 93 n.jjtOpen(); 94 } 95 96 100 void closeNodeScope(Node n, int num) 101 { 102 mk = ((Integer ) marks.pop()).intValue(); 103 while (num-- > 0) 104 { 105 Node c = popNode(); 106 c.jjtSetParent(n); 107 n.jjtAddChild(c, num); 108 } 109 n.jjtClose(); 110 pushNode(n); 111 node_created = true; 112 } 113 114 119 void closeNodeScope(Node n, boolean condition) 120 { 121 if (condition) 122 { 123 int a = nodeArity(); 124 mk = ((Integer ) marks.pop()).intValue(); 125 while (a-- > 0) 126 { 127 Node c = popNode(); 128 c.jjtSetParent(n); 129 n.jjtAddChild(c, a); 130 } 131 n.jjtClose(); 132 pushNode(n); 133 node_created = true; 134 } 135 else 136 { 137 mk = ((Integer ) marks.pop()).intValue(); 138 node_created = false; 139 } 140 } 141 } | Popular Tags |