Commit 2b5b35ae authored by Alexander Weigl's avatar Alexander Weigl

Implemented Subst and rework on types

now Term<KeyType> ist possible!
parent 4efda617
...@@ -49,19 +49,19 @@ assignment ...@@ -49,19 +49,19 @@ assignment
expression expression
: :
MINUS expression #exprNegate expression MUL expression #exprMultiplication
| NOT expression #exprNot | <assoc=right> expression DIV expression #exprDivision
| expression '[' substExpressionList ']' #exprSubst | expression op=(PLUS|MINUS) expression #exprLineOperators
| expression MUL expression #exprMultiplication | expression op=(LE|GE|LEQ|GEQ) expression #exprComparison
| <assoc=right> expression DIV expression #exprDivision | expression op=(NEQ|EQ) expression #exprEquality
| expression op=(PLUS|MINUS) expression #exprLineOperators | expression AND expression #exprAnd
| expression op=(LE|GE|LEQ|GEQ) expression #exprComparison | expression OR expression #exprOr
| expression op=(NEQ|EQ) expression #exprEquality | expression IMP expression #exprIMP
| expression AND expression #exprAnd
| expression OR expression #exprOr
| expression IMP expression #exprIMP
//| expression EQUIV expression already covered by EQ/NEQ //| expression EQUIV expression already covered by EQ/NEQ
| '(' expression ')' #exprParen | expression LBRACKET substExpressionList RBRACKET #exprSubst
| MINUS expression #exprNegate
| NOT expression #exprNot
| '(' expression ')' #exprParen
| literals #exprLiterals | literals #exprLiterals
| matchPattern #exprMatch | matchPattern #exprMatch
; ;
...@@ -69,7 +69,9 @@ expression ...@@ -69,7 +69,9 @@ expression
substExpressionList substExpressionList
: :
scriptVar '/' expression (',' substExpressionList)* (scriptVar '/' expression
(',' scriptVar '/' expression)*
)?
; ;
literals : literals :
...@@ -205,4 +207,4 @@ EXE_MARKER: '\u2316' -> channel(HIDDEN); ...@@ -205,4 +207,4 @@ EXE_MARKER: '\u2316' -> channel(HIDDEN);
DIGITS : DIGIT+ ; DIGITS : DIGIT+ ;
fragment DIGIT : [0-9] ; fragment DIGIT : [0-9] ;
ID : [a-zA-Z] ([_a-zA-Z0-9] | '.' | '\\' | '[]' | '-')* ; ID : [a-zA-Z] ([_a-zA-Z0-9] | '.' | '\\')*;
\ No newline at end of file
...@@ -6,11 +6,16 @@ import edu.kit.formal.interpreter.data.VariableAssignment; ...@@ -6,11 +6,16 @@ import edu.kit.formal.interpreter.data.VariableAssignment;
import edu.kit.formal.proofscriptparser.DefaultASTVisitor; import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import edu.kit.formal.proofscriptparser.Visitor; import edu.kit.formal.proofscriptparser.Visitor;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.types.TermType;
import edu.kit.formal.proofscriptparser.types.TypeFacade;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/** /**
* Class handling evaluation of expressions (visitor for expressions) * Class handling evaluation of expressions (visitor for expressions)
...@@ -68,9 +73,9 @@ public class Evaluator<T> extends DefaultASTVisitor<Value> implements ScopeObser ...@@ -68,9 +73,9 @@ public class Evaluator<T> extends DefaultASTVisitor<Value> implements ScopeObser
Value pattern = (Value) match.getPattern().accept(this); Value pattern = (Value) match.getPattern().accept(this);
if (match.isDerivable()) { if (match.isDerivable()) {
} else { } else {
if (pattern.getType() == Type.STRING) { if (pattern.getType() == SimpleType.STRING) {
va = matcher.matchLabel(goal, (String) pattern.getData()); va = matcher.matchLabel(goal, (String) pattern.getData());
} else if (pattern.getType() == Type.TERM) { } else if (TypeFacade.isTerm(pattern.getType())) {
va = matcher.matchSeq(goal, (String) pattern.getData(), match.getSignature()); va = matcher.matchSeq(goal, (String) pattern.getData(), match.getSignature());
} }
} }
...@@ -127,5 +132,29 @@ public class Evaluator<T> extends DefaultASTVisitor<Value> implements ScopeObser ...@@ -127,5 +132,29 @@ public class Evaluator<T> extends DefaultASTVisitor<Value> implements ScopeObser
return op.evaluate(exValue); return op.evaluate(exValue);
} }
public Value visit(SubstituteExpression expr) {
Value term = (Value) expr.getSub().accept(this);
if (term.getType() instanceof TermType) {
Pattern pattern = Pattern.compile("\\?[a-zA-Z_]+");
String termstr = term.getData().toString();
Matcher m = pattern.matcher(termstr);
StringBuffer newTerm = new StringBuffer();
while (m.find()) {
String name = m.group().substring(1); // remove trailing '?'
Expression t = expr.getSubstitution().get(m.group());
//either evalute the substitent or find ?X in the
String newVal = "";
if (t != null)
newVal = ((Value) t.accept(this)).getData().toString();
else
newVal = state.getValue(new Variable(name)).getData().toString();
m.appendReplacement(newTerm, newVal);
}
m.appendTail(newTerm);
return new Value<>(TypeFacade.ANY_TERM, newTerm.toString());
} else {
throw new IllegalStateException("Try to apply substitute on a non-term value.");
}
}
} }
...@@ -14,6 +14,8 @@ import edu.kit.formal.interpreter.funchdl.CommandLookup; ...@@ -14,6 +14,8 @@ import edu.kit.formal.interpreter.funchdl.CommandLookup;
import edu.kit.formal.proofscriptparser.DefaultASTVisitor; import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import edu.kit.formal.proofscriptparser.Visitor; import edu.kit.formal.proofscriptparser.Visitor;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.types.Type;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableList;
...@@ -33,15 +35,15 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -33,15 +35,15 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
implements ScopeObservable { implements ScopeObservable {
private static final int MAX_ITERATIONS = 5; private static final int MAX_ITERATIONS = 5;
@Getter @Getter
private static final BiMap<Type, VariableAssignments.VarType> typeConversionBiMap = private static final BiMap<SimpleType, VariableAssignments.VarType> typeConversionBiMap =
new ImmutableBiMap.Builder<Type, VariableAssignments.VarType>() new ImmutableBiMap.Builder<SimpleType, VariableAssignments.VarType>()
.put(Type.ANY, VariableAssignments.VarType.ANY) .put(SimpleType.ANY, VariableAssignments.VarType.ANY)
.put(Type.BOOL, VariableAssignments.VarType.BOOL) .put(SimpleType.BOOL, VariableAssignments.VarType.BOOL)
.put(Type.TERM, VariableAssignments.VarType.FORMULA) //TODO: parametrisierte Terms //.put(SimpleType.TERM, VariableAssignments.VarType.FORMULA) //TODO: parametrisierte Terms
.put(Type.INT, VariableAssignments.VarType.INT) .put(SimpleType.INT, VariableAssignments.VarType.INT)
.put(Type.STRING, VariableAssignments.VarType.OBJECT) .put(SimpleType.STRING, VariableAssignments.VarType.OBJECT)
.put(Type.INT_ARRAY, VariableAssignments.VarType.INT_ARRAY) .put(SimpleType.INT_ARRAY, VariableAssignments.VarType.INT_ARRAY)
.put(Type.SEQ, VariableAssignments.VarType.SEQ) .put(SimpleType.SEQ, VariableAssignments.VarType.SEQ)
.build(); .build();
private static Logger logger = Logger.getLogger("interpreter"); private static Logger logger = Logger.getLogger("interpreter");
//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)
...@@ -114,7 +116,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -114,7 +116,7 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
if (expr != null) { if (expr != null) {
Type type = node.getVariableType(var); Type type = node.getVariableType(var);
if (type == null) { if (type == null) {
throw new RuntimeException("Type of Variable " + var + " is not declared yet"); throw new RuntimeException("SimpleType of Variable " + var + " is not declared yet");
} else { } else {
Value v = evaluate(expr); Value v = evaluate(expr);
node.setVariableValue(var, v); node.setVariableValue(var, v);
......
...@@ -18,8 +18,9 @@ import edu.kit.formal.interpreter.data.Value; ...@@ -18,8 +18,9 @@ import edu.kit.formal.interpreter.data.Value;
import edu.kit.formal.interpreter.data.VariableAssignment; import edu.kit.formal.interpreter.data.VariableAssignment;
import edu.kit.formal.proofscriptparser.ast.Signature; import edu.kit.formal.proofscriptparser.ast.Signature;
import edu.kit.formal.proofscriptparser.ast.TermLiteral; import edu.kit.formal.proofscriptparser.ast.TermLiteral;
import edu.kit.formal.proofscriptparser.ast.Type; import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.ast.Variable; import edu.kit.formal.proofscriptparser.ast.Variable;
import edu.kit.formal.proofscriptparser.types.Type;
import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableList;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -114,7 +115,7 @@ public class KeYMatcher implements MatcherApi<KeyData> { ...@@ -114,7 +115,7 @@ public class KeYMatcher implements MatcherApi<KeyData> {
if (branchLabelMatcher.matches()) { if (branchLabelMatcher.matches()) {
VariableAssignment va = new VariableAssignment(null); VariableAssignment va = new VariableAssignment(null);
va.declare("$$branchLabel_", Type.STRING); va.declare("$$branchLabel_", SimpleType.STRING);
va.assign("$$branchLabel_", Value.from(branchLabelMatcher.group())); va.assign("$$branchLabel_", Value.from(branchLabelMatcher.group()));
assignments.add(va); assignments.add(va);
resultsFromLabelMatch.add(branchLabelMatcher.toMatchResult()); resultsFromLabelMatch.add(branchLabelMatcher.toMatchResult());
...@@ -124,7 +125,7 @@ public class KeYMatcher implements MatcherApi<KeyData> { ...@@ -124,7 +125,7 @@ public class KeYMatcher implements MatcherApi<KeyData> {
Matcher linesMatcher = regexpForLabel.matcher(controlFlowLines); Matcher linesMatcher = regexpForLabel.matcher(controlFlowLines);
if (linesMatcher.matches()) { if (linesMatcher.matches()) {
VariableAssignment va = new VariableAssignment(null); VariableAssignment va = new VariableAssignment(null);
va.declare("$$CtrlLinesLabel_", Type.STRING); va.declare("$$CtrlLinesLabel_", SimpleType.STRING);
va.assign("$$CtrlLinesLabel_", Value.from(linesMatcher.group())); va.assign("$$CtrlLinesLabel_", Value.from(linesMatcher.group()));
assignments.add(va); assignments.add(va);
resultsFromLabelMatch.add(linesMatcher.toMatchResult()); resultsFromLabelMatch.add(linesMatcher.toMatchResult());
...@@ -134,7 +135,7 @@ public class KeYMatcher implements MatcherApi<KeyData> { ...@@ -134,7 +135,7 @@ public class KeYMatcher implements MatcherApi<KeyData> {
Matcher flowStmtsMatcher = regexpForLabel.matcher(controlFlowLines); Matcher flowStmtsMatcher = regexpForLabel.matcher(controlFlowLines);
if (flowStmtsMatcher.matches()) { if (flowStmtsMatcher.matches()) {
VariableAssignment va = new VariableAssignment(null); VariableAssignment va = new VariableAssignment(null);
va.declare("$$FlowStmtsLabel_", Type.STRING); va.declare("$$FlowStmtsLabel_", SimpleType.STRING);
va.assign("$$FlowStmtsLabel_", Value.from(flowStmtsMatcher.group())); va.assign("$$FlowStmtsLabel_", Value.from(flowStmtsMatcher.group()));
assignments.add(va); assignments.add(va);
resultsFromLabelMatch.add(flowStmtsMatcher.toMatchResult()); resultsFromLabelMatch.add(flowStmtsMatcher.toMatchResult());
...@@ -144,7 +145,7 @@ public class KeYMatcher implements MatcherApi<KeyData> { ...@@ -144,7 +145,7 @@ public class KeYMatcher implements MatcherApi<KeyData> {
Matcher ruleMatcher = regexpForLabel.matcher(ruleLabel); Matcher ruleMatcher = regexpForLabel.matcher(ruleLabel);
if (ruleMatcher.matches()) { if (ruleMatcher.matches()) {
VariableAssignment va = new VariableAssignment(null); VariableAssignment va = new VariableAssignment(null);
va.declare("$$RuleLabel_", Type.STRING); va.declare("$$RuleLabel_", SimpleType.STRING);
va.assign("$$RuleLabel_", Value.from(ruleMatcher.group())); va.assign("$$RuleLabel_", Value.from(ruleMatcher.group()));
assignments.add(va); assignments.add(va);
resultsFromLabelMatch.add(ruleMatcher.toMatchResult()); resultsFromLabelMatch.add(ruleMatcher.toMatchResult());
......
...@@ -6,6 +6,8 @@ import edu.kit.formal.interpreter.data.VariableAssignment; ...@@ -6,6 +6,8 @@ import edu.kit.formal.interpreter.data.VariableAssignment;
import edu.kit.formal.proofscriptparser.DefaultASTVisitor; import edu.kit.formal.proofscriptparser.DefaultASTVisitor;
import edu.kit.formal.proofscriptparser.Visitor; import edu.kit.formal.proofscriptparser.Visitor;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.types.TypeFacade;
import lombok.Getter; import lombok.Getter;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
...@@ -156,10 +158,10 @@ public class MatchEvaluator extends DefaultASTVisitor<List<VariableAssignment>> ...@@ -156,10 +158,10 @@ public class MatchEvaluator extends DefaultASTVisitor<List<VariableAssignment>>
// Value pattern = (Value) match.getPattern().accept(this); // Value pattern = (Value) match.getPattern().accept(this);
List<VariableAssignment> va = null; List<VariableAssignment> va = null;
if (pattern.getType() == Type.STRING) { if (pattern.getType() == SimpleType.STRING) {
va = getMatcher().matchLabel(goal, (String) pattern.getData()); va = getMatcher().matchLabel(goal, (String) pattern.getData());
//TODO extract the results form the matcher in order to retrieve the selection results //TODO extract the results form the matcher in order to retrieve the selection results
} else if (pattern.getType() == Type.TERM) { } else if (TypeFacade.isTerm(pattern.getType())) {
va = getMatcher().matchSeq(goal, (String) pattern.getData(), sig); va = getMatcher().matchSeq(goal, (String) pattern.getData(), sig);
} }
return va != null ? va : Collections.emptyList(); return va != null ? va : Collections.emptyList();
...@@ -203,7 +205,7 @@ public class MatchEvaluator extends DefaultASTVisitor<List<VariableAssignment>> ...@@ -203,7 +205,7 @@ public class MatchEvaluator extends DefaultASTVisitor<List<VariableAssignment>>
*/ */
public List<VariableAssignment> transformTruthValue(Value v) { public List<VariableAssignment> transformTruthValue(Value v) {
if (v.getType().equals(Type.BOOL)) { if (v.getType().equals(SimpleType.BOOL)) {
List<VariableAssignment> transformedValue = new ArrayList<>(); List<VariableAssignment> transformedValue = new ArrayList<>();
if (v.getData().equals(Value.TRUE)) { if (v.getData().equals(Value.TRUE)) {
transformedValue.add(new VariableAssignment(null)); transformedValue.add(new VariableAssignment(null));
......
package edu.kit.formal.interpreter.data; package edu.kit.formal.interpreter.data;
import edu.kit.formal.proofscriptparser.ast.Type; import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.ast.Variable; import edu.kit.formal.proofscriptparser.ast.Variable;
import edu.kit.formal.proofscriptparser.types.Type;
import lombok.Getter; import lombok.Getter;
import lombok.ToString; import lombok.ToString;
......
package edu.kit.formal.interpreter.data; package edu.kit.formal.interpreter.data;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.types.Type;
import edu.kit.formal.proofscriptparser.types.TypeFacade;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -15,8 +18,8 @@ import java.math.BigInteger; ...@@ -15,8 +18,8 @@ import java.math.BigInteger;
*/ */
@RequiredArgsConstructor @RequiredArgsConstructor
public class Value<T> { public class Value<T> {
public static final Value TRUE = new Value<>(Type.BOOL, true); public static final Value TRUE = new Value<>(SimpleType.BOOL, true);
public static final Value FALSE = new Value<>(Type.BOOL, false); public static final Value FALSE = new Value<>(SimpleType.BOOL, false);
@Getter @Getter
private final Type type; private final Type type;
...@@ -25,35 +28,35 @@ public class Value<T> { ...@@ -25,35 +28,35 @@ public class Value<T> {
public static Value<BigInteger> from(IntegerLiteral i) { public static Value<BigInteger> from(IntegerLiteral i) {
return new Value<>(Type.INT, i.getValue()); return new Value<>(SimpleType.INT, i.getValue());
} }
public static Value<BigInteger> from(Integer i) { public static Value<BigInteger> from(Integer i) {
return new Value<>(Type.INT, BigInteger.valueOf(i)); return new Value<>(SimpleType.INT, BigInteger.valueOf(i));
} }
public static Value<String> from(StringLiteral s) { public static Value<String> from(StringLiteral s) {
return new Value<>(Type.STRING, s.getText()); return new Value<>(SimpleType.STRING, s.getText());
} }
public static Value<Boolean> from(BooleanLiteral b) { public static Value<Boolean> from(BooleanLiteral b) {
return new Value(Type.BOOL, b.isValue()); return new Value<>(SimpleType.BOOL, b.isValue());
} }
public static Value<Boolean> from(boolean equals) { public static Value<Boolean> from(boolean equals) {
return new Value(Type.BOOL, equals); return new Value<>(SimpleType.BOOL, equals);
} }
public static Value<BigInteger> from(BigInteger apply) { public static Value<BigInteger> from(BigInteger apply) {
return new Value<>(Type.INT, apply); return new Value<>(SimpleType.INT, apply);
} }
public static Value<String> from(String s) { public static Value<String> from(String s) {
return new Value<>(Type.STRING, s); return new Value<>(SimpleType.STRING, s);
} }
public static Value<String> from(TermLiteral term) { public static Value<String> from(TermLiteral term) {
return new Value<>(Type.TERM, term.getText()); return new Value<>(TypeFacade.ANY_TERM, term.getText());
} }
@Override @Override
......
package edu.kit.formal.interpreter.data; package edu.kit.formal.interpreter.data;
import edu.kit.formal.interpreter.exceptions.VariableNotDefinedException; import edu.kit.formal.interpreter.exceptions.VariableNotDefinedException;
import edu.kit.formal.proofscriptparser.ast.Type; import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.ast.Variable; import edu.kit.formal.proofscriptparser.ast.Variable;
import edu.kit.formal.proofscriptparser.types.Type;
import lombok.ToString; import lombok.ToString;
import java.util.HashMap; import java.util.HashMap;
......
...@@ -5,8 +5,9 @@ import edu.kit.formal.interpreter.data.GoalNode; ...@@ -5,8 +5,9 @@ import edu.kit.formal.interpreter.data.GoalNode;
import edu.kit.formal.interpreter.data.Value; import edu.kit.formal.interpreter.data.Value;
import edu.kit.formal.interpreter.data.VariableAssignment; import edu.kit.formal.interpreter.data.VariableAssignment;
import edu.kit.formal.proofscriptparser.ast.Signature; import edu.kit.formal.proofscriptparser.ast.Signature;
import edu.kit.formal.proofscriptparser.ast.Type; import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.ast.Variable; import edu.kit.formal.proofscriptparser.ast.Variable;
import edu.kit.formal.proofscriptparser.types.Type;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
......
...@@ -5,6 +5,7 @@ import edu.kit.formal.interpreter.Interpreter; ...@@ -5,6 +5,7 @@ import edu.kit.formal.interpreter.Interpreter;
import edu.kit.formal.interpreter.data.Value; import edu.kit.formal.interpreter.data.Value;
import edu.kit.formal.interpreter.data.VariableAssignment; import edu.kit.formal.interpreter.data.VariableAssignment;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.SimpleType;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
...@@ -39,7 +40,7 @@ public class MacroCommandHandler implements CommandHandler { ...@@ -39,7 +40,7 @@ public class MacroCommandHandler implements CommandHandler {
CallStatement macroCall = new CallStatement("macro", p); CallStatement macroCall = new CallStatement("macro", p);
macroCall.setRuleContext(call.getRuleContext()); macroCall.setRuleContext(call.getRuleContext());
VariableAssignment newParam = new VariableAssignment(null); VariableAssignment newParam = new VariableAssignment(null);
newParam.declare("#2", Type.STRING); newParam.declare("#2", SimpleType.STRING);
newParam.assign("#2", Value.from(call.getCommand())); newParam.assign("#2", Value.from(call.getCommand()));
//macro proofscript command //macro proofscript command
interpreter.getFunctionLookup().callCommand(interpreter, macroCall, newParam); interpreter.getFunctionLookup().callCommand(interpreter, macroCall, newParam);
......
package edu.kit.formal.interpreter.graphs; package edu.kit.formal.interpreter.graphs;
/** /**
* Edge Types a state graph and control flow graph may have * Edge Type a state graph and control flow graph may have
*/ */
public enum EdgeTypes { public enum EdgeTypes {
STEP_INTO, STEP_OVER, STEP_BACK, STEP_RETURN, STEP_OVER_COND, STATE_FLOW; STEP_INTO, STEP_OVER, STEP_BACK, STEP_RETURN, STEP_OVER_COND, STATE_FLOW;
......
...@@ -24,6 +24,8 @@ package edu.kit.formal.proofscriptparser; ...@@ -24,6 +24,8 @@ package edu.kit.formal.proofscriptparser;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.types.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
......
...@@ -24,6 +24,7 @@ package edu.kit.formal.proofscriptparser; ...@@ -24,6 +24,7 @@ package edu.kit.formal.proofscriptparser;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.Type;
import java.util.Map; import java.util.Map;
...@@ -146,7 +147,7 @@ public interface ASTTraversal<T> extends Visitor<T> { ...@@ -146,7 +147,7 @@ public interface ASTTraversal<T> extends Visitor<T> {
@Override @Override
default T visit(Parameters parameters) { default T visit(Parameters parameters) {
for (Map.Entry<Variable, Expression> e : for (Map.Entry<Variable, Expression> e :
parameters.entrySet()) { parameters.entrySet()) {
e.getKey().accept(this); e.getKey().accept(this);
e.getValue().accept(this); e.getValue().accept(this);
} }
...@@ -171,4 +172,13 @@ public interface ASTTraversal<T> extends Visitor<T> { ...@@ -171,4 +172,13 @@ public interface ASTTraversal<T> extends Visitor<T> {
simpleCaseStatement.getBody().accept(this); simpleCaseStatement.getBody().accept(this);
return null; return null;
} }
@Override
default T visit(SubstituteExpression subst) {
subst.getSub().accept(this);
for (Expression e : subst.getSubstitution().values()) {
e.accept(this);
}
return null;
}
} }
...@@ -94,6 +94,11 @@ public class DefaultASTVisitor<T> implements Visitor<T> { ...@@ -94,6 +94,11 @@ public class DefaultASTVisitor<T> implements Visitor<T> {
return defaultVisit(caseStatement); return defaultVisit(caseStatement);
} }
@Override
public T visit(SubstituteExpression subst) {
return defaultVisit(subst);
}
@Override @Override
public T visit(CallStatement call) { public T visit(CallStatement call) {
return defaultVisit(call); return defaultVisit(call);
...@@ -138,5 +143,6 @@ public class DefaultASTVisitor<T> implements Visitor<T> { ...@@ -138,5 +143,6 @@ public class DefaultASTVisitor<T> implements Visitor<T> {
public T visit(SimpleCaseStatement simpleCaseStatement) { public T visit(SimpleCaseStatement simpleCaseStatement) {
return defaultVisit(simpleCaseStatement); return defaultVisit(simpleCaseStatement);
} }
} }
...@@ -24,6 +24,8 @@ package edu.kit.formal.proofscriptparser; ...@@ -24,6 +24,8 @@ package edu.kit.formal.proofscriptparser;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.SimpleType;
import edu.kit.formal.proofscriptparser.types.Type;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
......
...@@ -24,6 +24,7 @@ package edu.kit.formal.proofscriptparser; ...@@ -24,6 +24,7 @@ package edu.kit.formal.proofscriptparser;
import edu.kit.formal.proofscriptparser.ast.*; import edu.kit.formal.proofscriptparser.ast.*;
import edu.kit.formal.proofscriptparser.types.TypeFacade;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode; import org.antlr.v4.runtime.tree.ErrorNode;
import org.antlr.v4.runtime.tree.ParseTree; import org.antlr.v4.runtime.tree.ParseTree;
...@@ -31,7 +32,9 @@ import org.antlr.v4.runtime.tree.RuleNode; ...@@ -31,7 +32,9 @@ import org.antlr.v4.runtime.tree.RuleNode;
import org.antlr.v4.runtime.tree.TerminalNode; import org.antlr.v4.runtime.tree.TerminalNode;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author Alexander Weigl * @author Alexander Weigl
...@@ -66,7 +69,8 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -66,7 +69,8 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
public Signature visitArgList(ScriptLanguageParser.ArgListContext ctx) { public Signature visitArgList(ScriptLanguageParser.ArgListContext ctx) {
Signature signature = new Signature(); Signature signature = new Signature();
for (ScriptLanguageParser.VarDeclContext decl : ctx.varDecl()) { for (ScriptLanguageParser.VarDeclContext decl : ctx.varDecl()) {
signature.put(new Variable(decl.name), Type.findType(decl.type.getText())); signature.put(new Variable(decl.name),
TypeFacade.findType(decl.type.getText()));
} }
return signature; return signature;
} }
...@@ -80,7 +84,7 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -80,7 +84,7 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
public Object visitVarDecl(ScriptLanguageParser.VarDeclContext ctx) { public Object visitVarDecl(ScriptLanguageParser.VarDeclContext ctx) {
/* VariableDeclaration varDecl = new VariableDeclaration(); /* VariableDeclaration varDecl = new VariableDeclaration();
varDecl.setIdentifier(new Variable(ctx.name)); varDecl.setIdentifier(new Variable(ctx.name));
varDecl.setType(Type.findType(ctx.type.getText())); varDecl.setType(SimpleType.findType(ctx.type.getText()));
return varDecl;*/ return varDecl;*/
return null; return null;
...@@ -90,7 +94,7 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -90,7 +94,7 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
public Statements visitStmtList(ScriptLanguageParser.StmtListContext ctx) { public Statements visitStmtList(ScriptLanguageParser.StmtListContext ctx) {
Statements statements = new Statements(); Statements statements = new Statements();
for (ScriptLanguageParser.StatementContext stmt : ctx.statement()) { for (ScriptLanguageParser.StatementContext stmt : ctx.statement()) {
statements.add((Statement) stmt.accept(this)); statements.add((Statement<ParserRuleContext>) stmt.accept(this));
} }
return statements; return statements;
}