Extracted the data-half of Pratt-style precedence parsing: the operator table format and lookup. The climbing loop stays per-language because the two canaries use opposite conventions (lua: higher prec = tighter; prolog: lower prec = tighter, with xfx/xfy/yfx assoc tags) — forcing one shared loop adds callback indirection that obscures more than it shares. The brief's literal ask is "Grammar is a dict, not hardcoded cond" and that's what gets shared. Entry shape: (NAME PREC ASSOC). Three accessors: pratt-op-name / pratt-op-prec / pratt-op-assoc. One traversal: pratt-op-lookup. Ported lua/parser.sx — replaced 18-clause cond and the lua-binop-right? hardcoded `or` with a 15-entry lua-op-table, now queried via pratt-op-lookup. Ported prolog/parser.sx — pl-op-find (linear walk reimpl) deleted; pl-op-lookup wraps pratt-op-lookup; pl-token-op simplified to return the entry directly. Verification: - lua/test.sh: 185/185 = baseline. - prolog/conformance.sh: 590/590 = baseline (timestamp-only diff). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
8.7 KiB
8.7 KiB