cobol/demo/demo_std.cob · 1748 字节 · 下载原文
*> demo_std.cob —— COBOL 第一层:**标准输出**(std)
*> demo_std.cob -- COBOL layer 1: **standard output** (std)
*>
*> 只用 `DISPLAY` 与 `PERFORM VARYING` 循环,不碰 Crt / BGI / 宿主 `ui_*`。
*> Only DISPLAY and a PERFORM VARYING loop; no Crt / BGI / host ui_*.
*>
*> 跑法(桌面 vmlcli):
*> How to run (desktop vmlcli):
*> dotnet scripts/vmlcli/bin/Release/net10.0/vmlcli.dll Examples/cobol/demo/demo_std.cob
*>
*> 本前端的两个事实:
*> Two facts about this frontend:
*> ① 固定格式:第 1-6 列序号区、第 7 列指示符、代码从第 8 列起。
*> ① Fixed format: columns 1-6 are the sequence area, column 7 the indicator, code starts at column 8.
*> ② `DISPLAY` 的各个操作数**之间不加空格** —— 要空格就写进字面量。
*> ② DISPLAY does **not** insert spaces between operands -- put them in the literal yourself.
IDENTIFICATION DIVISION.
PROGRAM-ID. DEMO-STD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-I PIC S9(9) VALUE 0.
01 WS-SUM PIC S9(9) VALUE 0.
01 WS-PROD PIC S9(9) VALUE 0.
PROCEDURE DIVISION.
MAIN-PARA.
DISPLAY "=== COBOL 标准输出 demo ===".
DISPLAY "=== COBOL standard output demo ===".
DISPLAY "你好,世界 / hello, world".
DISPLAY "整数: " 42.
COMPUTE WS-PROD = 7 * 6.
DISPLAY "计算: 7 * 6 = " WS-PROD.
PERFORM VARYING WS-I FROM 1 BY 1 UNTIL WS-I > 10
ADD WS-I TO WS-SUM
END-PERFORM.
DISPLAY "循环求和: 1..10 = " WS-SUM.
STOP RUN.