Most people approach Jeebox from a "coder's viewpoint", or a "knowledge representation" viewpoint. I feel there is a natural and good reason for these two separate viewpoints.
Learn Jeebox Syntax
For this reason I'll explain "Jeebox for code" on this page, and "Jeebox for the real world" on the DRS page. But really, there is only one Jeebox.
Jeebox has two contexts. Argument context, and list context.
This affects parsing. The flow of things is...
Whats a "temporal statement"? Thats my name for commands like "return", "if", "do", "class", etc, that come at the start of a line.
Argument Context Syntax
Argument context, can contain temporal statements. This differs from lists and arrays, which can't.
You can easily construct wierd syntax, like:
but it's best to avoid doing things like that.
The goal of the rules is to allow the kind of syntax that has become natural to modern computer programmers.
This basically parses, as you would expect.
Brackets, and lists, have the same "parse context". The only difference is that a list contains one or more "end-of-line".
Lists are very expressive.
Above is a list with 3 items.
Above is a list with 1 item. Just like in Python, actually.
Above is a list where we have a string index "a" and a value of a "thing" named "b".
Above, the index/value pairs don't have to be used on every item, you are free to mix and match as you like.
Despite this "free-form", this syntax can unambiguously express any list, or normal bracket.
Arrays have the same meaning as lists, they just use slightly different syntax.
Apart from the index being strings for lists, and objects for arrays, the meaning of lists and arrays is the same.
Object indexes let you use any expression for the index of an array:
Arrays don't need any "special rule" to express a list of 1 item, but lists do.
Jeebox basically does away with precedence, with one exception described in "temporal operators".
The reason for this, is that Jeebox's operators are extensible. You can add new operators as you like.
With no predefined operators, precedence is impossible. So we just abandon it entirely. This actually makes programs more predictable, because now you don't need to find some list of precedence rules, to figure out what comes first, you simply look at the order in which the operators appear.
"Temporal Operators" have a higher precedence than non-temporal operators. They begin with
#and can be any word...
"#until" and "#while" are temporal operators, and come first. This makes the above example, parse as you'd expect. While temporal operators are aimed for "knowledge representation" rather than code, actually you can use temporal operators to describe the code itself.
You can use any name for any operator, you like.
Inbuilt comparison operators.
|= >= <= > < !=|
Inbuilt arithmetic operators.
|∗ - + / >> << ^|
There are 4 unitary operators. They come before their parameter, and "bind" to their parameter more tightly than other operators. You can't add unitary operators.
All arithmetic operators and named operators (but not unitary or comparison operators) can be used in "+=" form, just like in C.
Units and numbers
Numbers can be in a few forms:
Units are extensible and quite fun:
Units start with a number and end with a letter. They are "read backwards" to find the first digit from 0-9 or "_". That is why 0FEFF_x will parse as a number of value "0FEFF" in the "x" unit. (Basically just an easy way to write hex in Jeebox).
Units can be utf-8.
Jeebox strings are pretty powerful and flexible... mostly because I was fed up with other languages having bad string support. You can embed Jeebox code in strings.
Letters can be escaped, using "escape codes" or "character references":
Right there... we have a few ways of representing Unicode characters (codepoints). "Ĵ" is Hexadecimal. "ⓧ" is decimal.
Jeebox also lets you write raw bytes... by using "\". To enter Unicode using raw bytes, it must be valid UTF-8 (like
\C3\AA\C6\81). But you might want to write something else than Unicode... so you don't have to write valid UTF-8.
Jeebox accepts Unicode directly... like "(ĴëêƁoⓧ)" so you don't need character references or anything special to store Unicode.
More conventional syntax
Declarations and types
Jeebox uses |bars| to declare things.
The type can be omitted. This allows for type inferencing.
Typecasting uses ||, but after the object's name.
Temporal statements are easily the most flexible part of Jeebox!
Temporal statements, are words that start on a line, within "Argument context".
However, there are two exceptions:
example temporal statements:
Temporal statements, use a special rule to make code parse more naturally... Any word after an argument, is a nested temporal statement. Meaning you can do this:
Finally, using a colon ":", it is possible to put temporal statements, into places that a "thing" (number/object/etc) would normally go. This can be used to get a temporal statement as a thing.
Jeebox syntax is powerfully expressive and fun-to-use. Jeebox was designed so that all it's features work together in harmony.
Next: Read about the Jeebox AST.