Commit 3c2fa0ad authored by Sarah Grebing's avatar Sarah Grebing

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/main/java/edu/kit/formal/psdb/termmatcher/MatcherImpl.java
parents 427e4177 c2e74e84
......@@ -9,7 +9,9 @@ cache:
variables:
MAVEN_OPTS: -Dmaven.repo.local=${CI_PROJECT_DIR}/.m2
GIT_SUBMODULE_STRATEGY: recursive
GIT_SSL_NO_VERIFY: "true"
build:
......
......@@ -20,30 +20,28 @@ sequentPattern : antec=semiSeqPattern? ARROW succ=semiSeqPattern? | anywhere=sem
semiSeqPattern : termPattern (',' termPattern)*;
termPattern :
DONTCARE #dontCare
//| STARDONTCARE #starDontCare
| SID #schemaVar
| STARDONTCARE termPattern STARDONTCARE #anywhere
| DIGITS #number
| func=ID ( '(' termPattern (',' termPattern)* ')')? #function
| left=termPattern op=(PLUS|MINUS|MUL|LE|GE|LEQ|GEQ|NEQ|EQ| AND|OR|IMP) right=termPattern #binaryOperation
;
termPattern MUL termPattern #mult
| <assoc=right> termPattern op=(DIV|MOD) termPattern #divMod
| termPattern op=(PLUS|MINUS) termPattern #plusMinus
| termPattern op=(LE|GE|LEQ|GEQ) termPattern #comparison
| termPattern op=(NEQ|EQ) termPattern #equality
| termPattern AND termPattern #and
| termPattern OR termPattern #or
| termPattern IMP termPattern #impl
| termPattern XOR termPattern #xor
//| termPattern EQUIV termPattern already covered by EQ/NEQ
| MINUS termPattern #exprNegate
| NOT termPattern #exprNot
| '(' termPattern ')' #exprParen
| func=ID ( '(' termPattern (',' termPattern)* ')')? #function
| DONTCARE #dontCare
//| STARDONTCARE #starDontCare
| SID #schemaVar
| STARDONTCARE termPattern STARDONTCARE #anywhere
| DIGITS #number
// not working because of ambigue | left=termPattern op=(PLUS|MINUS|MUL|LE|GE|LEQ|GEQ|NEQ|EQ| AND|OR|IMP) right=termPattern #binaryOperation
;
/*
expression MUL expression #exprMultiplication
| <assoc=right> expression DIV expression #exprDivision
| expression op=(PLUS|MINUS) expression #exprLineOperators
| expression op=(LE|GE|LEQ|GEQ) expression #exprComparison
| expression op=(NEQ|EQ) expression #exprEquality
| expression AND expression #exprAnd
| expression OR expression #exprOr
| expression IMP expression #exprIMP
//| expression EQUIV expression already covered by EQ/NEQ
| expression LBRACKET substExpressionList RBRACKET #exprSubst
| MINUS expression #exprNegate
| NOT expression #exprNot
| '(' expression ')' #exprParen
*/
/*
f(x), f(x,y,g(y)), X, ?Y, _, ..., f(... ?X ...), f(..., ?X), f(..., ...?X...), f(..., ... g(x) ...), f(_, x, _, y, ... y ...)
*/
......@@ -52,12 +50,6 @@ f(x), f(x,y,g(y)), X, ?Y, _, ..., f(... ?X ...), f(..., ?X), f(..., ...?X...), f
ARROW : '⇒' | '==>';
DONTCARE: '?' | '_' | '█';
STARDONTCARE: '...' | '…';
DIGITS : DIGIT+ ;
fragment DIGIT : [0-9] ;
SID: '?' [_a-zA-Z0-9\\]+ ;
ID : [a-zA-Z\\_] ([_a-zA-Z0-9\\])*;
PLUS : '+' ;
MINUS : '-' ;
MUL : '*' ;
......@@ -71,6 +63,13 @@ LE : '<' ;
AND : '&' ;
OR: '|' ;
IMP: '->';
MOD:'%';
XOR:'^';
DIGITS : DIGIT+ ;
fragment DIGIT : [0-9] ;
SID: '?' [_a-zA-Z0-9\\]+ ;
ID : [a-zA-Z\\_] ([_a-zA-Z0-9\\])*;
COMMENT: '//' ~[\n\r]* -> channel(HIDDEN);
WS: [\n\f\r\t ] -> channel(HIDDEN);
\ No newline at end of file
WS: [\n\f\r\t ] -> channel(HIDDEN);
......@@ -55,11 +55,6 @@ public abstract class MatchPatternDualVisitor<T, S> extends MatchPatternBaseVisi
return visitFunction(ctx, stack.peek());
}
@Override
public T visitBinaryOperation(MatchPatternParser.BinaryOperationContext ctx) {
return visitBinaryOperation(ctx, stack.peek());
}
@Override
public final T visitAnywhere(MatchPatternParser.AnywhereContext ctx) {
return visitAnywhere(ctx, stack.peek());
......@@ -67,11 +62,94 @@ public abstract class MatchPatternDualVisitor<T, S> extends MatchPatternBaseVisi
protected abstract T visitAnywhere(MatchPatternParser.AnywhereContext ctx, S peek);
protected abstract T visitBinaryOperation(MatchPatternParser.BinaryOperationContext ctx, S peek);
protected abstract T visitFunction(MatchPatternParser.FunctionContext ctx, S peek);
protected abstract T visitNumber(MatchPatternParser.NumberContext ctx, S peek);
protected abstract T visitSequentPattern(MatchPatternParser.SequentPatternContext ctx, S peek);
@Override
public T visitPlusMinus(MatchPatternParser.PlusMinusContext ctx) {
return visitPlusMinus(ctx, stack.peek());
}
protected abstract T visitPlusMinus(MatchPatternParser.PlusMinusContext ctx, S peek);
@Override
public T visitMult(MatchPatternParser.MultContext ctx) {
return visitMult(ctx, stack.peek());
}
protected abstract T visitMult(MatchPatternParser.MultContext ctx, S peek);
@Override
public T visitComparison(MatchPatternParser.ComparisonContext ctx) {
return visitComparison(ctx, stack.peek());
}
protected abstract T visitComparison(MatchPatternParser.ComparisonContext ctx, S peek);
@Override
public T visitOr(MatchPatternParser.OrContext ctx) {
return visitOr(ctx, stack.peek());
}
protected abstract T visitOr(MatchPatternParser.OrContext ctx, S peek);
@Override
public T visitExprNot(MatchPatternParser.ExprNotContext ctx) {
return visitExprNot(ctx, stack.peek());
}
public abstract T visitExprNot(MatchPatternParser.ExprNotContext ctx, S peek);
@Override
public T visitExprNegate(MatchPatternParser.ExprNegateContext ctx) {
return visitExprNegate(ctx, stack.peek());
}
public abstract T visitExprNegate(MatchPatternParser.ExprNegateContext ctx, S peek);
@Override
public T visitExprParen(MatchPatternParser.ExprParenContext ctx) {
return accept(ctx.termPattern(), stack.peek());
}
@Override
public T visitImpl(MatchPatternParser.ImplContext ctx) {
return visitImpl(ctx, stack.peek());
}
protected abstract T visitImpl(MatchPatternParser.ImplContext ctx, S peek);
@Override
public T visitDivMod(MatchPatternParser.DivModContext ctx) {
return visitDivMod(ctx, stack.peek());
}
protected abstract T visitDivMod(MatchPatternParser.DivModContext ctx, S peek);
@Override
public T visitAnd(MatchPatternParser.AndContext ctx) {
return visitAnd(ctx, stack.peek());
}
protected abstract T visitAnd(MatchPatternParser.AndContext ctx, S peek);
@Override
public T visitXor(MatchPatternParser.XorContext ctx) {
return visitXor(ctx, stack.peek());
}
protected abstract T visitXor(MatchPatternParser.XorContext ctx, S peek);
@Override
public T visitEquality(MatchPatternParser.EqualityContext ctx) {
return visitEquality(ctx, stack.peek());
}
protected abstract T visitEquality(MatchPatternParser.EqualityContext ctx, S peek);
}
......@@ -4,6 +4,8 @@ import de.uka.ilkd.key.logic.SequentFormula;
import de.uka.ilkd.key.logic.Term;
import org.antlr.v4.runtime.Token;
import org.key_project.util.collection.ImmutableArray;
import org.antlr.v4.runtime.CommonToken;
import org.apache.commons.lang.NotImplementedException;
import java.util.*;
import java.util.stream.IntStream;
......@@ -11,6 +13,7 @@ import java.util.stream.Stream;
/**
* Matchpattern visitor visits the matchpatterns of case-statements
*
* @author Alexander Weigl
* @author S. Grebing
*/
......@@ -111,6 +114,7 @@ class MatcherImpl extends MatchPatternDualVisitor<Matchings, Term> {
/**
* Visit a '...'Term'...' structure
*
* @param ctx
* @param peek
* @return
......@@ -125,29 +129,12 @@ class MatcherImpl extends MatchPatternDualVisitor<Matchings, Term> {
return m;
}
@Override
protected Matchings visitBinaryOperation(MatchPatternParser.BinaryOperationContext ctx, Term peek) {
Token op = ctx.op;
String opToKeYName = convert(op.getType());
MatchPatternParser.TermPatternContext left = ctx.left;
MatchPatternParser.TermPatternContext right = ctx.right;
if (peek.op().name().toString().equals(opToKeYName) // same name
&& peek.arity() == 2 // we know that we are in binary term
) {
Matchings lM = accept(left, peek.sub(0));
Matchings rM = accept(right, peek.sub(1));
Matchings ret = reduceConform(lM, rM);
return ret;
/*return IntStream.range(0, peek.arity())
.mapToObj(i -> (Matchings) accept(ctx.termPattern(i), peek.sub(i)))
.reduce(MatcherImpl::reduceConform)
.orElse(NO_MATCH);*/
}
return NO_MATCH;
protected Matchings visitBinaryOperation(String keyOpName, MatchPatternParser.TermPatternContext right, MatchPatternParser.TermPatternContext left, Term peek) {
MatchPatternParser.FunctionContext func = new MatchPatternParser.FunctionContext(left);
func.func = new CommonToken(MatchPatternLexer.ID, keyOpName);
func.termPattern().add(left);
func.termPattern().add(right);
return accept(func, peek);
}
private String convert(int op) {
......@@ -233,6 +220,7 @@ class MatcherImpl extends MatchPatternDualVisitor<Matchings, Term> {
/**
* Visit a function and predicate symbol without a sequent arrow
*
* @param ctx
* @param peek
* @return
......@@ -251,6 +239,17 @@ class MatcherImpl extends MatchPatternDualVisitor<Matchings, Term> {
return NO_MATCH;
}
/**
* Visit a semisequent pattern f(x), f(y)
* @param ctx
* @param peek
* @return
*/
@Override
protected Matchings visitSemiSeqPattern(MatchPatternParser.SemiSeqPatternContext ctx, Term peek) {
return null;
}
@Override
protected Matchings visitNumber(MatchPatternParser.NumberContext ctx, Term peek) {
//we are at a natural number
......@@ -274,13 +273,80 @@ class MatcherImpl extends MatchPatternDualVisitor<Matchings, Term> {
/**
* Visit a sequent pattern 'f(x) ==> f(x)', 'f(x) ==>' or '==> f(x)'
*
* @param ctx
* @param peek
* @return
*/
@Override
protected Matchings visitSequentPattern(MatchPatternParser.SequentPatternContext ctx, Term peek) {
return null;
throw new NotImplementedException("use the facade!");
}
@Override
protected Matchings visitPlusMinus(MatchPatternParser.PlusMinusContext ctx, Term peek) {
return visitBinaryOperation(convert(ctx.op.getType()),
ctx.termPattern(0), ctx.termPattern(1), peek);
}
@Override
protected Matchings visitMult(MatchPatternParser.MultContext ctx, Term peek) {
return visitBinaryOperation("mul", ctx.termPattern(0), ctx.termPattern(1), peek);
}
@Override
protected Matchings visitComparison(MatchPatternParser.ComparisonContext ctx, Term peek) {
return visitBinaryOperation(convert(ctx.op.getType()), ctx.termPattern(0), ctx.termPattern(1), peek);
}
@Override
protected Matchings visitOr(MatchPatternParser.OrContext ctx, Term peek) {
return visitBinaryOperation("or", ctx.termPattern(0), ctx.termPattern(1), peek);
}
@Override
public Matchings visitExprNot(MatchPatternParser.ExprNotContext ctx, Term peek) {
return visitBinaryOperation("not", ctx.termPattern(), ctx, peek);
}
@Override
public Matchings visitExprNegate(MatchPatternParser.ExprNegateContext ctx, Term peek) {
return visitUnaryOperation("sub", ctx.termPattern(), peek);
}
private Matchings visitUnaryOperation(String unaryOp,
MatchPatternParser.TermPatternContext ctx,
Term peek) {
MatchPatternParser.FunctionContext func = new MatchPatternParser.FunctionContext(ctx);
func.termPattern().add(ctx);;
func.func = new CommonToken(MatchPatternLexer.ID, unaryOp);
return accept(func, peek);
}
@Override
protected Matchings visitImpl(MatchPatternParser.ImplContext ctx, Term peek) {
return visitBinaryOperation("imp", ctx.termPattern(0), ctx.termPattern(1), peek);
}
@Override
protected Matchings visitDivMod(MatchPatternParser.DivModContext ctx, Term peek) {
return visitBinaryOperation(convert(ctx.op.getType()), ctx.termPattern(0), ctx.termPattern(1), peek);
}
@Override
protected Matchings visitAnd(MatchPatternParser.AndContext ctx, Term peek) {
return visitBinaryOperation("and", ctx.termPattern(0), ctx.termPattern(1), peek);
}
@Override
protected Matchings visitXor(MatchPatternParser.XorContext ctx, Term peek) {
return visitBinaryOperation("xor", ctx.termPattern(0), ctx.termPattern(1), peek);
}
@Override
protected Matchings visitEquality(MatchPatternParser.EqualityContext ctx, Term peek) {
return visitBinaryOperation("eq", ctx.termPattern(0), ctx.termPattern(1), peek);
}
private Stream<Term> subTerms(Term peek) {
......
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