summaryrefslogtreecommitdiff
path: root/docs/chapter23
diff options
context:
space:
mode:
Diffstat (limited to 'docs/chapter23')
-rw-r--r--docs/chapter23/23-grammar.ja.md9
-rw-r--r--docs/chapter23/23-grammar.md9
-rw-r--r--docs/chapter23/README.ja.md2
-rw-r--r--docs/chapter23/README.md14
4 files changed, 28 insertions, 6 deletions
diff --git a/docs/chapter23/23-grammar.ja.md b/docs/chapter23/23-grammar.ja.md
index ff7b5d56..682bd967 100644
--- a/docs/chapter23/23-grammar.ja.md
+++ b/docs/chapter23/23-grammar.ja.md
@@ -80,11 +80,16 @@ expression : logicalExpression ('?' assignment (':' assignment)?)? ;
logicalExpression : bitwiseExpression (('&&' | '||') logicalExpression)? ;
bitwiseExpression
- : comparisonExpression (('&' | '|' | '^') comparisonExpression)*
+ : equalityExpression (('&' | '|' | '^') equalityExpression)*
;
+equalityExpression : comparisonExpression (('==' | '!=') comparisonExpression)* ;
+
+// Compare adjacent operands once; stop after the first false comparison.
+// Keep one direction per chain; < and <= (or > and >=) may mix.
comparisonExpression
- : shiftExpression (('==' | '!=' | '<' | '<=' | '>' | '>=') shiftExpression)*
+ : shiftExpression (('<' | '<=') shiftExpression)*
+ | shiftExpression (('>' | '>=') shiftExpression)+
;
shiftExpression
diff --git a/docs/chapter23/23-grammar.md b/docs/chapter23/23-grammar.md
index 1d52d5a6..cd231b08 100644
--- a/docs/chapter23/23-grammar.md
+++ b/docs/chapter23/23-grammar.md
@@ -80,11 +80,16 @@ expression : logicalExpression ('?' assignment (':' assignment)?)? ;
logicalExpression : bitwiseExpression (('&&' | '||') logicalExpression)? ;
bitwiseExpression
- : comparisonExpression (('&' | '|' | '^') comparisonExpression)*
+ : equalityExpression (('&' | '|' | '^') equalityExpression)*
;
+equalityExpression : comparisonExpression (('==' | '!=') comparisonExpression)* ;
+
+// Compare adjacent operands once; stop after the first false comparison.
+// Keep one direction per chain; < and <= (or > and >=) may mix.
comparisonExpression
- : shiftExpression (('==' | '!=' | '<' | '<=' | '>' | '>=') shiftExpression)*
+ : shiftExpression (('<' | '<=') shiftExpression)*
+ | shiftExpression (('>' | '>=') shiftExpression)+
;
shiftExpression
diff --git a/docs/chapter23/README.ja.md b/docs/chapter23/README.ja.md
index 5c5427f5..62b69094 100644
--- a/docs/chapter23/README.ja.md
+++ b/docs/chapter23/README.ja.md
@@ -5,7 +5,7 @@
この文書は [原文](README.md) の日本語訳です。
[前の章: 第22章](../chapter22/README.ja.md) |
-[次の章: 第24章](../chapter24/README.ja.md)
+[次の章: 第24章](../chapter24a/README.ja.md)
この章では *メソッド* を追加します。構造体内で定義し、隠れた `self` 引数を取り、構造体のフィールドへアクセスできる関数です。文字列のようなクラスの `indexOf` メソッドを示します。
diff --git a/docs/chapter23/README.md b/docs/chapter23/README.md
index fac74770..b91dc0b1 100644
--- a/docs/chapter23/README.md
+++ b/docs/chapter23/README.md
@@ -3,7 +3,7 @@
English | [日本語](README.ja.md)
[Previous: Chapter 22](../chapter22/README.md) |
-[Next: Chapter 24](../chapter24/README.md)
+[Next: Chapter 24a](../chapter24a/README.md)
In this chapter we add *methods*, functions defined in structs which take a
hidden `self` argument and can access the struct fields. Here is an
@@ -53,6 +53,18 @@ You can also read [this chapter](https://github.com/SeaOfNodes/Simple/tree/linea
Here is the [complete language grammar](23-grammar.md) for this chapter.
+## Chained comparisons
+
+`lo <= x < hi` compares adjacent values and evaluates `x` only once. If the
+first comparison fails, the later operand is not evaluated. This uses the
+same control and scope merges as short-circuit expressions; it does not need
+SCCP. For example, `10 < 30 < 20` is false, and `0 < 2 <= 2` is true.
+
+A chain must keep one direction, but may mix strict and inclusive tests:
+`a < b <= c` and `a >= b > c` are allowed; `a < b > c` is rejected. Equality
+has lower precedence and does not join a chain. Parentheses can still make
+the result of one comparison an operand of another.
+
## Why Cyclic Types?
Cyclic types give us a sharper analysis than the alternative, and thus admit