Nojotalk Scripting Language

[ Home ]

Game designers use Nojotalk as their scripting language. Nojotalk is based on the subset of JavaScript described in the book JavaScript: The Good Parts, by Douglas Crockford. Nojotalk differs from JavaScript only in its radically simplified syntax, in which parentheses are used for all grouping (except string literals are delimited with single or double quotes; square brackets and semicolons/commas are not used). Comments start with // or are delimited with brace brackets.

Debugger

An object consists of a list of zero or more pairs, separated by white space and enclosed in parentheses. The open parenthesis is followed by the keyword pairs. Each pair is enclosed in parentheses and consists of a string literal followed by a value. A value can be one of the following: an object, an array, a string literal, a number, or a constant keyword. An object having a "tag" pair equal to "script" can also have a "text" pair with a value consisting of a Nojotalk block (zero or more statements), which is always enclosed in parentheses. The value of a "type" pair is often a widget type. Examples of widget types include "button" and "checkbox". If the value of a "tag" pair is a string literal beginning with a forward slash, then that object serves to terminate the matching object without the forward slash (which lacks a "text" pair).

Code is an Array of Tokens

Nojotalk code is represented in memory as an array of tokens (Nojotalk is implemented in Python). Every pair of parentheses in Nojotalk code corresponds to an array of tokens and/or other arrays. If the open parenthesis is followed by a token, instead of another open parenthesis, then the first element of the corresponding array contains that token in the form of a token object. If instead of a token the open parenthesis is followed by another open parenthesis, then the first element of the corresponding array contains another array. Token objects can be either keywords/operators, constants (literals), or identifiers. Each token object contains a token type (keyword/constant/identifier) and a data type (both integers). The data type is either the particular keyword/operator or data type of the constant/identifier. Token objects which are constants/identifiers also have a token value. The token value is either the value of the constant or an object reference (an object embedded in the Nojotalk function/variable data structure).

Keyboard Aid

This optional feature enables hyphens, open parentheses, and close parentheses to be entered by typing semicolons, commas, and periods, respectively. When enabled, keyboard aid can be temporarily suppressed by using the Ctrl key in conjunction with typing semicolons, commas, and periods (no character substitution takes place). By convention, hyphens are used to separate words in multi-word identifiers, but semicolons are easier to type. Similarly, commas and periods are easier to type than parentheses.

Nojotalk Syntax

  • Non-terminal symbol: <symbol name>
  • Optional text in brackets: [ text ]
  • Repeats zero or more times: [ text ]...
  • Repeats one or more times: <symbol name>...
  • Pipe separates alternatives: opt1 | opt2
  • Comments in italics

No white space allowed between tokens:

<name>:

  • <letter> [<idchar>]...

<idchar>:

  • <letter>
  • <digit>
  • <underscore>
  • <hyphen>   each hyphen must be delimited with alphanumeric chars.

<num lit>:

  • <integer> [<fraction>] [<exponent>]

<integer>:

  • 0
  • [<hyphen>] <any digit except 0> [<digit>]...

<fraction>:

  • <dot> [<digit>]...

<exponent>:

  • <e> [<sign>] <digit>...

<e>:

  • e | E

<sign>:

  • + | -

<string lit>:

  • " [<esc or non-quote>]... [<non-quote>] "
  • " [<esc or non-apostrophe>]... [<non-apostrophe>] "

<non-quote>:

  • any Unicode character except " and \ and control character

<non-apostrophe>:

  • any Unicode character except ' and \ and control character

<esc or non-quote>:

  • <escaped character>
  • <non-quote>

<esc or non-apostrophe>:

  • <escaped character>
  • <non-apostrophe>

<escaped character>:

  • \" double quote
  • \' single quote
  • \\ backslash
  • \/ slash
  • \b backspace
  • \f formfeed
  • \n new line
  • \r carriage return
  • \t tab
  • \u <4 hexadecimal digits>

<regexp lit>:

  • / <regexp choice> / [ g ] [ i ] [ m ]

White space occurs between tokens (parentheses need no adjacent white space):

<var stmt>:

  • ( var <name> [<expr>] )
  • ( var ( <name or pair>... ))

<name or pair>:

  • <name>
  • ( <name><expr> )

<stmt>:

  • <expr stmt>
  • <disruptive stmt>
  • <try stmt>
  • <if stmt>
  • <switch stmt>
  • <while stmt>
  • <for stmt>
  • <do stmt>

<disruptive stmt>:

  • <break stmt>
  • <return stmt>
  • <throw stmt>

<block>:

  • ( [<stmt>]... )

<if stmt>:

  • ( if <expr><block> [ elif <expr><block>]... [ else <block>] )

<switch stmt>:

  • ( switch <expr><case clause>... [ default <block> ] )

<case clause>:

  • ( <expr><block> )
  • ( case ( <expr>... ) <block> )

<while stmt>:

  • ( while <expr> do <block> )

<for stmt>:

  • ( for ( <initialization><condition><increment> ) <block> )
  • ( for <name> in <expr><block> )

<initialization>:
<increment>:

  • ( )
  • <expr stmt>

<condition>:

  • ( )
  • <expr>

<do stmt>:

  • ( do <block> while <expr> )

<try stmt>:

  • ( try <block> catch <name><block> )

<throw stmt>:

  • ( throw <expr> )

<return stmt>:

  • return
  • ( return <expr> )

<break stmt>:

  • break

<expr stmt>:

  • <asst stmt>
  • <invocation>
  • ( delete <expr><expr> )

<asst stmt>:

  • ( <asst op><name><expr> )
  • ( <asst op><refinement><expr> )

<asst op>:

  • = | += | -=

<refinement>:

  • ( : <expr><expr>... )

<invocation>:

  • ( <func name> [<expr>]... )
  • ( $ <expr>... )

<expr>:

  • <literal>
  • <name>
  • ( <prefix op><expr> )
  • ( <bin op><expr><expr> )
  • ( <multi op><expr><expr>... )
  • ( ? <expr><expr><expr> )
  • <invocation>
  • <refinement>
  • ( new <invocation> )
  • ( delete <expr><expr> )

<prefix op>:

  • typeof
  • + to number
  • - negate
  • not

<bin op>:

  • / | % | - | >= | <= | > | < | === | !==

<multi op>:

  • * | + | or | and

<literal>:

  • <num lit>
  • <string lit>
  • <obj lit>
  • <array lit>
  • <func lit>
  • <regexp lit>

<obj lit>:

  • ( pairs [ ( <name or string><expr> ) ]... )

<array lit>:

  • ( list [<expr>]... )

<func lit>:

  • ( func [<name>] <parms><body> )

<parms>:

  • ( [<name>]... )

<body>:

  • ( [<var stmt>]... [<stmt>]... )
[ Back to Top ]