1 2 3 package com.genimen.djeneric.tools.generator.core; 4 5 class JJTDjentelParserEngineState 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 JJTDjentelParserEngineState() 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 while (sp > mk) 81 { 82 popNode(); 83 } 84 mk = ((Integer ) marks.pop()).intValue(); 85 } 86 87 void openNodeScope(Node n) 88 { 89 marks.push(new Integer (mk)); 90 mk = sp; 91 n.jjtOpen(); 92 } 93 94 98 void closeNodeScope(Node n, int num) 99 { 100 mk = ((Integer ) marks.pop()).intValue(); 101 while (num-- > 0) 102 { 103 Node c = popNode(); 104 c.jjtSetParent(n); 105 n.jjtAddChild(c, num); 106 } 107 n.jjtClose(); 108 pushNode(n); 109 node_created = true; 110 } 111 112 117 void closeNodeScope(Node n, boolean condition) 118 { 119 if (condition) 120 { 121 int a = nodeArity(); 122 mk = ((Integer ) marks.pop()).intValue(); 123 while (a-- > 0) 124 { 125 Node c = popNode(); 126 c.jjtSetParent(n); 127 n.jjtAddChild(c, a); 128 } 129 n.jjtClose(); 130 pushNode(n); 131 node_created = true; 132 } 133 else 134 { 135 mk = ((Integer ) marks.pop()).intValue(); 136 node_created = false; 137 } 138 } 139 } | Popular Tags |