Add arithmetic expressions

This commit is contained in:
2026-06-17 23:00:14 +09:00
parent dc28cddbff
commit 3f7dd7c692
18 changed files with 6336 additions and 2757 deletions
@@ -0,0 +1,43 @@
# Arithmetic Expression
Decodal supports arithmetic over concrete numeric values.
```dcdl
{
workers = 2 + 2;
timeout = 30.0 / 2;
port = 8000 + 80;
negative = -1;
}
```
## Operators
- `+` addition
- `-` subtraction
- `*` multiplication
- `/` division
- unary `-` negation
`*` and `/` bind tighter than `+` and `-`.
Parentheses can be used to make grouping explicit.
```dcdl
2 + 3 * 4 # 14
(2 + 3) * 4 # 20
```
## Numeric behavior
Arithmetic requires concrete `Int` or `Float` operands.
`Int + Int`, `Int - Int`, and `Int * Int` produce `Int` when no overflow occurs.
Mixed `Int` / `Float` arithmetic produces `Float`.
Division always produces `Float`.
Division by zero and integer overflow are evaluation errors.
Arithmetic expressions can be used anywhere a concrete numeric expression is expected, including defaults and numeric constraints.
```dcdl
port = Int & > 4000 + 42 default 8080;
```
+22 -2
View File
@@ -1,6 +1,26 @@
# 合成演算子
# 演算子
この章では、`&``//` の意味を定義する。
この章では、Decodal の演算子の意味を定義する。
## 優先順位
優先順位は高い順に以下である。
1. 関数呼び出しとフィールド参照
2. unary `-`
3. `*` `/`
4. `+` `-`
5. `&`
6. `//`
7. `default`
同じ優先順位の二項演算子は左結合である。
`default` は右結合である。
## Arithmetic operators
`+` `-` `*` `/` は具体的な `Int` / `Float` に対する四則演算である。
詳しくは [Arithmetic Expression](./expression/arithmetic.md) を参照する。
## `&`: 制約合成
+2 -2
View File
@@ -115,6 +115,7 @@ rec
主要な演算子は以下である。
```text
+ - * / 四則演算
& 制約合成
// patch 合成
default fallback 指定
@@ -122,5 +123,4 @@ default fallback 指定
. フィールド参照 / ドットパス定義
```
演算子の優先順位は未確定である。
詳細は [合成演算子](./operators.md) で定義する。
演算子の優先順位は [合成演算子](./operators.md) で定義する。