Skip to main content

FLOW-MATIC Interpreter - Grace Hopper's 1957 Business Language

Project description

FLOW-MATIC: Grace Hopper's Business Language (1957)

PyPI version Python 3.8+ License: MIT

"It is much easier for most people to write an English statement than it is to use symbols." — Grace Hopper, 1952

Part of The Ian Index — Preserving computing history.

What is FLOW-MATIC?

FLOW-MATIC was the first English-like programming language, developed by Grace Hopper and her team at Remington Rand from 1955-1959. It ran on the UNIVAC I and UNIVAC II computers and was the direct ancestor of COBOL.

This implementation faithfully recreates FLOW-MATIC's syntax and semantics based on the original U1518 FLOW-MATIC Programming System manual (1958).

Installation

pip install flowmatic

Quick Start

# Run a program
flowmatic examples/invoice_generator.flowmatic

# Run all demos
flowmatic --demo

# List available examples
flowmatic --list

# Or use Python directly
python -c "from flowmatic import run_file; run_file('program.flowmatic')"

Example Programs

Program Description
invoice_generator.flowmatic Generates invoices by matching orders with product catalog
payroll.flowmatic Calculates employee pay with overtime and deductions
inventory_reorder.flowmatic Checks stock levels and generates purchase orders
set_operation_demo.flowmatic Demonstrates runtime flow modification (feature COBOL killed!)
xi_sections_demo.flowmatic Shows X-I machine code sections (another lost feature)
block_integrity.flowmatic Language-level data integrity checking

FLOW-MATIC Syntax

File Definitions (Operation 0)

(0)  INPUT INVENTORY FILE-A PRICE-LIST FILE-B ;
     OUTPUT INVOICE FILE-C ;
     HSP D .
  • INPUT - Define input files with single-letter aliases
  • OUTPUT - Define output files
  • HSP - High-Speed Printer output

Operations

Each operation is numbered and contains statements:

(1)  READ-ITEM A ;
     IF END OF DATA GO TO OPERATION 10 .

(2)  COMPARE PRODUCT-NO (A) WITH PRODUCT-NO (B) ;
     IF EQUAL GO TO OPERATION 4 ;
     IF LESS GO TO OPERATION 3 ;
     OTHERWISE GO TO OPERATION 5 .

Available Statements

Statement Description
READ-ITEM A Read next record from file A
WRITE-ITEM C Write current record to file C
PRINT-ITEM D Print to high-speed printer
TRANSFER A TO C Copy entire record from A to C
MOVE value TO field (C) Move value to a field
COMPARE field (A) WITH field (B) Compare two fields
IF EQUAL GO TO OPERATION n Conditional jump
IF GREATER GO TO OPERATION n Conditional jump
IF LESS GO TO OPERATION n Conditional jump
OTHERWISE GO TO OPERATION n Default branch
JUMP TO OPERATION n Unconditional jump
IF END OF DATA GO TO OPERATION n End-of-file check
MULTIPLY a BY b GIVING c Multiplication
ADD a TO b Addition
SUBTRACT a FROM b Subtraction
DIVIDE a BY b GIVING c Division
SET OPERATION n TO GO TO OPERATION m Runtime flow modification!
TEST field AGAINST value Test a field value
EXECUTE OPERATION n [THROUGH m] Subroutine call! (from U1518)
REWIND A Rewind file for multi-pass (from U1518)
CLOSE-OUT FILES C Close output files
STOP End program

Features COBOL Killed

1. SET OPERATION (Runtime Flow Modification)

FLOW-MATIC:

SET OPERATION 9 TO GO TO OPERATION 2

This one English sentence changes where operation 9 jumps to at runtime.

Modern equivalent requires:

  • Interface definition
  • Concrete strategy classes
  • Context class
  • Factory or dependency injection

COBOL had ALTER which did something similar, but it was deprecated and removed.

2. X-I Sections (Inline Machine Code)

FLOW-MATIC allowed embedding machine code for performance-critical sections:

* In original FLOW-MATIC:
X-I  A000  ; Load from input area
X-I  M010  ; Multiply instruction
X-I  W000  ; Store to working storage

The relative addressing (A000, W000, M000) kept code portable between UNIVAC models.

COBOL removed this to achieve "machine independence" — creating a 39-year gap before FFI/JNI/ctypes reinvented the concept in 1996.

3. Single-Letter File Aliases

FLOW-MATIC:

COMPARE PRODUCT-NO (A) WITH PRODUCT-NO (B)
TRANSFER A TO C

COBOL:

COMPARE PRODUCT-NUMBER OF INVENTORY-MASTER-FILE
    WITH PRODUCT-NUMBER OF PRICE-LIST-FILE
MOVE CORRESPONDING INVENTORY-MASTER-RECORD
    TO OUTPUT-INVOICE-RECORD

18 FLOW-MATIC operations became 50+ COBOL statements.

4. EXECUTE (Subroutine Mechanism!)

From U1518 page 92: "Performs designated operation or sequence of operations."

(5)  EXECUTE OPERATION 10 THROUGH OPERATION 12 .

This runs operations 10-12 as a subroutine, then returns to operation 6! A primitive but effective subroutine mechanism in 1958.

5. REWIND (Multi-Pass Processing)

From U1518 page 97: "Rewinds current reel of an input file."

(4)  REWIND A .
(5)  READ-ITEM A ; ...

This resets file A to the beginning, allowing multi-pass algorithms.

6. Language-Level Integrity Checking

FLOW-MATIC file definitions included:

BLK CT IND 000000000001   ; Enable block counting
BLK CT LOC 000000000001   ; Where count stored
END REEL SEN              ; End-of-reel sentinel
END FILE SEN              ; End-of-file sentinel

The language verified your data automatically. We now need external checksums, database transaction logs, and ETL validation code.

Historical Context

  • 1955: Grace Hopper begins development of FLOW-MATIC
  • 1957: FLOW-MATIC operational on UNIVAC I
  • 1958: U1518 manual published
  • 1959: CODASYL committee formed (includes Hopper)
  • 1960: COBOL released, based heavily on FLOW-MATIC
  • 1960+: FLOW-MATIC features gradually dropped from COBOL

Project Structure

flowmatic/
├── README.md                    # This file
├── flowmatic_parser.py          # FLOW-MATIC interpreter (recursive descent)
├── run_flowmatic.py             # Command-line runner
├── demo.py                      # Quick demonstration
├── play_21.py                   # Interactive UNIVAC 21 card game
├── src/
│   ├── flowmatic.gram           # Formal BNF grammar
│   └── ast_nodes.py             # AST node classes
├── tests/
│   ├── run_tests.py             # Test runner
│   ├── 01_simple_transfer.flowmatic
│   ├── 02_arithmetic.flowmatic
│   ├── 03_compare_match.flowmatic
│   └── 04_set_operation.flowmatic
└── examples/
    ├── invoice_generator.flowmatic
    ├── payroll.flowmatic
    ├── inventory_reorder.flowmatic
    ├── set_operation_demo.flowmatic
    ├── xi_sections_demo.flowmatic
    ├── block_integrity.flowmatic
    └── univac_21.flowmatic      # Card game in authentic FLOW-MATIC

Running Tests

# Run all tests
python tests/run_tests.py

# Run with verbose output
python tests/run_tests.py --verbose

# Run specific test
python tests/run_tests.py 01

Grammar

The formal grammar is defined in src/flowmatic.gram. Key production rules:

Program         ::= Operation0 { Operation }
Operation       ::= '(' NUMBER ')' StatementList '.'
Statement       ::= ReadItem | WriteItem | Compare | IfCondition | Jump | Transfer | ...
FieldRef        ::= IDENTIFIER '(' LETTER ')'

Implementation Notes

Parser

The interpreter uses a recursive descent parser, following the same pattern as the Plankalkül implementation in this repository. Each statement type has a corresponding regex pattern that matches the statement and extracts its components.

Execution Model

FLOW-MATIC uses a memory-changing model where:

  1. Files are read into current records indexed by single-letter aliases (A, B, C...)
  2. Statements modify these records in place
  3. Records are written back to output files

SET OPERATION

The SET OPERATION feature stores modified jump targets in operation_targets dict. When a JUMP/GO TO executes, it checks if the current operation has an override target. This is how FLOW-MATIC achieved runtime polymorphism without objects or functions!

References

  • U1518 FLOW-MATIC Programming System (1958), Remington Rand UNIVAC
  • "The Education of a Computer" - Grace Hopper (1952)
  • COBOL-60 Report (1960)

License

Part of the Hopper Project - Preserving Grace Hopper's Legacy.


"The most dangerous words in the language: 'We have always done it this way.'" — Grace Hopper

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ian_flowmatic-1.0.0.tar.gz (36.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ian_flowmatic-1.0.0-py3-none-any.whl (38.8 kB view details)

Uploaded Python 3

File details

Details for the file ian_flowmatic-1.0.0.tar.gz.

File metadata

  • Download URL: ian_flowmatic-1.0.0.tar.gz
  • Upload date:
  • Size: 36.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for ian_flowmatic-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b298d797dce00af8688ad49a824cae72c9211c17655176a26d8d928b46f1392b
MD5 c2bd0c4707214428d8801faa2427b377
BLAKE2b-256 8e8a01a2c2a102ae72a63746c3089c513b1023e617e01bf119deb16a5f9c9f96

See more details on using hashes here.

File details

Details for the file ian_flowmatic-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ian_flowmatic-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 38.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for ian_flowmatic-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b7a26e569723d3652b10b6fc7f79d8ca9902f341f0644f5506768d8342a64a4
MD5 21c2fcb34c3b83357b5980500e892d70
BLAKE2b-256 dd46c34a93fff071aa0189df10d8662fc6654157721d286b236f77c269e0dbb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page