Skip to content

Commit

Permalink
Support XOR in STS DSL
Browse files Browse the repository at this point in the history
  • Loading branch information
hajduakos committed Jul 30, 2020
1 parent 2f4f843 commit d4519c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {

allprojects {
group = "hu.bme.mit.inf.theta"
version = "1.4.1"
version = "1.4.2"

apply(from = rootDir.resolve("gradle/shared-with-buildSrc/mirrors.gradle.kts"))
}
Expand Down
2 changes: 1 addition & 1 deletion subprojects/sts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Expressions of the STS include the following.
- Primed expressions (only in transition expression) to represent the next state, e.g., `x'`.
- Literals, e.g., `true`, `false` (Bool), `0`, `123` (integer), `4 % 5` (rational).
- Comparison, e.g., `=`, `/=`, `<`, `>`, `<=`, `>=`.
- Boolean operators, e.g., `and`, `or`, `not`, `imply`, `iff`.
- Boolean operators, e.g., `and`, `or`, `xor`, `not`, `imply`, `iff`.
- Arithmetic, e.g., `+`, `-`, `/`, `*`, `mod`, `rem`.
- Conditional: `if . then . else .`
- Array read (`a[i]`) and write (`a[i <- v]`).
Expand Down
9 changes: 8 additions & 1 deletion subprojects/sts/src/main/antlr/StsDsl.g4
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ existsExpr
;

orExpr
: ops+=andExpr (OR ops+=andExpr)*
: ops+=xorExpr (OR ops+=xorExpr)*
;

xorExpr
: leftOp=andExpr (XOR rightOp=xorExpr)?
;

andExpr
Expand Down Expand Up @@ -331,6 +335,9 @@ OR : 'or'
AND : 'and'
;

XOR : 'xor'
;

NOT : 'not'
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,7 @@
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neq;
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Sub;
import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Iff;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Imply;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True;
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*;
import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func;
import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int;
import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mod;
Expand Down Expand Up @@ -107,6 +98,7 @@
import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.RatLitExprContext;
import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.RelationExprContext;
import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.TrueExprContext;
import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.XorExprContext;

final class StsExprCreatorVisitor extends StsDslBaseVisitor<Expr<?>> {

Expand Down Expand Up @@ -230,6 +222,17 @@ public Expr<?> visitOrExpr(final OrExprContext ctx) {
}
}

@Override
public Expr<?> visitXorExpr(final XorExprContext ctx) {
if (ctx.rightOp != null) {
final Expr<BoolType> leftOp = TypeUtils.cast(ctx.leftOp.accept(this), Bool());
final Expr<BoolType> rightOp = TypeUtils.cast(ctx.rightOp.accept(this), Bool());
return Xor(leftOp, rightOp);
} else {
return visitChildren(ctx);
}
}

@Override
public Expr<?> visitAndExpr(final AndExprContext ctx) {
if (ctx.ops.size() > 1) {
Expand Down

0 comments on commit d4519c9

Please sign in to comment.