This repository was archived by the owner on Nov 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathGrammarRule.java
More file actions
60 lines (52 loc) · 1.48 KB
/
GrammarRule.java
File metadata and controls
60 lines (52 loc) · 1.48 KB
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
import java.util.LinkedList;
/**
* Abstract class for a grammar rule.
* Implementations include both terminal rules (i.e. tokens) and nonterminal rules (i.e. A -> B | C).
*
* @author Logan Blyth, James McCarty, & Robert Rayborn
*
*/
public abstract class GrammarRule
{
/**
* The string associated with the grammar rule.
* For terminals this is the string value itself (i.e. "INT").
* For nonterminals this is the value of the name of the grammar rule.
* i.e. if the grammar rule is A -> B | C then symbol is "A".
*/
protected String symbol;
/**
* Tells whether the grammar rule is terminal.
* @return - true if the grammar rule is terminal, false otherwise
*/
public abstract boolean isTerminal();
/**
* Gets the first set.
* @return a linked list of the first set for the grammar rule.
*/
public abstract LinkedList<TerminalRule> getFirst();
/**
* Gets the follow set.
* @return a linked list of the follow set for the grammar rule.
*/
public abstract LinkedList<TerminalRule> getFollow();
/**
* Gets the string associated with the grammar rule.
* @return - the symbol
*/
public String getSymbol()
{
return symbol;
}
/**
* Returns true if the rules have the same symbol.
* @param other the other GrammarRule
* @return
*/
public boolean equals(GrammarRule other)
{
return ( other.getSymbol().equals(this.getSymbol()) );
}
@Override
public abstract String toString();
}