1 package org.metricshub.jawk.frontend;
2
3 /*-
4 * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5 * Jawk
6 * ჻჻჻჻჻჻
7 * Copyright (C) 2006 - 2025 MetricsHub
8 * ჻჻჻჻჻჻
9 * This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Lesser General Public License as
11 * published by the Free Software Foundation, either version 3 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Lesser Public License for more details.
18 *
19 * You should have received a copy of the GNU General Lesser Public
20 * License along with this program. If not, see
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22 * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
23 */
24
25 import java.io.PrintStream;
26 import org.metricshub.jawk.intermediate.AwkTuples;
27
28 /**
29 * A Jawk abstract syntax tree node. This provides an appropriate public
30 * interface to the abstract syntax tree.
31 *
32 * @author Danny Daglas
33 */
34 public abstract class AstNode {
35
36 /**
37 * Dump a meaningful text representation of this abstract syntax tree node to
38 * the output (print) stream. Either it is called directly by the application
39 * program, or it is called by the parent node of this tree node.
40 *
41 * @param ps The print stream to dump the text representation.
42 */
43 public abstract void dump(PrintStream ps);
44
45 /**
46 * Apply semantic checks to this node. The default implementation is to simply
47 * call semanticAnalysis() on all the children of this abstract syntax tree
48 * node. Therefore, this method must be overridden to provide meaningful
49 * semantic analysis / checks.
50 */
51 public abstract void semanticAnalysis();
52
53 /**
54 * Appends tuples to the AwkTuples list for this abstract syntax tree node.
55 * Subclasses must implement this method.
56 * <p>
57 * This is called either by the main program to generate a full list of tuples
58 * for the abstract syntax tree, or it is called by other abstract syntax tree
59 * nodes in response to their attempt at populating tuples.
60 *
61 * @param tuples The tuples to populate.
62 * @return The number of items left on the operand stack after these tuples
63 * have executed.
64 */
65 public abstract int populateTuples(AwkTuples tuples);
66 }