Skip to content

Commit

Permalink
Merge pull request #57 from ftsrg/xor
Browse files Browse the repository at this point in the history
Support XOR in the CFA DSL
  • Loading branch information
hajduakos authored Jul 16, 2020
2 parents 39d76d0 + bbc4271 commit 766f08f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 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.2.0"
version = "1.2.1"

apply(from = rootDir.resolve("gradle/shared-with-buildSrc/mirrors.gradle.kts"))
}
Expand Down
2 changes: 1 addition & 1 deletion subprojects/cfa/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Expressions of the CFA include the following.
- Literals, e.g., `true`, `false` (Bool), `0`, `123` (integer), `4 % 5` (rational).
- Array literals can be given by listing the key-value pairs and the (mandatory) default element, e.g., `[0 <- 182, 1 <- 41, default <- 75]`. If there are no elements, the key type has to be given before the default element, e.g., `[<int>default <- 75]`.
- 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
11 changes: 9 additions & 2 deletions subprojects/cfa/src/main/antlr/CfaDsl.g4
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ existsExpr
;

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

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

andExpr
Expand Down Expand Up @@ -225,7 +229,7 @@ primaryExpr
| falseExpr
| intLitExpr
| ratLitExpr
| arrLitExpr
| arrLitExpr
| idExpr
| parenExpr
;
Expand Down Expand Up @@ -291,6 +295,9 @@ OR : 'or'
AND : 'and'
;

XOR : 'xor'
;

NOT : 'not'
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,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 766f08f

Please sign in to comment.