# Ada 外部老程序语料（10 个）

口径见上级 [`../README.md`](../README.md)。**判据只有一条：编不编得过。**

- 编译器：`vmlcli --lang ada`（Ada 子集：过程/函数/数组/控制流/字符串/浮点）
- 三条硬口径（`scripts/compat-external-lint.py --dir .`）：**10 个文件 0 违规**
- 结果：**通过 3 / 失败 7**

## 清单

| 文件名 | 类别 | 来源 URL | 许可 | 行数 | 编译 | 第一条错误 |
|:--|:--|:--|:--|--:|:--:|:--|
| `gcd.adb` | 数值/算术 | https://rosettacode.org/wiki/Greatest_common_divisor | GFDL 1.2 | 21 | ✅ | — |
| `fibonacci.adb` | 数值/算术 | https://rosettacode.org/wiki/Fibonacci_sequence | GFDL 1.2 | 20 | ✅ | — |
| `ackermann.adb` | 递归 | https://rosettacode.org/wiki/Ackermann_function | GFDL 1.2 | 21 | ✅ | — |
| `reverse_string.adb` | 字符串 | https://rosettacode.org/wiki/Reverse_a_string | GFDL 1.2 | 14 | ❌ | `reverse_string.adb:5:23: error: 期望 SEMICOLON，实际得到 LPAREN` |
| `run_length_encoding.adb` | 字符串 | https://rosettacode.org/wiki/Run-length_encoding | GFDL 1.2 | 48 | ❌ | `run_length_encoding.adb:13:42: error: 期望一个表达式，实际得到 THEN` |
| `selection_sort.adb` | 数组 | https://rosettacode.org/wiki/Sorting_algorithms/Selection_sort | GFDL 1.2 | 31 | ❌ | `selection_sort.adb:5:33: error: 期望 INTEGER_LIT，实际得到 IDENTIFIER` |
| `sieve_of_eratosthenes.adb` | 数组 | https://rosettacode.org/wiki/Sieve_of_Eratosthenes | GFDL 1.2 | 26 | ❌ | `sieve_of_eratosthenes.adb:6:11: error: 期望 IDENTIFIER，实际得到 ARRAY` |
| `hanoi.adb` | 递归/控制流 | https://rosettacode.org/wiki/Towers_of_Hanoi | GFDL 1.2 | 15 | ❌ | `hanoi.adb:4:17: error: 期望 IDENTIFIER，实际得到 LPAREN` |
| `one_hundred_doors.adb` | 模拟 | https://rosettacode.org/wiki/100_doors | GFDL 1.2 | 22 | ❌ | `one_hundred_doors.adb:4:24: error: 期望 IDENTIFIER，实际得到 LPAREN` |
| `conways_game_of_life.adb` | 模拟 | https://rosettacode.org/wiki/Conway%27s_Game_of_Life | GFDL 1.2 | 56 | ❌ | `conways_game_of_life.adb:4:28: error: 期望 SEMICOLON，实际得到 RANGE` |

> 许可：Rosetta Code 全站内容按 **GNU Free Documentation License 1.2** 发布
> （见 https://rosettacode.org/wiki/Rosetta_Code:Copyrights ）。逐条贡献者另有署名，
> 收进仓库前按上级 README「许可」一节由人来定。

## 逐条失败根因（按错误行定位）

| 文件 | 出错行 | 根因 |
|:--|:--|:--|
| `hanoi.adb` | `type Pegs is (Left, Center, Right);` | **枚举类型** `type X is (A, B, C);` 不支持（`is` 后只认 `array`/子类型名） |
| `one_hundred_doors.adb` | `type Door_State is (Closed, Open);` | 同上：枚举类型 |
| `selection_sort.adb` | `type Integer_Array is array (Positive range <>) of Integer;` | **无约束数组类型**：下标只接受整数字面量界（`1 .. N`），`Positive range <>` 里的子类型名被当成整数界 |
| `conways_game_of_life.adb` | `SUBTYPE Cell IS Natural RANGE 0 .. 1;` | **带范围约束的子类型** `subtype X is T range L .. H;` 不支持 |
| `sieve_of_eratosthenes.adb` | `Prime: array(1 .. Last) of Boolean := …;` | **匿名数组类型**（声明里直接写 `array(…) of`）不支持，要先 `type T is array(…) of …;` |
| `reverse_string.adb` | `Result : String (Item'Range);` | **不定长字符串结果** `String (Item'Range)` 不支持（`String` 只能当指针，不能当带约束的值） |
| `run_length_encoding.adb` | `while Index <= Data'Last and then Code = Data (Index) loop` | **短路布尔运算 `and then` / `or else`** 不支持 |

## 两个观察

1. **这批失败全是"解析器不认识某种声明/运算"，没有一条走到代码生成或链接** ——
   说明卡点在**语法覆盖面**（类型系统），不在后端。
   （旁证：Rosetta Code 的 `Palindrome_detection` 里那个不写 `Result` 缓冲、直接用
   形参 `Text` 的函数变体，是**唯一一条**能走进 CodeGen 的失败样本，报
   `未声明的函数 'text'` —— 形参在函数体里没被登记成变量。）
2. **通过的 3 条跑出来的结果都对**（`gcd` 5/5/1、`fibonacci` 0..10、`ackermann` 4×7 全表），
   说明「整数 + while/for + if/elsif + mod/rem + 函数/过程调用 + `Integer'Image`」
   这条最短路是通的。

## 复现

```bash
cd /Users/shitanyu/Desktop/source/mycoder/my-coder
python3 scripts/compat-external-lint.py --dir third_party/vml/compat-corpus/external/ada
bash scripts/vml-compat-external.sh ada
```

## 与本目录文件的差异说明

- `sieve_of_eratosthenes.adb`：原 Rosetta 条目用 `Ada.Command_Line.Argument(1)` 取上界，
  **改了 1 行**（`Last: constant Positive := 100;`）+ 去掉 `with Ada.Command_Line;`，
  目的是让它**自包含**（上级 README 要求）。**未做任何"迁就子集"的改写**。
- 其余 9 条**逐字照抄** Rosetta Code 的 Ada 段落，未改一个字符。
