1 16 17 18 package org.apache.commons.jexl.parser; 19 20 import java.util.Stack ; 21 22 class JJTParserState { 23 private final Stack nodes; 24 25 private final Stack marks; 26 27 private int sp; 29 private int mk; 31 private boolean node_created; 32 33 JJTParserState() { 34 nodes = new Stack (); 35 marks = new Stack (); 36 sp = 0; 37 mk = 0; 38 } 39 40 44 boolean nodeCreated() { 45 return node_created; 46 } 47 48 52 void reset() { 53 nodes.removeAllElements(); 54 marks.removeAllElements(); 55 sp = 0; 56 mk = 0; 57 } 58 59 63 Node rootNode() { 64 return (Node) nodes.elementAt(0); 65 } 66 67 68 void pushNode(Node n) { 69 nodes.push(n); 70 ++sp; 71 } 72 73 76 Node popNode() { 77 if (--sp < mk) { 78 mk = ((Integer ) marks.pop()).intValue(); 79 } 80 return (Node) nodes.pop(); 81 } 82 83 84 Node peekNode() { 85 return (Node) nodes.peek(); 86 } 87 88 91 int nodeArity() { 92 return sp - mk; 93 } 94 95 void clearNodeScope(Node n) { 96 while (sp > mk) { 97 popNode(); 98 } 99 mk = ((Integer ) marks.pop()).intValue(); 100 } 101 102 void openNodeScope(Node n) { 103 marks.push(new Integer (mk)); 104 mk = sp; 105 n.jjtOpen(); 106 } 107 108 113 void closeNodeScope(Node n, int num) { 114 mk = ((Integer ) marks.pop()).intValue(); 115 while (num-- > 0) { 116 Node c = popNode(); 117 c.jjtSetParent(n); 118 n.jjtAddChild(c, num); 119 } 120 n.jjtClose(); 121 pushNode(n); 122 node_created = true; 123 } 124 125 132 void closeNodeScope(Node n, boolean condition) { 133 if (condition) { 134 int a = nodeArity(); 135 mk = ((Integer ) marks.pop()).intValue(); 136 while (a-- > 0) { 137 Node c = popNode(); 138 c.jjtSetParent(n); 139 n.jjtAddChild(c, a); 140 } 141 n.jjtClose(); 142 pushNode(n); 143 node_created = true; 144 } else { 145 mk = ((Integer ) marks.pop()).intValue(); 146 node_created = false; 147 } 148 } 149 } 150 | Popular Tags |