KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > build > conflict > ShiftReduceConflict


1 /*
2  * Copyright (C) Chaperon. All rights reserved.
3  * -------------------------------------------------------------------------
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 package net.sourceforge.chaperon.build.conflict;
10
11 import net.sourceforge.chaperon.build.ItemSetCollection;
12 import net.sourceforge.chaperon.model.grammar.Grammar;
13 import net.sourceforge.chaperon.model.symbol.Terminal;
14
15 /**
16  * This class represents a shift/reduce conflict.
17  *
18  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels </a>
19  * @version CVS $Id: ShiftReduceConflict.java,v 1.7 2003/12/09 19:55:52 benedikta Exp $
20  */

21 public class ShiftReduceConflict extends Conflict
22 {
23   private Grammar grammar;
24   private ItemSetCollection itemsets;
25   private int state;
26   private Terminal symbol;
27   private int production;
28
29   /**
30    * Creates a shift/reduce conflict.
31    *
32    * @param grammar Grammar.
33    * @param itemsets Collection of item sets.
34    * @param state The state, in which the conflict occurs.
35    * @param symbol The symbol, which the conflict produce.
36    * @param production Production.
37    */

38   public ShiftReduceConflict(Grammar grammar, ItemSetCollection itemsets, int state,
39                              Terminal symbol, int production)
40   {
41     this.grammar = grammar;
42     this.itemsets = itemsets;
43     this.state = state;
44     this.symbol = symbol;
45     this.production = production;
46   }
47
48   /**
49    * The state, in which the conflict occurs.
50    *
51    * @return Index of state.
52    */

53   public int getState()
54   {
55     return state;
56   }
57
58   /**
59    * The symbol, which the conflict produce.
60    *
61    * @return Symbol.
62    */

63   public Terminal getSymbol()
64   {
65     return symbol;
66   }
67
68   /**
69    * Production.
70    *
71    * @return production.
72    */

73   public int getProduction()
74   {
75     return production;
76   }
77
78   /**
79    * Return a string representation of the conflict.
80    *
81    * @return String representation of the conflict.
82    */

83   public String JavaDoc toString()
84   {
85     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
86
87     buffer.append("Shift/Reduce conflict in state ");
88     buffer.append(String.valueOf(state));
89     buffer.append(" at");
90     buffer.append(System.getProperty("line.separator"));
91     buffer.append(grammar.getProduction(production));
92     buffer.append("[priority=");
93     buffer.append(String.valueOf(grammar.getPriority(grammar.getProduction(production))));
94     buffer.append(" associativity=");
95     buffer.append(String.valueOf(grammar.getAssociativity(grammar.getProduction(production))));
96     buffer.append("]");
97     buffer.append(System.getProperty("line.separator"));
98     buffer.append("and symbol ");
99     buffer.append(symbol);
100     buffer.append("[priority=");
101     buffer.append(String.valueOf(grammar.getPriority(symbol)));
102     buffer.append(" associativity=");
103     buffer.append(String.valueOf(grammar.getAssociativity(symbol)));
104     buffer.append("]");
105
106     return buffer.toString();
107   }
108 }
109
Popular Tags