Commit b08c1ba4 authored by Sarah Grebing's avatar Sarah Grebing

Some changes to handle ambigous commands

parent 40e5a455
Pipeline #13557 failed with stage
in 2 minutes and 31 seconds
...@@ -41,6 +41,10 @@ import java.util.Map; ...@@ -41,6 +41,10 @@ import java.util.Map;
* @version 1 (27.04.17) * @version 1 (27.04.17)
*/ */
public class TransformAst implements ScriptLanguageVisitor<Object> { public class TransformAst implements ScriptLanguageVisitor<Object> {
/**
* Start Index for positional arguments for command calls
*/
public static final int KEY_START_INDEX_PARAMETER = 2;
private List<ProofScript> scripts = new ArrayList<>(10); private List<ProofScript> scripts = new ArrayList<>(10);
...@@ -380,7 +384,9 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -380,7 +384,9 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
@Override @Override
public Object visitParameters(ScriptLanguageParser.ParametersContext ctx) { public Object visitParameters(ScriptLanguageParser.ParametersContext ctx) {
Parameters params = new Parameters(); Parameters params = new Parameters();
int i = 1;
int i = KEY_START_INDEX_PARAMETER;
for (ScriptLanguageParser.ParameterContext pc : ctx.parameter()) { for (ScriptLanguageParser.ParameterContext pc : ctx.parameter()) {
Expression expr = (Expression) pc.expr.accept(this); Expression expr = (Expression) pc.expr.accept(this);
Variable key = pc.pname != null ? new Variable(pc.pname) : new Variable("#" + (i++)); Variable key = pc.pname != null ? new Variable(pc.pname) : new Variable("#" + (i++));
......
...@@ -51,7 +51,7 @@ public class InterpreterBuilder { ...@@ -51,7 +51,7 @@ public class InterpreterBuilder {
@Getter @Getter
private ScopeLogger logger; private ScopeLogger logger;
@Getter @Getter
private DefaultLookup lookup = new DefaultLookup(psh, pmh, pmr, pmc); private DefaultLookup lookup = new DefaultLookup(psh, pmh, pmc, pmr);
private KeyInterpreter interpreter = new KeyInterpreter(lookup); private KeyInterpreter interpreter = new KeyInterpreter(lookup);
@Getter @Getter
......
...@@ -21,7 +21,7 @@ import java.util.HashMap; ...@@ -21,7 +21,7 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* This class handle the call of key's proof script commands, e.g. select or auto; * This class handles the call of key's proof script commands, e.g. select or auto;
* *
* @author Alexander Weigl * @author Alexander Weigl
* @version 1 (21.05.17) * @version 1 (21.05.17)
...@@ -56,7 +56,6 @@ public class ProofScriptCommandBuilder implements CommandHandler<KeyData> { ...@@ -56,7 +56,6 @@ public class ProofScriptCommandBuilder implements CommandHandler<KeyData> {
KeyData kd = expandedNode.getData(); KeyData kd = expandedNode.getData();
Map<String, String> map = new HashMap<>(); Map<String, String> map = new HashMap<>();
params.asMap().forEach((k, v) -> map.put(k.getIdentifier(), v.getData().toString())); params.asMap().forEach((k, v) -> map.put(k.getIdentifier(), v.getData().toString()));
//System.out.println(map);
try { try {
EngineState estate = new EngineState(kd.getProof()); EngineState estate = new EngineState(kd.getProof());
estate.setGoal(kd.getNode()); estate.setGoal(kd.getNode());
......
script cutTest(){ script cutTest(){
cases{ cut `p`;
case match `==>?X -> ?Y`: //cases{
// case match `==>?X -> ?Y`:
//auto steps=100;
//cut formula=`?X`[];
} //}
//cut #2=`p`; //cut #2=`p`;
//auto steps=100; //auto steps=100;
} }
\ No newline at end of file
...@@ -34,7 +34,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -34,7 +34,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
//TODO later also include information about source line for each state (for debugging purposes and rewind purposes) //TODO later also include information about source line for each state (for debugging purposes and rewind purposes)
private Stack<State<T>> stateStack = new Stack<>(); private Stack<State<T>> stateStack = new Stack<>();
//We now need thet stack of listeners to handle try statements scuh that listnersa re only informed if a try was sucessfull
private Stack<List<Visitor>> entryListenerStack = new Stack<>(); private Stack<List<Visitor>> entryListenerStack = new Stack<>();
private Stack<List<Visitor>> exitListenerStack = new Stack<>(); private Stack<List<Visitor>> exitListenerStack = new Stack<>();
...@@ -517,10 +517,12 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -517,10 +517,12 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
try { try {
functionLookup.callCommand(this, call, params); functionLookup.callCommand(this, call, params);
} catch (RuntimeException e) { } catch (RuntimeException e) {
System.err.println("Call command not applicable");
throw e;
//TODO handling of error state for each visit //TODO handling of error state for each visit
State<T> newErrorState = newState(null, null); //State<T> newErrorState = newState(null, null);
newErrorState.setErrorState(true); //newErrorState.setErrorState(true);
pushState(newErrorState); //pushState(newErrorState);
} }
g.exitScope(); g.exitScope();
exitScope(call); exitScope(call);
......
...@@ -53,18 +53,9 @@ public class DefaultLookup implements CommandLookup { ...@@ -53,18 +53,9 @@ public class DefaultLookup implements CommandLookup {
if (b.handles(callStatement)) { if (b.handles(callStatement)) {
foundHandlers.add(b); foundHandlers.add(b);
found = b; found = b;
/*if (found == null) {
found = b;
} else {
found = b; //CUTCommand
System.out.println(b.getClass());
System.out.println(found.getClass());
if (callStatement.getCommand().equals("cut")) {
System.out.println("Cut Case");
}
//throw new IllegalStateException("Call on line" + callStatement + " is ambigue.");
}*/
} else { } else {
//if a proof macro contains a "-" character, the proof script language does not support this.
// Therefore we have to check for both versions
if (mayBeEscapedMacro) { if (mayBeEscapedMacro) {
String command = callStatement.getCommand(); String command = callStatement.getCommand();
callStatement.setCommand(command.replace("_", "-")); callStatement.setCommand(command.replace("_", "-"));
...@@ -75,13 +66,9 @@ public class DefaultLookup implements CommandLookup { ...@@ -75,13 +66,9 @@ public class DefaultLookup implements CommandLookup {
} }
} }
} }
if (foundHandlers.size() >= 1) return foundHandlers.get(0);
if (foundHandlers.size() == 1) return foundHandlers.get(0);
if (foundHandlers.size() > 1) {
return foundHandlers.get(0);
} else {
throw new NoCallHandlerException(callStatement); throw new NoCallHandlerException(callStatement);
}
} }
@Override @Override
......
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