blob: 2f7c6a533f6963273007fe403aa4dd0db113f90c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
/*
* CompositeRule.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.ObjectList;
import io.devnulllabs.openjava.ptree.ParseTree;
/**
* The class <code>CompositeRule</code> represents iterative syntax
* rule.
* <p>
* Suppose there's a syntax rules; A, B, C. This class can represents
* the syntax ( A B C ).
*
* @author Michiaki Tatsubori
* @version 1.0
* @since $Id: CompositeRule.java,v 1.2 2003/02/19 02:54:32 tatsubori Exp $
* @see java.lang.Object
*/
public class CompositeRule extends AbstractSyntaxRule
{
private SyntaxRule[] elementRules;
/**
* Allocates a new rule representing a composition of given rules.
*
* @param elementRules an array of rules
*/
public CompositeRule( SyntaxRule[] elementRules ) {
this.elementRules = elementRules;
}
public CompositeRule( SyntaxRule e1, SyntaxRule e2 ) {
this( new SyntaxRule[] { e1, e2 } );
}
public CompositeRule( SyntaxRule e1, SyntaxRule e2, SyntaxRule e3 ) {
this( new SyntaxRule[] { e1, e2, e3 } );
}
/**
* Consumes token source.
*
* @param token_src token source.
* @return null if this fails to consume a syntax tree represented
* by this object. Otherwise it returns <code>ObjectList</code> object.
*/
public ParseTree consume( TokenSource token_src )
throws SyntaxException
{
ObjectList result = new ObjectList();
for (int i = 0; i < elementRules.length; ++i) {
ParseTree elem = elementRules[i].consume( token_src );
result.add( elem );
}
return result;
}
}
|