View Javadoc
1   package io.jawk.frontend;
2   
3   /*-
4    * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
5    * Jawk
6    * ჻჻჻჻჻჻
7    * Copyright (C) 2006 - 2026 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 io.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  	 * Creates an abstract syntax tree node.
38  	 */
39  	protected AstNode() {
40  		// Subclasses carry the state of the node they represent.
41  	}
42  
43  	/**
44  	 * Dump a meaningful text representation of this abstract syntax tree node to
45  	 * the output (print) stream. Either it is called directly by the application
46  	 * program, or it is called by the parent node of this tree node.
47  	 *
48  	 * @param ps The print stream to dump the text representation.
49  	 */
50  	public abstract void dump(PrintStream ps);
51  
52  	/**
53  	 * Apply semantic checks to this node. The default implementation is to simply
54  	 * call semanticAnalysis() on all the children of this abstract syntax tree
55  	 * node. Therefore, this method must be overridden to provide meaningful
56  	 * semantic analysis / checks.
57  	 */
58  	public abstract void semanticAnalysis();
59  
60  	/**
61  	 * Appends tuples to the AwkTuples list for this abstract syntax tree node.
62  	 * Subclasses must implement this method.
63  	 * <p>
64  	 * This is called either by the main program to generate a full list of tuples
65  	 * for the abstract syntax tree, or it is called by other abstract syntax tree
66  	 * nodes in response to their attempt at populating tuples.
67  	 *
68  	 * @param tuples The tuples to populate.
69  	 * @return The number of items left on the operand stack after these tuples
70  	 *         have executed.
71  	 */
72  	public abstract int populateTuples(AwkTuples tuples);
73  }