Last change
on this file since 11194 was
6152,
checked in by bfarka, 14 years ago
|
added ecj and custom statistics to communicate with the okb services #1441
|
File size:
1.7 KB
|
Line | |
---|
1 | package ec.gp.ge;
|
---|
2 | import java.util.*;
|
---|
3 |
|
---|
4 | /*
|
---|
5 | * GrammarRuleNode.java
|
---|
6 | *
|
---|
7 | * Created: Sun Dec 5 11:33:43 EST 2010
|
---|
8 | * By: Houston Mooers and Sean Luke
|
---|
9 | *
|
---|
10 | */
|
---|
11 |
|
---|
12 | /**
|
---|
13 | * A GrammarNode representing a Rule in the GE Grammar. The head of the GrammarRuleNode
|
---|
14 | * is the name of the rule; and the children are the various choices. These are returned
|
---|
15 | * by getChoice(...) and getNumChoices(). The merge(...) method unifies this GrammarRuleNode
|
---|
16 | * with the choices of another node.
|
---|
17 | *
|
---|
18 | */
|
---|
19 |
|
---|
20 | public class GrammarRuleNode extends GrammarNode
|
---|
21 | {
|
---|
22 | public GrammarRuleNode(String head)
|
---|
23 | {
|
---|
24 | super(head);
|
---|
25 | }
|
---|
26 |
|
---|
27 | /** Adds a choice to the children of this node. */
|
---|
28 | public void addChoice(GrammarNode choice)
|
---|
29 | {
|
---|
30 | children.add(choice);
|
---|
31 | }
|
---|
32 |
|
---|
33 | /** Returns the current number of choices to the node. */
|
---|
34 | public int getNumChoices() { return children.size(); }
|
---|
35 |
|
---|
36 | /** Returns a given choice. */
|
---|
37 | public GrammarNode getChoice(int index) { return (GrammarNode)(children.get(index)); }
|
---|
38 |
|
---|
39 | /** Adds to this node all the choices of another node. */
|
---|
40 | public void merge(GrammarRuleNode other)
|
---|
41 | {
|
---|
42 | int n = other.getNumChoices();
|
---|
43 | for(int i = 0 ; i < n; i++)
|
---|
44 | addChoice(other.getChoice(i));
|
---|
45 | }
|
---|
46 |
|
---|
47 | public String toString()
|
---|
48 | {
|
---|
49 | String ret = "" + head + " ::= ";
|
---|
50 | Iterator i = children.iterator();
|
---|
51 | boolean first = true;
|
---|
52 | while(i.hasNext())
|
---|
53 | {
|
---|
54 | ret = ret + (first ? "" : "| ") + ((GrammarNode)(i.next())).getHead();
|
---|
55 | first = false;
|
---|
56 | }
|
---|
57 | return ret;
|
---|
58 | }
|
---|
59 |
|
---|
60 | }
|
---|
61 |
|
---|
Note: See
TracBrowser
for help on using the repository browser.