GNTCFL

GNTCFL is a language with LISP-like syntax developed especially for GNTicker. Despite its resemblance to LISP, it is not a fully declarative programming language since it contains certain procedural elements.

A GNTCFL program is a set of function definitions that can be used as characteristic functions and predicates as well as user defined utility functions.

GNTCFL syntax
LISP-styled, the syntax of GNTCFL programs is very simple. It follows the BNF:

::= " ; ;..." ::= ...  ::= ...  ::= ( [ ...])  ::= | |  ::= if | for | and | or | let ::= | | | |  ::= #

Frame definitions, special forms, primitives and user-defined functions are described in details in the following sections.

GNTCFL semantics
As mentioned above, a GNTCFL program consists entirely of function definitions. As in functional languages there is a general rule for expression evaluating, which applies to all combinations except special forms. The semantics of special forms are specific for each of them and are described separately.

Let ( [ ...]) be an expression, where the supercombinator is not a special form. Evaluating the expression involves subsequent evaluation of the arguments, prior to the application of the supercombinator over their values. In terms of the functional programming the expression evaluations follow the so called applicative model. The following example includes only primitives and constants and demonstrates the process

(* 2 3 (- 11 (+ 1 1) (/10 5))) -> (* 2 3 (- 11 2 (/10 5)))  -> (* 2 3 (- 11 2 2))  -> (* 2 3 7)  -> 42

The if special form
The if special form is an exception from the evaluation rule.  ::= (if [ ]) ::=  ::=   ::=

After the conditional expression has been evaluated, the process continues with evaluating only one of   and   expressions, according to the condition value. Thus the following expression is evaluated to 42 instead of raising a "division by zero" error: (if (* 1 1) (* 7 6) (/ 8 0))

The for special form
 ::= (for    )

The  is assigned values starting from , increased or decreased by  </tt> to reach <end-value></tt>. On every assignment,  </tt> is evaluated. The result is the last evaluation of  </tt>. The <local-variable></tt> must be declared in the defun</tt> construction (see GNTCFL syntax).

The while special form
<while-expression> ::= (while )

Evaluation of the while special form involves consequent evaluation of  </tt> and  </tt>. If  </tt> evaluates to a zero value, the process of evaluation is completed and the result is the last value of.

The let special form
<let-expression> ::= (let <local-variable> )

The let special form is an assignment construction. First  </tt> is evaluated and then its value is assigned to the <local-variable></tt>. In all expressions in the same function, following the let construction, <local-variable></tt> is evaluated to its assigned value. Consequent assignment of different values to the same local variable is possible. In that case the latest assignment is valid.

User-defined functions
As shown in the previous sections, a function definition includes its frame definition, formal arguments and local variables.

Frames
Whenever a function needs to access some property of a GN component such as (and mainly) the characteristic of a named token, it needs to declare a reference in the so called function frame. The frame is a list of all needed GN properties. Frames describe an environment of network components for the functions. The BNF of the frame definitions is:

. obj | tokens. . char | places. . obj | file. .

where only reference definitions for the recently implemented reference types are given.

For example let us suppose that some function needs the characteristic of a token named "MyToken" and a reference to a place named "MyPlace". The frame definition will look like "2;tokens.MyToken.char;places.MyPlace.obj".

With this frame the network components properties will be referable in the function body as #0 and #1, respectively.

Declaring an user-defined function
As shown above, a user-defined function definition follows the BNF:



Having described of all the major components, let us go straight to the example:

(defun factorial "" (x) (if (= x 0) 1 (* x (factorial (- x 1))))

Here x</tt> is a local variable and the semantics of the expression has already been discussed.

Let us now define a function that gets the square of the default characteristic of some token named "MyToken" and afterward adds 5 to it if there is at least one token in place "MyPlace".

In this example sq</tt> is a local variable and the special form let is used to assign some value to it so that it can be used afterward in all following expressions. The value of the last expression of the function body forms the functions value.

Characteristic functions and predicates
The characteristic function is applied to each token entering the place. Characteristic functions are user-defined functions, which use primitive like set</tt>, set-nth</tt>, <tt>setnamed</tt>, split to set the new value of the characteristic of the token to which the function is applied. The functions are referred by their names in the char and <tt>mergeRule</tt> attributes of the <tt> </tt> tag.

Predicates are user-defined functions, which return a numeric value. Zero is considered false and any other value - true. Names of predicates are listed in the <tt> </tt> tag, when describing the predicate matrix of a transition. A predicate is evaluated whenever a token tries to pass through the transition from an input place to an output place.

Some reserved words are defined only for the characteristic functions and predicates. The reserved word time is evaluated as an integer, showing the current step of the GN. The reserved word token can be used only in characteristic functions, and is evaluated as the value of the last value of the "Default" named characteristic of the token having entered the place.

The reserved word <tt>tokenobj</tt> is also defined only for characteristic functions and is valuated to a reference to the token the function is applied to.

Finally, here is an example of GNTCFL definitions for test.xml.

Primitives
The primitives are built-in functions providing standard operations (arithmetical, input/output, etc). For a complete list of implemented primitives see the list below.