001/*
002 * Copyright 2021 Dominik Kopczynski, Nils Hoffmann.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.lifstools.jgoslin.parser;
017
018/**
019 * A node representing an element in the parse tree.
020 *
021 * @author Dominik Kopczynski
022 * @author Nils Hoffmann
023 */
024public final class TreeNode {
025
026    long rule_index;
027    TreeNode left;
028    TreeNode right;
029    char terminal;
030    boolean fire_event;
031    public static final char EOF_SIGN = '\0';
032    public static final String ONE_STR = "\0";
033
034    public TreeNode(long _rule, boolean _fire_event) {
035        rule_index = _rule;
036        left = null;
037        right = null;
038        terminal = '\0';
039        fire_event = _fire_event;
040    }
041
042    public String getText() {
043        if (terminal == '\0') {
044            String left_str = left.getText();
045            String right_str = right != null ? right.getText() : "";
046            return (!left_str.equals(ONE_STR) ? left_str : "") + (!right_str.equals(ONE_STR) ? right_str : "");
047        }
048        return String.valueOf(terminal);
049    }
050
051    public int getInt() {
052        return Integer.valueOf(getText());
053    }
054}