Commit 75b17d03 authored by Johannes Roith's avatar Johannes Roith

Final commit for today.

parent 10c9f1c5
......@@ -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)
}
......@@ -10,7 +10,7 @@ public class ShiftReduceConflict extends Conflict
{
private lalr_item conflict1;
private List<lalr_item> conflict2;
private terminal terminal; // TODO: change to Terminal. Requires link in terminal class
private terminal terminal;
public terminal getTerminal() {
return terminal;
......@@ -31,15 +31,7 @@ public class ShiftReduceConflict extends Conflict
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);
......
......@@ -32,6 +32,7 @@ import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.ast.ProductionRight;
import de.in.tum.www2.cup.internal.internal_error;
import de.in.tum.www2.cup.internal.lalr_item;
import de.in.tum.www2.cup.internal.terminal;
import de.tum.in.www2.cupplugin.Colors;
import de.tum.in.www2.cupplugin.PluginUtility;
import de.tum.in.www2.cupplugin.controller.Controller.JobsToDo;
......@@ -93,6 +94,8 @@ public class CupConflictsView implements ICupEditorPageVisibility,
TableWrapData td = new TableWrapData();
td.colspan = 1;
detailText.setLayoutData(td);
detailText.setBackground(new Color(Display.getCurrent(),
Colors.lightGray));
detailText.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
......@@ -104,15 +107,64 @@ public class CupConflictsView implements ICupEditorPageVisibility,
}
public void update(Conflict conflict) {
links.clear();
int linkCounter = 0;
stateLabel.setText("State: " + conflict.getState().index());
if (conflict instanceof ReduceReduceConflict) {
ReduceReduceConflict rrc = (ReduceReduceConflict) conflict;
conflictTypeLabel.setText("Reduce-Reduce conflict");
detailText.setText("TODO");
symbolLabel.setText("TODO");
// TODO!
ProductionRight conflict1Ast = rrc.getConflictItem1()
.the_production().getAstNode();
// TODO: clean up the string builder mess ... ; OAOO!
StringBuilder builder = new StringBuilder();
builder.append("between ");
if (conflict1Ast != null) {
builder.append("<a href=\"" + linkCounter++ + "\">");
links.add(conflict1Ast.getRange());
}
try {
builder.append(rrc.getConflictItem1().to_simple_string());
} catch (internal_error e1) {
e1.printStackTrace();
}
if (conflict1Ast != null)
builder.append("</a>");
builder.append(" and ");
ProductionRight conflict2Ast = rrc.getConflictItem2()
.the_production().getAstNode();
if (conflict2Ast != null) {
builder.append("<a href=\"" + linkCounter++ + "\">");
links.add(conflict2Ast.getRange());
}
try {
builder.append(rrc.getConflictItem2().to_simple_string());
} catch (internal_error e1) {
e1.printStackTrace();
}
if (conflict2Ast != null)
builder.append("</a>");
detailText.setText(builder.toString());
StringBuilder symbolsBuilder = new StringBuilder();
symbolsBuilder.append("Under symbols: ");
int size = rrc.getTerminals().size();
for (int i=0; i < size; i++) {
terminal t = rrc.getTerminals().get(i);
symbolsBuilder.append(t.name());
if (i != size-1)
symbolsBuilder.append(", ");
}
symbolLabel.setText(symbolsBuilder.toString());
} else if (conflict instanceof ShiftReduceConflict) {
ShiftReduceConflict src = (ShiftReduceConflict) conflict;
......@@ -123,8 +175,7 @@ public class CupConflictsView implements ICupEditorPageVisibility,
ProductionRight conflict1Ast = src.getConflictItem1()
.the_production().getAstNode();
links.clear();
int linkCounter = 0;
// TODO: clean up the string builder mess ... ; OAOO!
StringBuilder builder = new StringBuilder();
builder.append("between ");
......@@ -162,8 +213,6 @@ public class CupConflictsView implements ICupEditorPageVisibility,
}
detailText.setText(builder.toString());
detailText.setBackground(new Color(Display.getCurrent(),
Colors.lightGray));
} else {
throw new RuntimeException("unexpected conflict type.");
......
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