KickJava   Java API By Example, From Geeks To Geeks.

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


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 reduce/reduce conflict.
17  *
18  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels </a>
19  * @version CVS $Id: ReduceReduceConflict.java,v 1.6 2003/12/09 19:55:52 benedikta Exp $
20  */

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

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

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

66   public Terminal getSymbol()
67   {
68     return symbol;
69   }
70
71   /**
72    * First production.
73    *
74    * @return First production.
75    */

76   public int getFirstProduction()
77   {
78     return firstproduction;
79   }
80
81   /**
82    * Second production.
83    *
84    * @return Second production.
85    */

86   public int getSecondProduction()
87   {
88     return secondproduction;
89   }
90
91   /**
92    * Return a string representation of the conflict.
93    *
94    * @return String representation of the conflict.
95    */

96   public String JavaDoc toString()
97   {
98     StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
99
100     buffer.append("Reduce/Reduce conflict in state ");
101     buffer.append(String.valueOf(state));
102     buffer.append(" between");
103     buffer.append(System.getProperty("line.separator"));
104     buffer.append(grammar.getProduction(firstproduction));
105     buffer.append("[priority=");
106     buffer.append(String.valueOf(grammar.getPriority(grammar.getProduction(firstproduction))));
107     buffer.append("]");
108     buffer.append(System.getProperty("line.separator"));
109     buffer.append("and");
110     buffer.append(System.getProperty("line.separator"));
111     buffer.append(grammar.getProduction(secondproduction));
112     buffer.append("[priority=");
113     buffer.append(String.valueOf(grammar.getPriority(grammar.getProduction(firstproduction))));
114     buffer.append("]");
115     buffer.append(System.getProperty("line.separator"));
116     buffer.append("for symbol ");
117     buffer.append(symbol);
118     buffer.append("[priority=");
119     buffer.append(String.valueOf(grammar.getPriority(symbol)));
120     buffer.append(" associativity=");
121     buffer.append(String.valueOf(grammar.getAssociativity(symbol)));
122     buffer.append("]");
123
124     return buffer.toString();
125   }
126 }
127
Popular Tags