1 2 package org.ejen.util.arl; 3 4 class JJTArlParserState { 5 private java.util.Stack nodes; 6 private java.util.Stack marks; 7 private int sp; private int mk; private boolean node_created; 10 JJTArlParserState() { 11 nodes = new java.util.Stack (); 12 marks = new java.util.Stack (); 13 sp = 0; 14 mk = 0; 15 } 16 17 20 boolean nodeCreated() { 21 return node_created; 22 } 23 24 26 void reset() { 27 nodes.removeAllElements(); 28 marks.removeAllElements(); 29 sp = 0; 30 mk = 0; 31 } 32 33 35 Node rootNode() { 36 return (Node) nodes.elementAt(0); 37 } 38 39 40 void pushNode(Node n) { 41 nodes.push(n); 42 ++sp; 43 } 44 45 47 Node popNode() { 48 if (--sp < mk) { 49 mk = ((Integer ) marks.pop()).intValue(); 50 } 51 return (Node) nodes.pop(); 52 } 53 54 55 Node peekNode() { 56 return (Node) nodes.peek(); 57 } 58 59 61 int nodeArity() { 62 return sp - mk; 63 } 64 65 void clearNodeScope(Node n) { 66 while (sp > mk) { 67 popNode(); 68 } 69 mk = ((Integer ) marks.pop()).intValue(); 70 } 71 72 void openNodeScope(Node n) { 73 marks.push(new Integer (mk)); 74 mk = sp; 75 n.jjtOpen(); 76 } 77 78 82 void closeNodeScope(Node n, int num) { 83 mk = ((Integer ) marks.pop()).intValue(); 84 while (num-- > 0) { 85 Node c = popNode(); 86 87 c.jjtSetParent(n); 88 n.jjtAddChild(c, num); 89 } 90 n.jjtClose(); 91 pushNode(n); 92 node_created = true; 93 } 94 95 100 void closeNodeScope(Node n, boolean condition) { 101 if (condition) { 102 int a = nodeArity(); 103 104 mk = ((Integer ) marks.pop()).intValue(); 105 while (a-- > 0) { 106 Node c = popNode(); 107 108 c.jjtSetParent(n); 109 n.jjtAddChild(c, a); 110 } 111 n.jjtClose(); 112 pushNode(n); 113 node_created = true; 114 } else { 115 mk = ((Integer ) marks.pop()).intValue(); 116 node_created = false; 117 } 118 } 119 } 120 | Popular Tags |