Skip to content

autocorr/bok

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The Bok Language

Bok is a dynamic, concatenative programming language.

Bok Logo

Inspired by Joy, expressions manipulate a stack and are written in postfix notation without formal parameters. Lexical scoping is included, so that functions and variables can be grouped together into namespaces and closures, similar to Reforth. The Bok interpreter is written in Python and has a natural interface for calling Python objects and numpy arrays. Bok also comes with a full-featured REPL based on python-prompt-toolkit that includes autocompletion, syntax highlighting, multiline input, history, and a toolbar visualizing the stack.

Documentation on Bok may be found at ReadTheDocs, in the docs/ directory of this repository, and within the interpreter through the "help" function.

This is a hobby project designed for exploring programming language concepts and practices in software development. Because the runtime is written in pure Python, it is quite slow, but I suppose if you're using Python in the first place, what's another factor of twenty slower? :) Bok is named after the astronomer Bart Bok who was a pioneer in the study of the Milky Way and discoverer of Bok globules.

Installation

Install with pip by running:

pip install git+https://github.com/autocorr/bok.git

Or from the source with:

python setup.py install

Requirements

The interpreter makes use of Lark to generate a parser from an EBNF grammar, which for Bok is defined in grammar.g. prompt_toolkit and pygments are use to create the REPL and provide syntax highlighting, respectively. numpy is required for array literals and operations.

termcolor        ?
lark-parser      ?
prompt_toolkit   ?
pygments         ?
numpy            ?

Getting Started

$ python3 -m bok.repl
Bok 0.1, type '[<word>] help' for help.
Hit CTRL+D or type "exit" to quit.
 « # This is a comment
 « # Literals are pushed onto the stack and operated on by functions
 « "Hello, World!" println
Hello, World!
 « # Functions are defined with ( and )
 « ( think  "." print )
 « # Lists can be used to quote expresions
 « [think] 10 * eval
..........
 « ( lfive  [5 <=] [error] ["greater than five" println] if )
 « 4 lfive
Error: Raised an explicit error.
Stack dumped
 « # Numpy functions can be called with @
 « 5 @arange dup @cumsum stack
 # [type]    : [value]
 - ndarray   : [ 0  1  3  6 10]
 - ndarray   : [0 1 2 3 4]
 « + println
[ 0  2  5  9 14]
 « # Try this recursively in python!
 « ( factorial  [1 <] [drop 1] [dup 1 -] [*] linrec )
 « 10000 factorial println
2846259680917054518906413212119868890148051401702799230794179994274...
 « ^D
Do you really want to exit ([y]/n)? y

License

Copyright 2017, Brian Svoboda. This is free software and released under the GNU General Public License (version 3).

About

Bok: a concatenative, dynamic programming language

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published