Add logical and comparison expressions
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
# Logical and Comparison Expressions
|
||||
|
||||
Decodal supports boolean logic over concrete `Bool` values and comparison over concrete scalar values.
|
||||
|
||||
```dcdl
|
||||
{
|
||||
is_prod = env == "prod";
|
||||
high_port = port > 9000;
|
||||
enabled = is_prod && high_port;
|
||||
disabled = !enabled;
|
||||
}
|
||||
```
|
||||
|
||||
## Logical operators
|
||||
|
||||
- `!expr` negates a concrete `Bool`.
|
||||
- `lhs && rhs` returns boolean AND.
|
||||
- `lhs || rhs` returns boolean OR.
|
||||
|
||||
`&&` and `||` short-circuit: the right-hand side is evaluated only when needed.
|
||||
Logical operands must evaluate to concrete `Bool` values.
|
||||
|
||||
## Comparison operators
|
||||
|
||||
- `==`
|
||||
- `!=`
|
||||
- `<`
|
||||
- `<=`
|
||||
- `>`
|
||||
- `>=`
|
||||
|
||||
`==` and `!=` compare concrete scalar values: `String`, `Bool`, `Int`, and `Float`.
|
||||
`Int` and `Float` can be compared to each other numerically.
|
||||
|
||||
Ordering operators `<`, `<=`, `>`, and `>=` compare concrete numeric values only.
|
||||
They are separate from prefix comparison constraints such as `> 443`.
|
||||
|
||||
```dcdl
|
||||
port = Int & > 443 default 9443;
|
||||
is_high = port > 9000;
|
||||
```
|
||||
@@ -7,12 +7,15 @@
|
||||
優先順位は高い順に以下である。
|
||||
|
||||
1. 関数呼び出しとフィールド参照
|
||||
2. unary `-`
|
||||
2. unary `!` `-`
|
||||
3. `*` `/`
|
||||
4. `+` `-`
|
||||
5. `&`
|
||||
6. `//`
|
||||
7. `default`
|
||||
5. `==` `!=` `<` `<=` `>` `>=`
|
||||
6. `&&`
|
||||
7. `||`
|
||||
8. `&`
|
||||
9. `//`
|
||||
10. `default`
|
||||
|
||||
同じ優先順位の二項演算子は左結合である。
|
||||
`default` は右結合である。
|
||||
@@ -22,6 +25,15 @@
|
||||
`+` `-` `*` `/` は具体的な `Int` / `Float` に対する四則演算である。
|
||||
詳しくは [Arithmetic Expression](./expression/arithmetic.md) を参照する。
|
||||
|
||||
## Logical and comparison operators
|
||||
|
||||
`!` `&&` `||` は concrete `Bool` に対する論理演算である。
|
||||
`&&` と `||` は短絡評価される。
|
||||
|
||||
`==` `!=` は concrete scalar value を比較する。
|
||||
`<` `<=` `>` `>=` は concrete numeric value を比較する。
|
||||
詳しくは [Logical and Comparison Expressions](./expression/logical-and-comparison.md) を参照する。
|
||||
|
||||
## `&`: 制約合成
|
||||
|
||||
`&` は値・制約・構造を合成する演算子である。
|
||||
|
||||
@@ -115,12 +115,14 @@ rec
|
||||
主要な演算子は以下である。
|
||||
|
||||
```text
|
||||
+ - * / 四則演算
|
||||
& 制約合成
|
||||
// patch 合成
|
||||
default fallback 指定
|
||||
=> 関数
|
||||
. フィールド参照 / ドットパス定義
|
||||
+ - * / 四則演算
|
||||
! && || 論理演算
|
||||
== != < <= > >= 比較式
|
||||
& 制約合成
|
||||
// patch 合成
|
||||
default fallback 指定
|
||||
=> 関数
|
||||
. フィールド参照 / ドットパス定義
|
||||
```
|
||||
|
||||
演算子の優先順位は [合成演算子](./operators.md) で定義する。
|
||||
|
||||
Reference in New Issue
Block a user