Commit 3a681055 authored by Sebastian Pretscher's avatar Sebastian Pretscher

Merge branch 'master' of git@github.com:jroith/cup-eclipse.git

parents d79cbbb9 75b17d03
......@@ -4,13 +4,19 @@ import java.util.List;
import de.in.tum.www2.cup.internal.lalr_item;
import de.in.tum.www2.cup.internal.lalr_state;
import de.in.tum.www2.cup.internal.terminal;
public class ReduceReduceConflict extends Conflict
{
private lalr_item conflict1;
private lalr_item conflict2;
private List<terminal> terminals;
public List<terminal> getTerminals() {
return terminals;
}
public lalr_item getConflictItem1() {
return conflict1;
}
......@@ -19,20 +25,12 @@ public class ReduceReduceConflict extends Conflict
return conflict2;
}
public ReduceReduceConflict(lalr_state state, lalr_item conflict1, lalr_item conflict2) {
public ReduceReduceConflict(lalr_state state, lalr_item conflict1, lalr_item conflict2, List<terminal> terminals) {
super(state);
this.conflict1 = conflict1;
this.conflict2 = conflict2;
this.terminals = terminals;
}
// state (index)
// conflict between:
// item1 ( toString ; has corresponding the_production -> link to Production if in AST)
// item2 ( toString ; has corresponding the_production -> link to Production if in AST)
// symbols (lookahead)
// resolved in favour of item1 / item2 (the_production respectively)
// resolved in favor of item1 / item2 (the_production respectively)
}
......@@ -4,13 +4,18 @@ import java.util.List;
import de.in.tum.www2.cup.internal.lalr_item;
import de.in.tum.www2.cup.internal.lalr_state;
import de.in.tum.www2.cup.internal.terminal;
public class ShiftReduceConflict extends Conflict
{
private lalr_item conflict1;
private List<lalr_item> conflict2;
private terminal terminal;
public terminal getTerminal() {
return terminal;
}
public lalr_item getConflictItem1() {
return conflict1;
}
......@@ -19,21 +24,14 @@ public class ShiftReduceConflict extends Conflict
return conflict2;
}
public ShiftReduceConflict(lalr_state state, lalr_item conflict1, List<lalr_item> conflict2) {
public ShiftReduceConflict(lalr_state state, lalr_item conflict1, List<lalr_item> conflict2, terminal terminal) {
super(state);
this.conflict1 = conflict1;
this.conflict2 = conflict2;
this.terminal = terminal;
}
// state (index)
// conflict between:
// item which could be reduced ; toSimpleString has corresponding the_production -> link to Production if in AST)
// item(s) which could be shifted (have corresponding the_production -> link to Production if in AST)
// symbol
// resolved in favour of shifting
// resolved in favor of shifting
}
\ No newline at end of file
......@@ -822,6 +822,8 @@ public class lalr_state {
{
boolean comma_flag = false;
List<terminal> symbols = new ArrayList<terminal>();
String message = "*** Reduce/Reduce conflict found in state #"+index()+"\n" +
" between " + itm1.to_simple_string() + "\n" +
" and " + itm2.to_simple_string() + "\n" +
......@@ -832,7 +834,9 @@ public class lalr_state {
if (itm1.lookahead().contains(t) && itm2.lookahead().contains(t))
{
if (comma_flag) message+=(", "); else comma_flag = true;
message += (shared.find(t).name());
terminal sym = shared.find(t);
message += (sym.name());
symbols.add(sym);
}
}
message += "}\n Resolved in favor of ";
......@@ -843,7 +847,7 @@ public class lalr_state {
// TODO: add symbols!
// TODO: add resolved in favour of.
Conflict conflict = new ReduceReduceConflict(this, itm1, itm2);
Conflict conflict = new ReduceReduceConflict(this, itm1, itm2, symbols);
ConflictManager cm = context.getConflictManager();
cm.addConflict(conflict);
......@@ -896,7 +900,7 @@ public class lalr_state {
message += " under symbol "+ shared.find(conflict_sym).name() + "\n"+
" Resolved in favor of shifting.\n";
Conflict conflict = new ShiftReduceConflict(this, red_itm, conflictingItems);
Conflict conflict = new ShiftReduceConflict(this, red_itm, conflictingItems, shared.find(conflict_sym));
ConflictManager cm = context.getConflictManager();
cm.addConflict(conflict);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment