Rapira (Рапира) – 苏联编程语言解释器
Rapira (Рапира) – Soviet programming language interpreter

原始链接: https://github.com/begoon/rapira

本项目是一个基于 TypeScript/Bun 开发的 **RAPIRA** 语言解释器,完全忠实于原版。RAPIRA 是一种苏联教育编程语言,诞生于 20 世纪 80 年代初,最初是为“阿加特”(Agat)微型计算机设计的。作为“学校”(Shkolnitsa)系统的一部分,该解释器保留了 1985 年的原版方言,涵盖俄语关键字、独特的复合数据类型(元组、集合和记录)以及专门的参数传递机制。 项目实现内容包括: * **核心引擎:** 包含词法分析器、语法分析器和树遍历求值器。 * **跨平台支持:** 可通过基于 Web 的在线环境(使用 CodeMirror 和 Web Workers)访问,或通过 `npx rapira` 使用命令行界面。 * **海龟绘图:** 完整实现了“绘图员”(Чертёжник)执行器,能够将输出渲染至 Canvas,或通过命令行导出为 SVG 文件。 * **开发工具:** 使用 Bun 构建的稳健测试套件、包含 1985 年原始规范的详尽文档,以及从简单输入输出到复杂几何循环的各类代码示例。 本项目采用 MIT 开源协议,旨在进行历史保护与教育用途,让用户能够在现代环境中运行苏联时期的遗留代码。欢迎访问在线演示:[https://begoon.github.io/rapira](https://begoon.github.io/rapira)。

这篇 Hacker News 帖子讨论了苏联开发的教育编程语言 **Rapira**。用户们分析了该语言的语法,指出其类似于 Pascal,但使用了俄语关键字。 讨论重点是一段计算阶乘的代码片段。参与者阐明了特定 Rapira 关键字的含义: * **КНЦ (KNC):** *Конец Цикла*(“循环结束”)的缩写,用作循环的结束定界符。 * **ВСЕ (VSE):** 通常用于表示程序块的结束,大致翻译为“全部结束”。 文中提供了一个修正后的阶乘代码版本,将原有的西里尔字母关键字替换为更标准的英语对应词(如 `DONE` 和 `END`),以更清晰地展示该语言的逻辑结构。总的来说,这次讨论突显了 Rapira 作为苏联计算机教育独特遗迹的地位。
相关文章

原文

A TypeScript / Bun interpreter for РАПИРА — the Soviet educational programming language designed in the early 1980s under G. A. Zvenigorodsky as part of the Школьница (Shkolnitsa) school computing system for the Агат (Agat) microcomputer.

▶ Try it in your browser: https://begoon.github.io/rapira

▶ Run it from your terminal: npx rapira factorial.rap

ФУНК ФАКТ (Н);
   ИМЕНА: Р;
   1 -> Р;
   ДЛЯ И ОТ 1 ДО Н ::
      Р * И -> Р
   ВСЕ
РЕЗ: Р
КНЦ;

ДЛЯ Н ОТ 0 ДО 6 ::
   ? "ФАКТ(", Н, ") = ", ФАКТ(Н)
ВСЕ;
  • Interpreter core (src/) — lexer, parser, tree-walking evaluator. Faithful to the 1985 Agat dialect: Russian-only keywords, case-insensitive identifiers, (* … *) block comments, ; statement separator, three compound types (tuples < >, sets <* *>, records <¤ ¤>), three-arrow procedure parameter scheme (name / name => / <=> name), trailing РЕЗ: for function results.
  • CLI (cli/) — rapira FILE.rap runs a program, rapira drops into a multi-line REPL, --svg PATH captures turtle graphics as SVG.
  • Web playground (web/) — vanilla HTML + CodeMirror 6 + Web Worker, light/dark theme, example selector loading from tests/snippets/. Build with bun build, output sits in docs/ ready for GitHub Pages. Live at https://begoon.github.io/rapira.
  • Snippet test pipeline (tests/snippets/) — .rap files diffed against sibling .expected.txt / .expected.svg on every run of bun test.
  • Чертёжник turtle — Soviet "Draftsman" executor exposed as ordinary Rapira procedures (ВПЕРЕД, НАЗАД, НАПРАВО, НАЛЕВО, ПЕРО_ВНИЗ, ПЕРО_ВВЕРХ, ДОМОЙ, В_ТОЧКУ, КУРС). Layered on top of the same GfxEvent stream as the documented graphics primitives (ЛИН, ПРЯМ, ОБЛ, etc.) so the CLI's SVG renderer and the playground's canvas renderer draw identical output.

The CLI ships as a self-contained Node bundle. With Node ≥ 18 you can run it without cloning:

npx rapira FILE.rap                           # run a program
npx rapira FILE.rap --svg out.svg             # capture turtle graphics
npx rapira                                    # multi-line REPL (Ctrl-D to quit)

Or install globally:

npm install -g rapira
rapira FILE.rap

For local development you'll want Bun (it runs the tests and the dev server natively):

bun install
bun test                                      # 129 tests across 9 files
bun run cli/index.ts examples/factorial.rap   # ФАКТ(0..7)
bun run dev                                   # playground on http://localhost:10000
bun run cli:build                             # bundle the CLI to dist/rapira.js

If you have just installed, you can use the recipe names — just test, just dev, just run examples/turtle_star.rap --svg star.svg, etc.

File What it shows
examples/hello.rap canonical ВЫВОД: "Здравствуй, мир!"
examples/factorial.rap ФУНК with trailing РЕЗ:, ДЛЯ … ОТ … ДО, integer math
examples/turtle_square.rap Чертёжник draws a square via ПОВТОР … РАЗА :: ВПЕРЕД(50); НАПРАВО(90)
examples/turtle_star.rap five-pointed star from a single repeat loop
examples/io_files.rap ОТКРЫТЬ … КАК, ВЫВОД В ФАЙЛ, ВВОД ИЗ ФАЙЛА ТЕКСТОВ, ЗАКРЫТЬ
examples/io_seek.rap ПОЗИЦИЯ Ф = N for random-access file reading
  • SPEC.md — the implementation contract: lexical structure, statements, operators, built-ins, what's done vs. honestly deferred.
  • RAPIRA.md — the canonical 1985 spec (Фг.00031-01 35 01) reformatted to Markdown from the agatcomp.ru KOI-8 source.
  • CLAUDE.md — onboarding notes for working on this codebase.

MIT © Alexander Demin

联系我们 contact @ memedata.com