1 7 8 9 10 package com.sun.jmx.snmp.IPAcl; 11 12 class JJTParserState { 13 private java.util.Stack nodes; 14 private java.util.Stack marks; 15 16 private int sp; private int mk; private boolean node_created; 19 20 JJTParserState() { 21 nodes = new java.util.Stack (); 22 marks = new java.util.Stack (); 23 sp = 0; 24 mk = 0; 25 } 26 27 30 boolean nodeCreated() { 31 return node_created; 32 } 33 34 36 void reset() { 37 nodes.removeAllElements(); 38 marks.removeAllElements(); 39 sp = 0; 40 mk = 0; 41 } 42 43 45 Node rootNode() { 46 return (Node)nodes.elementAt(0); 47 } 48 49 50 void pushNode(Node n) { 51 nodes.push(n); 52 ++sp; 53 } 54 55 57 Node popNode() { 58 if (--sp < mk) { 59 mk = ((Integer )marks.pop()).intValue(); 60 } 61 return (Node)nodes.pop(); 62 } 63 64 65 Node peekNode() { 66 return (Node)nodes.peek(); 67 } 68 69 71 int nodeArity() { 72 return sp - mk; 73 } 74 75 76 void clearNodeScope(Node n) { 77 while (sp > mk) { 78 popNode(); 79 } 80 mk = ((Integer )marks.pop()).intValue(); 81 } 82 83 84 void openNodeScope(Node n) { 85 marks.push(new Integer (mk)); 86 mk = sp; 87 n.jjtOpen(); 88 } 89 90 91 95 void closeNodeScope(Node n, int num) { 96 mk = ((Integer )marks.pop()).intValue(); 97 while (num-- > 0) { 98 Node c = popNode(); 99 c.jjtSetParent(n); 100 n.jjtAddChild(c, num); 101 } 102 n.jjtClose(); 103 pushNode(n); 104 node_created = true; 105 } 106 107 108 113 void closeNodeScope(Node n, boolean condition) { 114 if (condition) { 115 int a = nodeArity(); 116 mk = ((Integer )marks.pop()).intValue(); 117 while (a-- > 0) { 118 Node c = popNode(); 119 c.jjtSetParent(n); 120 n.jjtAddChild(c, a); 121 } 122 n.jjtClose(); 123 pushNode(n); 124 node_created = true; 125 } else { 126 mk = ((Integer )marks.pop()).intValue(); 127 node_created = false; 128 } 129 } 130 } 131 | Popular Tags |