001: /*
002: * Copyright (C) Chaperon. All rights reserved.
003: * -------------------------------------------------------------------------
004: * This software is published under the terms of the Apache Software License
005: * version 1.1, a copy of which has been included with this distribution in
006: * the LICENSE file.
007: */
008:
009: package net.sourceforge.chaperon.build.conflict;
010:
011: import net.sourceforge.chaperon.build.ItemSetCollection;
012: import net.sourceforge.chaperon.model.grammar.Grammar;
013: import net.sourceforge.chaperon.model.symbol.Terminal;
014:
015: /**
016: * This class represents a reduce/reduce conflict.
017: *
018: * @author <a href="mailto:stephan@apache.org">Stephan Michels </a>
019: * @version CVS $Id: ReduceReduceConflict.java,v 1.6 2003/12/09 19:55:52 benedikta Exp $
020: */
021: public class ReduceReduceConflict extends Conflict {
022: private Grammar grammar;
023: private ItemSetCollection itemsets;
024: private int state;
025: private Terminal symbol;
026: private int firstproduction;
027: private int secondproduction;
028:
029: /**
030: * Creates a reduce/reduce conflict
031: *
032: * @param grammar Grammar
033: * @param collection Collection of item sets.
034: * @param state The state, in which the conflict occurs.
035: * @param symbol The symbol, which the conflict produce.
036: * @param firstproduction First production.
037: * @param secondproduction Second production.
038: */
039: public ReduceReduceConflict(Grammar grammar,
040: ItemSetCollection itemsets, int state, Terminal symbol,
041: int firstproduction, int secondproduction) {
042: this .grammar = grammar;
043: this .itemsets = itemsets;
044: this .state = state;
045: this .symbol = symbol;
046: this .firstproduction = firstproduction;
047: this .secondproduction = secondproduction;
048: }
049:
050: /**
051: * The state, in which the conflict occurs.
052: *
053: * @return Index of state.
054: */
055: public int getState() {
056: return state;
057: }
058:
059: /**
060: * The symbol, which the conflict produce.
061: *
062: * @return Symbol.
063: */
064: public Terminal getSymbol() {
065: return symbol;
066: }
067:
068: /**
069: * First production.
070: *
071: * @return First production.
072: */
073: public int getFirstProduction() {
074: return firstproduction;
075: }
076:
077: /**
078: * Second production.
079: *
080: * @return Second production.
081: */
082: public int getSecondProduction() {
083: return secondproduction;
084: }
085:
086: /**
087: * Return a string representation of the conflict.
088: *
089: * @return String representation of the conflict.
090: */
091: public String toString() {
092: StringBuffer buffer = new StringBuffer();
093:
094: buffer.append("Reduce/Reduce conflict in state ");
095: buffer.append(String.valueOf(state));
096: buffer.append(" between");
097: buffer.append(System.getProperty("line.separator"));
098: buffer.append(grammar.getProduction(firstproduction));
099: buffer.append("[priority=");
100: buffer.append(String.valueOf(grammar.getPriority(grammar
101: .getProduction(firstproduction))));
102: buffer.append("]");
103: buffer.append(System.getProperty("line.separator"));
104: buffer.append("and");
105: buffer.append(System.getProperty("line.separator"));
106: buffer.append(grammar.getProduction(secondproduction));
107: buffer.append("[priority=");
108: buffer.append(String.valueOf(grammar.getPriority(grammar
109: .getProduction(firstproduction))));
110: buffer.append("]");
111: buffer.append(System.getProperty("line.separator"));
112: buffer.append("for symbol ");
113: buffer.append(symbol);
114: buffer.append("[priority=");
115: buffer.append(String.valueOf(grammar.getPriority(symbol)));
116: buffer.append(" associativity=");
117: buffer.append(String.valueOf(grammar.getAssociativity(symbol)));
118: buffer.append("]");
119:
120: return buffer.toString();
121: }
122: }
|