Introduction
Abstract
Syntax
License
Try It
# Slogo **Slogo** is a multi-agent programmable modelling environment for WebGL. Slogo provides an
API
and graphics framework for producing hardware-accelerated [turtle graphics](https://en.wikipedia.org/wiki/Turtle_graphics). _Note: The specification is still under development (pre-alpha)._ ## Mascot Slogo the slug ![Slogo the slug](./public/images/Slogo.png "Slogo the slug")
# Slogo Slogo is a [context-free grammar](https://en.wikipedia.org/wiki/Context_free_grammar) which leverages several existing Javascript libraries. Most notable of these libraries are: * [Jison](#jison) - a parser generator * [WebGL](#webgl) - a 3d graphics specification # Jison Slogo makes use of the [Jison](https://github.com/zaach/jison) Javascript library to simplify the process of defining a formal grammar. Jison takes a context-free grammar as input and produces a javascript file capable of parsing the specified grammar. Jison has modes to recognize languages described by the following grammars: * [LALR(1)](https://en.wikipedia.org/wiki/LALR_parser) * [LR(0)](https://en.wikipedia.org/wiki/LR_parser) * [SLR(1)](https://en.wikipedia.org/wiki/SLR_grammar) * [LR(1)](https://en.wikipedia.org/wiki/Canonical_LR_parser) _canonical LR parsers_ It also has a special mode for generating [LL(1)](https://en.wikipedia.org/wiki/LL_parser) parse tables > ## Bison > > Jison is modeled after [Bison](https://www.gnu.org/software/bison/) a parser > generator for the C progamming language. Bison is a parser generator that > converts an annotated context-free grammar into an LALR(1) or > [GLR](https://en.wikipedia.org/wiki/Glr_parser) parser for that grammar. # WebGL [WebGL](https://en.wikipedia.org/wiki/WebGL) is a recently released specification for modern browsers. It extends Javascript with the ability to generate 3D graphics. WebGL enables the creation of hardware-accelerated graphics as it communicates directly to the
GPU
on the host computer. Slogo makes use of Jison's ability to share the scope of a grammar with other parts of Javascript via the [`yy` variable](https://zaach.github.com/jison/docs/#sharing-scope). When a Slogo program is parsed it makes direct calls to WebGL via the Slogo graphics framework.
# Slogo Syntax Since Slogo compiles down to Javascript we borrow some functionality however the syntax is more like Lisp or Ruby. * [Math constants and functions](#mathconstantsandfunctions) * [Bitwise Operations](#bitwiseoperators) ## Math constants and functions The [Mozilla Developer Network documentation](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Math) for Javascript's Math object is worth looking up because we retain many of Javascript's math constants and functions. In regards to math the syntax of Slogo differs from Javascript in a number of ways. Namely one design consideration is that math functions are first class citizens in Slogo. The idea is that we're here to do math primarily and develop code secondarily. 1. In Slogo every math constant and function is directly available in the main namespace. PI # returns 3.141592653589793 max 2, 5, 3 # returns 5 2. Exponents have their own operator, the `^` operator 3 ^ 2 # returns 9 3. Factorials have their own operator, the `!` operator 4! # returns 4 * 3 * 2 * 1 4. The percent sign is used for percentages. 50% # returns 0.50 5. The [`modulus`](https://en.wikipedia.org/wiki/Modulo_operation) operator is still an operator but it has a longer name 3 mod 2 # returns 1 ## Bitwise operators We have four bitwise operators in Slogo. Bitwise operators allow for the comparison of boolean values. _Note: If you're familiar with how bitwise operations work in other languages feel free to skip to the next section._ ### And operator true and true # returns true true and false # returns false false and false # returns false false and true # returns false ### Or operator true or true # returns true true or false # returns true false or false # returns false false or true # returns true ### Xor operator (exclusive or) true xor true # returns false true xor false # returns true false xor false # returns false false xor true # returns true ### Not operator true not true # returns true true not false # returns false false not false # returns false false not true # returns true ## Blocks Blocks also known as functions exist in several different forms in Slogo we eschew the purely imperative approach of Javascript and provide some helpers for blocks. Blocks return their last statement by default. ### Block Examples to add |a, b| a + b end ### Anonymous Blocks to bind |func, scope| to func.apply(scope, arguments) end end ### Closures Closures build on the idea of blocks. Using closures we can bind the scope of a function to a particular object to run @motivation end more = { motivation: 'Yes!' } do run(more) # returns 'Yes!'
# License agreement Slogo is **free** software released under the MIT user license. The MIT user license is the most permissive license out there. > Copyright (c) 2011 Hans Oksendahl > > Permission is hereby granted, free of charge, to any person > obtaining a copy of this software and associated documentation > files (the "Software"), to deal in the Software without > restriction, including without limitation the rights to use, > copy, modify, merge, publish, distribute, sublicense, and/or sell > copies of the Software, and to permit persons to whom the > Software is furnished to do so, subject to the following > conditions: > > The above copyright notice and this permission notice shall be > included in all copies or substantial portions of the Software. > > You must not take yourself too seriously. > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES > OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND > NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT > HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, > WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR > OTHER DEALINGS IN THE SOFTWARE.
# Try Slogo Online The Slogo project includes a browser based
IDE
so you can get started creating your own Slogo simulations. Just [click here](./app.html) to get started.