summaryrefslogtreecommitdiff
path: root/src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java')
-rw-r--r--src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java b/src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java
new file mode 100644
index 0000000..763560d
--- /dev/null
+++ b/src/main/java/io/devnulllabs/openjava/syntax/SelectionRule.java
@@ -0,0 +1,61 @@
+/*
+ * SelectionRule.java
+ *
+ * comments here.
+ *
+ * @author Michiaki Tatsubori
+ * @version %VERSION% %DATE%
+ * @see java.lang.Object
+ *
+ * COPYRIGHT 1998 by Michiaki Tatsubori, ALL RIGHTS RESERVED.
+ */
+package io.devnulllabs.openjava.syntax;
+
+import io.devnulllabs.openjava.ptree.ParseTree;
+
+/**
+ * The class <code>SelectionRule</code> represents selective syntax
+ * rule.
+ * <p>
+ * Suppose there're several syntax rules; A, B, C. This class
+ * can represents the syntax ( A | B | C ).
+ * If both A and B are adaptable to token source, A is choosed since
+ * A is specified at lefter part than B's part.
+ *
+ * @author Michiaki Tatsubori
+ * @version 1.0
+ * @since $Id: SelectionRule.java,v 1.2 2003/02/19 02:54:31 tatsubori Exp $
+ * @see java.lang.Object
+ */
+public class SelectionRule extends AbstractSyntaxRule {
+ protected SyntaxRule[] elementRules;
+
+ /**
+ * Allocates a new rule representing a selection of given rules.
+ *
+ * @param elementRules an array of rules
+ */
+ public SelectionRule(SyntaxRule[] elementRules) {
+ this.elementRules = elementRules;
+ }
+
+ public SelectionRule(SyntaxRule e1, SyntaxRule e2) {
+ this(new SyntaxRule[] { e1, e2 });
+ }
+
+ public SelectionRule(SyntaxRule e1, SyntaxRule e2, SyntaxRule e3) {
+ this(new SyntaxRule[] { e1, e2, e3 });
+ }
+
+ public ParseTree consume(TokenSource token_src) throws SyntaxException {
+ for (int i = 0; i < elementRules.length; ++i) {
+ if (elementRules[i].lookahead(token_src)) {
+ ParseTree result = elementRules[i].consume(token_src);
+ return result;
+ }
+ }
+ /***** to become specifed error report */
+ throw new SyntaxException("neither of selection");
+ }
+
+}