DEV Community

SUNGMIN BAE
SUNGMIN BAE

Posted on

I built a numpad-only language for PLC programming

The Problem

PLC programming in 2025 still looks like this:

  1. Open a 2GB proprietary IDE
  2. Click "New Rung"
  3. Drag a NO contact from a palette
  4. Click to place it
  5. Type the address in a popup
  6. Repeat 500 times

For X1 AND X2 → Y50, that's 12 mouse clicks.

The Solution

1 2 = 50
Enter fullscreen mode Exit fullscreen mode

One line. 8 characters. Zero clicks.

I built BNS Lang — a minimal DSL where numbers are I/O addresses and symbols are logic operators. The entire grammar is 15 lines of BNF.

How it works

Numbers     = I/O addresses
Space       = AND (series)
|           = OR (parallel)
-           = NOT (normally closed)
=           = output coil
Enter fullscreen mode Exit fullscreen mode

Self-holding motor circuit

Every PLC engineer writes this 100 times a year:

1 -2 | 100 = 100
Enter fullscreen mode Exit fullscreen mode

This compiles to:

──┤ X1 ├──┤/X2 ├──┬──( Y100 )
                   │
──┤Y100 ├──────────┘
Enter fullscreen mode Exit fullscreen mode

And outputs IEC 61131-3 Structured Text:

Y100 := (X1 AND NOT X2) OR Y100;
Enter fullscreen mode Exit fullscreen mode

Traffic light controller

T302 -T300 = 100       # Green phase
T300 -T301 = 101       # Yellow phase
T301 -T302 = 102       # Red phase
100 = T300 5000        # Green timer 5s
101 = T301 2000        # Yellow timer 2s
102 = T302 5000        # Red timer 5s
Enter fullscreen mode Exit fullscreen mode

Six lines. Complete state machine.

AI-native: MCP server for Cursor / Claude Code

This is where it gets interesting. BNS Lang ships with an MCP server, so you can do this inside Cursor:

You: "Make a conveyor controller with emergency stop"

Cursor: [generates BNS] → [validates] → [compiles to ST] → [shows ladder diagram]
Enter fullscreen mode Exit fullscreen mode

Natural language → BNS Lang → IEC 61131-3, without leaving your editor.

The .cursorrules file is included — clone the repo and Cursor already knows the syntax.

Why LLMs + BNS Lang?

Traditional ladder logic is visual (GUI layouts, not text). Structured Text is text-based but verbose — LLMs frequently mess up variable declarations and types.

BNS Lang is pure logic, zero boilerplate. An LLM only needs to know 5 rules. The compiler handles everything else.

Target PLCs

Target Status
LS Electric XGT ✅ Production
IEC 61131-3 Generic ✅ Production
Inovance H5U/H3U 🚧 Beta
Siemens S7 📋 Planned
Mitsubishi MELSEC 📋 Planned

Why I built this

The industrial automation market is $200B+. PLC programming is a bottleneck. Most PLC engineers are aging out with no replacements.

AI-generated PLC code could be the bridge — but only if there's a language simple enough for AI to reliably produce. BNS Lang is that language.

MIT licensed. PRs welcome.

GitHub logo BAESY2 / bns-lang-

Write PLC ladder logic with just a numpad. IEC 61131-3 DSL + MCP for Cursor.

 ██████╗ ███╗   ██╗███████╗    ██╗      █████╗ ███╗   ██╗ ██████╗
 ██╔══██╗████╗  ██║██╔════╝    ██║     ██╔══██╗████╗  ██║██╔════╝ 
 ██████╔╝██╔██╗ ██║███████╗    ██║     ███████║██╔██╗ ██║██║  ███╗
 ██╔══██╗██║╚██╗██║╚════██║    ██║     ██╔══██║██║╚██╗██║██║   ██║
 ██████╔╝██║ ╚████║███████║    ███████╗██║  ██║██║ ╚████║╚██████╔╝
 ╚═════╝ ╚═╝  ╚═══╝╚══════╝    ╚══════╝╚═╝  ╚═╝╚═╝  ╚═══╝ ╚═════╝ 

Write PLC ladder logic with just a numpad.

A minimal DSL that compiles to IEC 61131-3 ladder diagrams.
No IDE needed. No mouse clicking. Just type numbers → get rungs.

License: MIT IEC 61131-3 PLC MCP PRs Welcome

Quick Start · Syntax · Examples · Why? · Roadmap


⚡ 3 Seconds to Understand

Traditional PLC programming requires a GUI IDE, mouse-clicking contacts onto rungs, and navigating nested menus. BNS Lang lets you type it.

         BNS Lang                          Ladder Diagram
                                     
    1 2 + 3 = 50                     ──┤ X1 ├──┤ X2 ├──┬──┤ X3 ├──── ( Y50 )
                                                        │
    1 2 | 4 = 50                     ──┤ X1 ├──┤ X2 ├──┤ X4 ├────── ( Y50 )

That's it. Numbers are I/O addresses. + is series (AND). | is…

Top comments (0)