PageRenderTime 42ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-0-pre3/bsh/JJTParserState.java

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