Submit your research to the International Journal "Notes on Intuitionistic Fuzzy Sets". Contact us at nifs.journal@gmail.com

Call for Papers for the 27th International Conference on Intuitionistic Fuzzy Sets is now open!
Conference: 5–6 July 2024, Burgas, Bulgaria • EXTENDED DEADLINE for submissions: 15 APRIL 2024.

GNTCFL

From Ifigenia, the wiki for intuitionistic fuzzy sets and generalized nets
Revision as of 18:23, 27 April 2009 by Vassia Atanassova (talk | contribs) (New page: <div style="float:right; margin-left: .5em">__TOC__</div> '''GNTCFL''' is a language with Lisp-like syntax developed especially for GNTicker. Despite its resemblance to LISP, it is no...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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. The main purpose of the language is to provide the capability of defining GN characteristic functions and predicates as well as user-defined functions used in them.

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:

  <program> ::= <function definition>...
  <function definition> ::= (defun <unique name> <frame definition> ([<formal arguments>]) ([<local variables>]) <expression>...)
  <frame definition> ::= “<number of references>;<reference>;...”
  <formal arguments> ::= <unique name>...
  <local variables> ::= <unique name>...
  <expression> ::= (<supercombinator> [<argument>...])
  <supercombinator> ::= <primitive> | <special form> | <user-defined function>
  <special form> ::= if | for | and | or | let
  <argument> ::= <formal argument> | <local variable> | <constant> | <frame index> | <expression>
  <frame index> ::= #<number>

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

(<supercombinator> [<argument>...])

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-expression> ::= (if <condition> <then> [<else>])
 <condition> ::= <expression>
 <then> ::= <expression>
 <else> ::= <expression>

After the conditional expression has been evaluated, the process continues with evaluating only one of <then> and <else> 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-expression> ::= (for <local-variable> <start-value> <end-value> <step> <expression>)

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

The while special form

 <while-expression> ::= (while <condition> <expression>)

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

The let special form

<let-expression> ::= (let <local-variable> <expression>)

The let special form is an assignment construction. First <expression> is evaluated and then its value is assigned to the <local-variable>. In all expressions in the same function, following the let construction, <local-variable> 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.

Primitives

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

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:

 <frame definition> ::= “<number of references>;<reference>;...”
 <reference> ::= tokens.<unique name>. obj | tokens.<unique name>. char | places.<unique name>. obj | file.<file name>.<file extension>

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:

 <function definition> ::= (defun <unique name> <frame definition> ([<formal arguments>]) ([<local variables>]) <expression>...)

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 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”.

        (defun square "" (x) () (* x x))
        (defun myfunction "2;tokens.MyToken.char;places.MyPlace.obj" () (sq)

                                                ;assign the square of the
                                                ;characteristic to the local variable
                                                ;sq
                        (let sq (square #0))
                                                ;return sq or sq + 5
                        (if (exists #1) (+ sq 5) sq))

In this example sq 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, set-nth, setnamed, 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 mergeRule attributes of the <place> 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 <predicates> 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 tokenobj 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.

        (defun inc "" () ()
                (set (+ token 1)))
        (defun less_than_10 “1;tokens.T1.char” () ()
                (< #0 10))

A list of GNTCFL primitives

References