Playground · Language guide · Examples · Grammar
BarkScript is a programming language written in dog commands. It has a real lexer, parser,
type checker and compiler, and it turns .bark files into plain, readable JavaScript.
What if a dog invented JavaScript? Roughly this:
sit dog = "Rover"
sit treats = 3
woof "Who's a good boy?"
fetch giveTreat()
if treats > 0
woof "Here you go"
treats = treats - 1
otherwise
woof "No more treats"
end
end
again 3
come here giveTreat()
end
play dead
bark compile turns that into:
let dog = "Rover";
let treats = 3;
console.log("Who's a good boy?");
function giveTreat() {
if (treats > 0) {
console.log("Here you go");
treats = treats - 1;
} else {
console.log("No more treats");
}
}
for (let i = 0; i < 3; i++) {
giveTreat();
}
process.exit(0);npm install -g barkscript
bark run hello.barkOr without installing: npx barkscript run hello.bark. Needs Node.js 20 or newer.
| BarkScript | Means | BarkScript | Means | |
|---|---|---|---|---|
woof |
again |
loop | ||
sit |
variable | no |
break | |
stay |
constant | leave it |
continue | |
fetch |
function | wait |
delay | |
come here |
call | beg |
read input | |
drop it |
return | play dead |
exit | |
if / otherwise |
if / else | end |
end a block | |
good boy |
true | bad dog |
false | |
empty bowl |
null | and or not |
logic | |
treats.bury |
save | treats.grab / treats.eat |
load / delete |
Strings interpolate ("Hi {name}"), lists and objects are JavaScript's, and JavaScript
globals like Math and JSON just work. The language guide covers all of
it in about ten minutes.
The compiler checks your whole program before it runs a line of it.
dog.bark:12
11 | sit treats = 3
12 | fetch
| ^^^^^
You told Rover to FETCH,
but never told him what to fetch.
hint: name the fetch, like `fetch giveTreat()`
Typos get suggestions, stay can't be reassigned, blocks that never end are caught, and
JavaScript habits (return, &&, true, ;) get pointed at their BarkScript words.
No install, no build step. Load the script, then write BarkScript in your HTML:
<script src="https://barkscript.com/barkscript.min.js"></script>
<script type="text/barkscript">
woof "Hello from the page"
</script>Details in docs/BROWSER.md.
bark run guess.bark # compile and run
bark compile fizzbuzz.bark # write fizzbuzz.js next to it
bark compile fizzbuzz.bark --stdout # or print it
bark check *.bark # just look for problemsMore in docs/CLI.md, including the JavaScript API.
hello · treats · fizzbuzz · fibonacci · guess the number · walk (async) · kennel (lists, objects, closures)
The biggest one is the website. Every page of barkscript.com is generated by website/site.bark.
| Language guide | Every feature, with examples the test suite runs |
| Grammar | The formal EBNF grammar and semantics |
| On a web page | The browser build: script tags, data-output, the BarkScript global |
| CLI and API | bark run, compile, check, and using the compiler from code |
| VS Code | Syntax highlighting (a TextMate grammar, so it works elsewhere too) |
| Contributing | How the compiler is built and how to add to it |
MIT
P.S. This was an inside joke about my dog working with me in the office, but if you wanna use it, go for it!