Your code is barking.
The world's least serious programming language.
BarkScript is a real language written in dog commands. A lexer, a parser, a type checker and a compiler turn it into plain JavaScript you could ship. Whether you should is between you and your dog.
npm install -g barkscript
Fifteen commands. You already know most of them.
Familiar dog commands, used for what they sound like. Strings, numbers, lists, objects and operators work the way they do in JavaScript, because underneath, that is what they are.
| BarkScript | JavaScript | Why |
|---|---|---|
woof "hi" | console.log("hi") | Dogs announce everything. |
sit treats = 3 | let treats = 3 | It sits there until you move it. |
stay name = "Rover" | const name = "Rover" | It does not move. Ever. |
fetch giveTreat() ... end | function giveTreat() {} | Goes off, does a job, comes back. |
come here giveTreat() | giveTreat() | You call, it comes. |
drop it treats | return treats | Hands back what it was holding. |
if ... otherwise ... end | if {} else {} | Dogs do not do conditionals, so these stay human. |
again 3 ... end | for (...) {} | Also again while, again each, again i from 1 to 10, again forever. |
no | break | Stops whatever is happening. |
leave it | continue | Skip this one, move on. |
wait 2 seconds | await sleep(2000) | Makes the fetch async for you. |
beg "Name? " | await ask("Name? ") | Asks for input, very nicely. |
play dead | process.exit(0) | The program stops moving. |
treats.bury("bones", 3) | localStorage.setItem("bones", 3) | Then treats.grab and treats.eat. Still there next visit. |
good boy, bad dog, empty bowl | true, false, null | good girl is also true. |
When something is wrong, Rover says so.
The compiler checks the whole program before any of it runs, and every error has a line, a column, and usually the fix. These are produced live by the same compiler the playground uses.
Put it straight in your HTML.
One script tag, then write BarkScript inside <script type="text/barkscript">. It compiles in the browser when the page loads. data-output also prints each woof into an element.
Install
Node.js 20 or newer. Then three steps.
-
Install the bark command
npm install -g barkscript -
Write
hello.barkwoof "Hello, world!"
-
Run it, or compile it to JavaScript
bark run hello.bark bark compile hello.bark # writes hello.js
Editor support: a TextMate grammar and VS Code extension live in editors/vscode.
Teach Rover a new trick.
BarkScript is MIT licensed and built in the open. The compiler is four small TypeScript files: lexer, parser, checker, code generator. Grammar changes start as an issue, so we can agree on the words first.
- Source on GitHubStar it so Rover feels seen.
- Contributing guideHow the compiler fits together.
- IssuesBugs, ideas, and new commands.
- The grammarThe EBNF the compiler follows.