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