Skip to content

Commit d4519c9

Browse files
committed
Support XOR in STS DSL
1 parent 2f4f843 commit d4519c9

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ buildscript {
1010

1111
allprojects {
1212
group = "hu.bme.mit.inf.theta"
13-
version = "1.4.1"
13+
version = "1.4.2"
1414

1515
apply(from = rootDir.resolve("gradle/shared-with-buildSrc/mirrors.gradle.kts"))
1616
}

subprojects/sts/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Expressions of the STS include the following.
3434
- Primed expressions (only in transition expression) to represent the next state, e.g., `x'`.
3535
- Literals, e.g., `true`, `false` (Bool), `0`, `123` (integer), `4 % 5` (rational).
3636
- Comparison, e.g., `=`, `/=`, `<`, `>`, `<=`, `>=`.
37-
- Boolean operators, e.g., `and`, `or`, `not`, `imply`, `iff`.
37+
- Boolean operators, e.g., `and`, `or`, `xor`, `not`, `imply`, `iff`.
3838
- Arithmetic, e.g., `+`, `-`, `/`, `*`, `mod`, `rem`.
3939
- Conditional: `if . then . else .`
4040
- Array read (`a[i]`) and write (`a[i <- v]`).

subprojects/sts/src/main/antlr/StsDsl.g4

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ existsExpr
211211
;
212212

213213
orExpr
214-
: ops+=andExpr (OR ops+=andExpr)*
214+
: ops+=xorExpr (OR ops+=xorExpr)*
215+
;
216+
217+
xorExpr
218+
: leftOp=andExpr (XOR rightOp=xorExpr)?
215219
;
216220

217221
andExpr
@@ -331,6 +335,9 @@ OR : 'or'
331335
AND : 'and'
332336
;
333337

338+
XOR : 'xor'
339+
;
340+
334341
NOT : 'not'
335342
;
336343

subprojects/sts/src/main/java/hu/bme/mit/theta/sts/dsl/StsExprCreatorVisitor.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,7 @@
3232
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Neq;
3333
import static hu.bme.mit.theta.core.type.abstracttype.AbstractExprs.Sub;
3434
import static hu.bme.mit.theta.core.type.anytype.Exprs.Prime;
35-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.And;
36-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Bool;
37-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Exists;
38-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.False;
39-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Forall;
40-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Iff;
41-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Imply;
42-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Not;
43-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.Or;
44-
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.True;
35+
import static hu.bme.mit.theta.core.type.booltype.BoolExprs.*;
4536
import static hu.bme.mit.theta.core.type.functype.FuncExprs.Func;
4637
import static hu.bme.mit.theta.core.type.inttype.IntExprs.Int;
4738
import static hu.bme.mit.theta.core.type.inttype.IntExprs.Mod;
@@ -107,6 +98,7 @@
10798
import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.RatLitExprContext;
10899
import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.RelationExprContext;
109100
import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.TrueExprContext;
101+
import hu.bme.mit.theta.sts.dsl.gen.StsDslParser.XorExprContext;
110102

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

@@ -230,6 +222,17 @@ public Expr<?> visitOrExpr(final OrExprContext ctx) {
230222
}
231223
}
232224

225+
@Override
226+
public Expr<?> visitXorExpr(final XorExprContext ctx) {
227+
if (ctx.rightOp != null) {
228+
final Expr<BoolType> leftOp = TypeUtils.cast(ctx.leftOp.accept(this), Bool());
229+
final Expr<BoolType> rightOp = TypeUtils.cast(ctx.rightOp.accept(this), Bool());
230+
return Xor(leftOp, rightOp);
231+
} else {
232+
return visitChildren(ctx);
233+
}
234+
}
235+
233236
@Override
234237
public Expr<?> visitAndExpr(final AndExprContext ctx) {
235238
if (ctx.ops.size() > 1) {

0 commit comments

Comments
 (0)