01: // find better name than getSufixAndLookahead
02:
03: package ro.infoiasi.donald.compiler.parser;
04:
05: import ro.infoiasi.donald.compiler.cfg.*;
06:
07: public class LR1Item {
08: private LR0Item lr0item;
09: private Terminal lookahead;
10:
11: public LR1Item(LR0Item lr0item, Terminal lookahead) {
12: this .lr0item = lr0item;
13: this .lookahead = lookahead;
14: }
15:
16: public boolean equals(Object o) {
17: return (o instanceof LR1Item
18: && lr0item.equals(((LR1Item) o).lr0item) && lookahead == ((LR1Item) o).lookahead);
19: }
20:
21: public int hashCode() {
22: return 17 + lr0item.hashCode() * 37 + lookahead.hashCode();
23: }
24:
25: public LR1Item nextItem() {
26: return new LR1Item(lr0item.nextItem(), lookahead);
27: }
28:
29: public boolean isComplete() {
30: return lr0item.isComplete();
31: }
32:
33: public boolean isNew() {
34: return lr0item.isNew();
35: }
36:
37: public Symbol getNextSymbol() {
38: return lr0item.getNextSymbol();
39: }
40:
41: public Word getSufixAndLookahead() {
42: if (!getNextSymbol().isTerminal()) {
43: Word w = new Word(lr0item.suffix());
44: w.removeFirst();
45: w.addLast(lookahead);
46: return w;
47: } else {
48: throw new UnsupportedOperationException();
49: }
50: }
51:
52: public LR0Item getLR0Item() {
53: return lr0item;
54: }
55:
56: public Production getProduction() {
57: return lr0item.getProduction();
58: }
59:
60: public int getPosition() {
61: return lr0item.getPosition();
62: }
63:
64: public Terminal getLookahead() {
65: return lookahead;
66: }
67:
68: public String toString() {
69: return "(" + lr0item + ", " + lookahead + ")";
70: }
71: }
|