1. /*
  2. * @(#)JJTParserState.java 4.11 04/07/26
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /* Generated By:JJTree: Do not edit this line. JJTParserState.java */
  8. package com.sun.jmx.snmp.IPAcl;
  9. class JJTParserState {
  10. private java.util.Stack nodes;
  11. private java.util.Stack marks;
  12. private int sp; // number of nodes on stack
  13. private int mk; // current mark
  14. private boolean node_created;
  15. JJTParserState() {
  16. nodes = new java.util.Stack();
  17. marks = new java.util.Stack();
  18. sp = 0;
  19. mk = 0;
  20. }
  21. /* Determines whether the current node was actually closed and
  22. pushed. This should only be called in the final user action of a
  23. node scope. */
  24. boolean nodeCreated() {
  25. return node_created;
  26. }
  27. /* Call this to reinitialize the node stack. It is called
  28. automatically by the parser's ReInit() method. */
  29. void reset() {
  30. nodes.removeAllElements();
  31. marks.removeAllElements();
  32. sp = 0;
  33. mk = 0;
  34. }
  35. /* Returns the root node of the AST. It only makes sense to call
  36. this after a successful parse. */
  37. Node rootNode() {
  38. return (Node)nodes.elementAt(0);
  39. }
  40. /* Pushes a node on to the stack. */
  41. void pushNode(Node n) {
  42. nodes.push(n);
  43. ++sp;
  44. }
  45. /* Returns the node on the top of the stack, and remove it from the
  46. stack. */
  47. Node popNode() {
  48. if (--sp < mk) {
  49. mk = ((Integer)marks.pop()).intValue();
  50. }
  51. return (Node)nodes.pop();
  52. }
  53. /* Returns the node currently on the top of the stack. */
  54. Node peekNode() {
  55. return (Node)nodes.peek();
  56. }
  57. /* Returns the number of children on the stack in the current node
  58. scope. */
  59. int nodeArity() {
  60. return sp - mk;
  61. }
  62. void clearNodeScope(Node n) {
  63. while (sp > mk) {
  64. popNode();
  65. }
  66. mk = ((Integer)marks.pop()).intValue();
  67. }
  68. void openNodeScope(Node n) {
  69. marks.push(new Integer(mk));
  70. mk = sp;
  71. n.jjtOpen();
  72. }
  73. /* A definite node is constructed from a specified number of
  74. children. That number of nodes are popped from the stack and
  75. made the children of the definite node. Then the definite node
  76. is pushed on to the stack. */
  77. void closeNodeScope(Node n, int num) {
  78. mk = ((Integer)marks.pop()).intValue();
  79. while (num-- > 0) {
  80. Node c = popNode();
  81. c.jjtSetParent(n);
  82. n.jjtAddChild(c, num);
  83. }
  84. n.jjtClose();
  85. pushNode(n);
  86. node_created = true;
  87. }
  88. /* A conditional node is constructed if its condition is true. All
  89. the nodes that have been pushed since the node was opened are
  90. made children of the the conditional node, which is then pushed
  91. on to the stack. If the condition is false the node is not
  92. constructed and they are left on the stack. */
  93. void closeNodeScope(Node n, boolean condition) {
  94. if (condition) {
  95. int a = nodeArity();
  96. mk = ((Integer)marks.pop()).intValue();
  97. while (a-- > 0) {
  98. Node c = popNode();
  99. c.jjtSetParent(n);
  100. n.jjtAddChild(c, a);
  101. }
  102. n.jjtClose();
  103. pushNode(n);
  104. node_created = true;
  105. } else {
  106. mk = ((Integer)marks.pop()).intValue();
  107. node_created = false;
  108. }
  109. }
  110. }