Bns Lang
Write PLC ladder logic with just a numpad. IEC 61131-3 DSL + MCP for Cursor.
Ask AI about Bns Lang
Powered by Claude Β· Grounded in docs
I know everything about Bns Lang. Ask me about installation, configuration, usage, or troubleshooting.
0/500
Reviews
Documentation
βββββββ ββββ βββββββββββ βββ ββββββ ββββ βββ βββββββ
βββββββββββββ βββββββββββ βββ βββββββββββββ βββββββββββ
ββββββββββββββ βββββββββββ βββ ββββββββββββββ ββββββ ββββ
ββββββββββββββββββββββββββ βββ βββββββββββββββββββββ βββ
βββββββββββ ββββββββββββββ βββββββββββ ββββββ βββββββββββββββ
βββββββ βββ βββββββββββββ βββββββββββ ββββββ βββββ βββββββ
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.
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 parallel (OR). = is the output coil.
π Quick Start
# Install
npm install -g bns-lang
# Compile a .bns file to IEC 61131-3 structured text
bns compile program.bns -o output.st
# Or pipe directly
echo "1 2 + 3 = 50" | bns compile --stdout
Create program.bns:
# Motor start/stop circuit
# START(X1) AND NOT STOP(X2) OR HOLDING(Y10) β MOTOR(Y10)
# Contact 110 = Y10 (output as contact), coil 10 = Y10
1 -2 | 110 = 10
Compile:
$ bns compile program.bns --stdout
(* Generated by BNS Lang v2.0 *)
(* Motor start/stop circuit *)
PROGRAM MAIN
VAR
X1 AT %IX0.1 : BOOL;
X2 AT %IX0.2 : BOOL;
Y10 AT %QX1.10 : BOOL;
END_VAR
Y10 := ((X1 AND NOT X2) OR Y10);
END_PROGRAM
π Syntax
BNS Lang is designed to be typed entirely on a numpad + a few keys. The full grammar fits on a sticky note.
Contacts & Coils
| BNS | Meaning | Ladder | IEC 61131-3 |
|---|---|---|---|
1 | NO contact X1 | βββ€ X1 βββ | X1 |
-1 | NC contact X1 | βββ€/X1 βββ | NOT X1 |
= 50 | Output coil Y50 | ββ( Y50 ) | Y50 := |
=! 50 | Set (latch) | ββ(S Y50) | Y50 := TRUE |
=/ 50 | Reset (unlatch) | ββ(R Y50) | Y50 := FALSE |
Operators
| BNS | Meaning | Description |
|---|---|---|
(space) | Series (AND) | Contacts in series on same rung |
+ | Series (AND) | Explicit AND (same as space) |
| | Parallel (OR) | Branch β creates parallel path |
- | Negate (NOT) | Prefix β normally closed contact |
( ) | Group | Group contacts for complex logic |
Special
| BNS | Meaning |
|---|---|
300 5000 | Timer 300, 5000ms (address 300 = T300) |
C5 100 | Counter C5, preset 100 |
# | Comment (rest of line) |
--- | Rung separator (optional) |
Address Mapping
| Range | Type | Description |
|---|---|---|
0-99 | X (Input) | Digital inputs |
100-199 | Y (Output as contact) | Y0βY99 when used as contact (e.g. 110 = Y10) |
0-99 (coil) | Y (Output) | Digital outputs Y0βY99 |
200-299 | M (Internal) | Internal relays |
300-399 | T (Timer) | Timer contacts |
400-499 | C (Counter) | Counter contacts |
Address mapping is configurable per target PLC. Defaults match LS Electric XGT conventions.
π Examples
See the examples/ folder: 01-basics.bns, 02-self-holding.bns, 03-conveyor.bns, 04-traffic-light.bns, 05-wafer-transfer.bns.
π€ Why BNS Lang?
- One line. 8 characters. Zero clicks. for
X1 AND X2 β Y50:1 2 = 50 - Version control with Git. Review in PRs. Generate from scripts. Pipe through CI/CD.
- For PLC engineers, automation teams, educators, and AI/LLM developers.
π€ AI Integration (Cursor / Claude Code)
BNS Lang is the first PLC language designed for AI-native development. Two ways to use it:
Option 1: Cursor Rules (zero setup)
This repo includes .cursorrules β just open the project in Cursor and start talking:
You: "μ»¨λ² μ΄μ΄μ μΌμ κ°μ§λλ©΄ λͺ¨ν° λλ¦¬κ³ λΉμμ μ§ λλ₯΄λ©΄ λ©μΆκ² ν΄μ€"
Cursor: Here's the BNS Lang code:
# Conveyor motor control
# X1 = Sensor, X99 = E-Stop (NC), Y100 = Motor
1 -99 | 200 = 100 # Sensor AND NOT E-Stop, self-held (200 = M200)
99 =/ 100 # E-Stop resets motor
Works with any natural language β BNS Lang β IEC 61131-3 pipeline.
Option 2: MCP Server (full pipeline)
Connect BNS Lang as an MCP tool in Cursor or Claude Code:
Cursor β .cursor/mcp.json is included:
{
"mcpServers": {
"bns-lang": {
"command": "node",
"args": ["./src/mcp-server.js"]
}
}
}
Claude Code:
claude mcp add bns-lang node ./src/mcp-server.js
Now you get 4 tools directly in your AI coding assistant:
| Tool | What it does |
|---|---|
bns_compile | BNS β IEC 61131-3 Structured Text |
bns_check | Syntax validation |
bns_ladder | ASCII ladder diagram visualization |
bns_explain | Explain BNS code in natural language |
Full workflow in Cursor/Claude Code:
You: "Create a traffic light controller with 3 phases"
AI: [generates BNS code]
AI: [calls bns_check β validates]
AI: [calls bns_compile β outputs ST]
AI: [calls bns_ladder β shows diagram]
You: "Change green phase to 7 seconds"
AI: [modifies and recompiles]
Natural language β BNS Lang β Compile β Verify β Ladder diagram, all without leaving your editor.
ποΈ Architecture
.bns source Parser IR Code Generator Target
ββββββββββββ ββββββββββββββββ βββββββ ββββββββββββββββββββββ ββββββββββββ
β 1 2 = 50 β β β Tokenizer β β β β AST β β β LS Electric XGT ST β β β .st file β
ββββββββββββ β Parser β β β β IEC 61131-3 ST β β .prj β
ββββββββββββββββ β β β Ladder JSON (viz) β ββββββββββββ
βββββββ ββββββββββββββββββββββ
Target PLCs
| Target | Status | Output Format |
|---|---|---|
| LS Electric XGT | β Production | Structured Text (.st) |
| IEC 61131-3 Generic | β Production | Structured Text (.st) |
| Inovance H5U/H3U | π§ Beta | LiteST / XML (.prj) |
| Siemens S7 (TIA) | π Planned | SCL |
| Mitsubishi MELSEC | π Planned | Structured Text |
| Ladder JSON | β Production | JSON (for visualization) |
π οΈ CLI Reference
# Compile to structured text
bns compile input.bns -o output.st
# Compile with target PLC
bns compile input.bns --target xgt -o output.st
bns compile input.bns --target inovance -o output.prj
# Validate syntax only
bns check input.bns
# Output AST as JSON (for tooling/LLM integration)
bns ast input.bns --json
# Output ladder diagram as ASCII art
bns ladder input.bns
# REPL mode
bns repl
> 1 2 = 50
βββ€ X1 ββββ€ X2 βββ( Y50 )
>
π¦ Project Structure
bns-lang/
βββ .cursor/
β βββ mcp.json # Cursor MCP config (ready to use)
βββ .cursorrules # Cursor AI rules for BNS Lang generation
βββ .github/
β βββ workflows/ci.yml
β βββ FUNDING.yml
β βββ ISSUE_TEMPLATE/
βββ src/
β βββ tokenizer.js
β βββ parser.js
β βββ ir.js
β βββ generators/ (st.js, xgt.js, inovance.js, ladder-json.js, ascii.js)
β βββ mcp-server.js # MCP server for Cursor / Claude Code
β βββ cli.js
β βββ index.js
βββ examples/
βββ docs/ (SYNTAX.md, TARGETS.md, LLM-GUIDE.md)
βββ tests/
βββ package.json
βββ LICENSE
βββ README.md
πΊοΈ Roadmap
- Core parser & tokenizer
- IEC 61131-3 Structured Text output
- LS Electric XGT target
- ASCII ladder diagram output
- CLI tool
- Timer/Counter support
- Cursor Rules (.cursorrules)
- MCP Server (Cursor / Claude Code integration)
- Inovance H5U/H3U target (beta)
- Siemens S7 SCL target
- Function Block (FB) support
-
bns fmtβ auto-formatter -
bns simβ offline logic simulator - VS Code extension with syntax highlighting
- Web playground (try BNS Lang in browser)
- PLAIDE deep integration
π€ Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
git clone https://github.com/BAESY2/bns-lang.git
cd bns-lang
npm install
npm test
Good First Issues
- Add syntax highlighting for more editors
- Write examples for common PLC patterns
- Add a new target PLC code generator
- Improve error messages
π License
MIT β Use it in your commercial PLC projects. No strings attached.
BNS Lang is part of the ZENION industrial automation ecosystem.
Industrial automation deserves modern developer tooling.
