TreeNode.java

  1. /*
  2.  * Copyright 2021 Dominik Kopczynski, Nils Hoffmann.
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  *      http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16. package org.lifstools.jgoslin.parser;

  17. /**
  18.  * A node representing an element in the parse tree.
  19.  *
  20.  * @author Dominik Kopczynski
  21.  * @author Nils Hoffmann
  22.  */
  23. public final class TreeNode {

  24.     long rule_index;
  25.     TreeNode left;
  26.     TreeNode right;
  27.     char terminal;
  28.     boolean fire_event;
  29.     public static final char EOF_SIGN = '\0';
  30.     public static final String ONE_STR = "\0";

  31.     public TreeNode(long _rule, boolean _fire_event) {
  32.         rule_index = _rule;
  33.         left = null;
  34.         right = null;
  35.         terminal = '\0';
  36.         fire_event = _fire_event;
  37.     }

  38.     public String getText() {
  39.         if (terminal == '\0') {
  40.             String left_str = left.getText();
  41.             String right_str = right != null ? right.getText() : "";
  42.             return (!left_str.equals(ONE_STR) ? left_str : "") + (!right_str.equals(ONE_STR) ? right_str : "");
  43.         }
  44.         return String.valueOf(terminal);
  45.     }

  46.     public int getInt() {
  47.         return Integer.valueOf(getText());
  48.     }
  49. }