Yarnball is an esoteric, stack-based programming language where every instruction reads sort of like a crochet pattern.
This is just a fun little side project and doesn't implement anything particularly novel. Yarnball programs are also fairly distinguishable from real crochet patterns. Otherwise, it is technically totally turing complete and pretty fun!
In Yarnball, operations are expressed using crochet terminology:
- ch (chain): Pushes a number onto the stack.
- pic (picot stitch): Pops a value and prints it as a character.
- yo (yarn over): Pops a value and prints it as a number.
- fo (finish off): Immediately halts program execution.
- stitch: Defines a reusable stitch pattern with
stitch name = (...), called by writing the name (oruse name). - repeat: Uses crochet-style blocks like
* ... * repeat while/untilor* ... * repeat 3. - AND MORE!
Other instructions manipulate the stack (e.g., dc, bob, hdc) or control the flow with loops (repeat) and conditionals (if).
To run a Yarnball program, use the command line. For example, to run the loop_counter.yarn example, execute:
make
./bin/yarnball examples/fib.yarnIf you prefer an interactive environment, start the REPL by running:
make replor
make # to build
./yarnball- cmd/main.go - The application entry point that initializes the Yarnball interpreter.
- pkg/evaluator - Implements the evaluator that processes Yarnball instructions.
- pkg/lexer - Responsible for lexing Yarnball source code into tokens.
- pkg/preprocessor/preprocessor.go - Preprocesses Yarnball source code, handling comments and whitespace and other aesthetic features of the language.
- pkg/parser/parser.go - Parses Yarnball source code into an abstract syntax tree (AST).
- docs/specification.md - Provides a detailed description of Yarnball’s instructions and behavior.
- examples/ - Contains sample Yarnball programs.
For a complete list of instructions and their behaviors, see the Yarnball Language Specification.