ocaml: phase 5.1 array literals [|...|] + lis.ml baseline (LIS = 6)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 35s

Added parser support for OCaml array literal syntax:

  [| e1; e2; ...; en |]  -->  Array.of_list [e1; e2; ...; en]
  [||]                   -->  Array.of_list []

Desugaring keeps the array representation unchanged (ref-of-list)
since Array.of_list is a no-op constructor for that backing.

Tokenizer emits [, |, |, ] as separate ops; parser detects [ followed
by | and enters array-literal mode, terminating on |].

Baseline lis.ml exercises the syntax:

  let lis arr =
    let n = Array.length arr in
    let dp = Array.make n 1 in
    for i = 1 to n - 1 do
      for j = 0 to i - 1 do
        if arr.(j) < arr.(i) && dp.(j) + 1 > dp.(i) then
          dp.(i) <- dp.(j) + 1
      done
    done;
    let best = ref 0 in
    for i = 0 to n - 1 do
      if dp.(i) > !best then best := dp.(i)
    done;
    !best

  lis [|10; 22; 9; 33; 21; 50; 41; 60; 80|] = 6

137 baseline programs total.
This commit is contained in:
2026-05-10 03:41:19 +00:00
parent 76de0a20f8
commit 551ed44f7f
4 changed files with 70 additions and 0 deletions

View File

@@ -407,6 +407,16 @@ _Newest first._
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
'a tree`) with insert + in-order traversal. Tests parametric ADT,
recursive match, List.append, List.fold_left.
- 2026-05-10 Phase 5.1 — array literals + lis.ml baseline (longest
increasing subsequence on a 9-element array = 6). Added parser
support for `[| e1; e2; ...; en |]` syntax: desugars to
`Array.of_list [e1; e2; ...; en]` (which is `ref [...]`). Empty
`[||]` → `Array.of_list []`. Tokenizer leaves `[`, `|`, `|`, `]`
as separate ops; parser detects `[` followed by `|` to switch to
array-literal mode and consumes `|` then `]` at the end.
Used in `lis [|10; 22; 9; 33; 21; 50; 41; 60; 80|] = 6`.
Tests Array.length, .(i)<-/.(i), nested for + ref.
137 baseline programs total.
- 2026-05-10 Phase 5.1 — josephus.ml baseline (Josephus problem,
n=50 k=3 → survivor at position 11, 1-indexed). Uses the classic
recursive formula: J(1, k) = 0; J(n, k) = (J(n-1, k) + k) mod n.