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 shift/reduce conflict.
017: *
018: * @author <a href="mailto:stephan@apache.org">Stephan Michels </a>
019: * @version CVS $Id: ShiftReduceConflict.java,v 1.7 2003/12/09 19:55:52 benedikta Exp $
020: */
021: public class ShiftReduceConflict extends Conflict {
022: private Grammar grammar;
023: private ItemSetCollection itemsets;
024: private int state;
025: private Terminal symbol;
026: private int production;
027:
028: /**
029: * Creates a shift/reduce conflict.
030: *
031: * @param grammar Grammar.
032: * @param itemsets Collection of item sets.
033: * @param state The state, in which the conflict occurs.
034: * @param symbol The symbol, which the conflict produce.
035: * @param production Production.
036: */
037: public ShiftReduceConflict(Grammar grammar,
038: ItemSetCollection itemsets, int state, Terminal symbol,
039: int production) {
040: this .grammar = grammar;
041: this .itemsets = itemsets;
042: this .state = state;
043: this .symbol = symbol;
044: this .production = production;
045: }
046:
047: /**
048: * The state, in which the conflict occurs.
049: *
050: * @return Index of state.
051: */
052: public int getState() {
053: return state;
054: }
055:
056: /**
057: * The symbol, which the conflict produce.
058: *
059: * @return Symbol.
060: */
061: public Terminal getSymbol() {
062: return symbol;
063: }
064:
065: /**
066: * Production.
067: *
068: * @return production.
069: */
070: public int getProduction() {
071: return production;
072: }
073:
074: /**
075: * Return a string representation of the conflict.
076: *
077: * @return String representation of the conflict.
078: */
079: public String toString() {
080: StringBuffer buffer = new StringBuffer();
081:
082: buffer.append("Shift/Reduce conflict in state ");
083: buffer.append(String.valueOf(state));
084: buffer.append(" at");
085: buffer.append(System.getProperty("line.separator"));
086: buffer.append(grammar.getProduction(production));
087: buffer.append("[priority=");
088: buffer.append(String.valueOf(grammar.getPriority(grammar
089: .getProduction(production))));
090: buffer.append(" associativity=");
091: buffer.append(String.valueOf(grammar.getAssociativity(grammar
092: .getProduction(production))));
093: buffer.append("]");
094: buffer.append(System.getProperty("line.separator"));
095: buffer.append("and symbol ");
096: buffer.append(symbol);
097: buffer.append("[priority=");
098: buffer.append(String.valueOf(grammar.getPriority(symbol)));
099: buffer.append(" associativity=");
100: buffer.append(String.valueOf(grammar.getAssociativity(symbol)));
101: buffer.append("]");
102:
103: return buffer.toString();
104: }
105: }
|