/src/main/java/com/bog/model/ast/JJTBrainfuckState.java

https://gitlab.com/bog/qbic · Java · 123 lines · 81 code · 18 blank · 24 comment · 6 complexity · 0967df784117c819d6e5a63e14a75fb5 MD5 · raw file

  1. /* Generated By:JavaCC: Do not edit this line. JJTBrainfuckState.java Version 5.0 */
  2. package com.bog.model.ast;
  3. public class JJTBrainfuckState {
  4. private java.util.List<Node> nodes;
  5. private java.util.List<Integer> marks;
  6. private int sp; // number of nodes on stack
  7. private int mk; // current mark
  8. private boolean node_created;
  9. public JJTBrainfuckState() {
  10. nodes = new java.util.ArrayList<Node>();
  11. marks = new java.util.ArrayList<Integer>();
  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. public 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. public void reset() {
  24. nodes.clear();
  25. marks.clear();
  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. public Node rootNode() {
  32. return nodes.get(0);
  33. }
  34. /* Pushes a node on to the stack. */
  35. public void pushNode(Node n) {
  36. nodes.add(n);
  37. ++sp;
  38. }
  39. /* Returns the node on the top of the stack, and remove it from the
  40. stack. */
  41. public Node popNode() {
  42. if (--sp < mk) {
  43. mk = marks.remove(marks.size()-1);
  44. }
  45. return nodes.remove(nodes.size()-1);
  46. }
  47. /* Returns the node currently on the top of the stack. */
  48. public Node peekNode() {
  49. return nodes.get(nodes.size()-1);
  50. }
  51. /* Returns the number of children on the stack in the current node
  52. scope. */
  53. public int nodeArity() {
  54. return sp - mk;
  55. }
  56. public void clearNodeScope(Node n) {
  57. while (sp > mk) {
  58. popNode();
  59. }
  60. mk = marks.remove(marks.size()-1);
  61. }
  62. public void openNodeScope(Node n) {
  63. marks.add(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. public void closeNodeScope(Node n, int num) {
  72. mk = marks.remove(marks.size()-1);
  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 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. public void closeNodeScope(Node n, boolean condition) {
  88. if (condition) {
  89. int a = nodeArity();
  90. mk = marks.remove(marks.size()-1);
  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 = marks.remove(marks.size()-1);
  101. node_created = false;
  102. }
  103. }
  104. }
  105. /* JavaCC - OriginalChecksum=eec1f9d76550636b281f932d7b569417 (do not edit this line) */