\section{Grammar of the Network Files}
\label{Grammer}

\subsection{Conventions}
\subsubsection{Lexical Elements of the Grammar}
\index{Network File!Grammar!Lexical Element}
\label{grammarConventions}

The lexical elements of the grammar which defines network files are
listed as regular expresions. The first column lists the name of the
symbol, the second the regular expresion defining it. The third
column may contain comments.

\begin{itemize} 
\item All terminals (characters) are put between
\verb&"&\dots\verb&"&. 

\item Elements of sets are put between square brackets. Within the
brackets, the characters represent themselves (even without \verb&"&),
and - defines a range of values. The class of digits is defined, e.g.
as {\verb&["0"-"9"]&}.

\item Characters can be combined into groups with parenteses {\verb&()&}.

\item {\verb&x*&} means, that the character or group x can
occur zero or more times.

\item {\verb&x+&}  means, that the character or group x must
occur at least once, but may occur several times.

\item {\verb&x?&} means, that x can be omitted.

\item {\verb&x{n}&} means, that x has to occur exactly n times.

\item {\verb&x|y&} means, that either x or y has to occur.

\item {\verb&*&}, {\verb&+&} and {\verb&{}&} bind
strongest, {\verb&?&} is second, {\verb&|&} binds weakest.

\item Groups or classes of characters are treated like a single
character with respect to priority.
\end{itemize}

\subsubsection{Definition of the Grammar}
\index{Network File!Grammar!Definition}

The Grammar defining the interface is listed in a special form of EBNF.

\begin{itemize}
\item Parts between square brackets {\verb&[]&} are facultative.

\item {\verb&|&} separates alternatives (like with terminal symbols).

\item {\verb&{x}&} means, that x may occur zero or more times.

\item CSTRING is everything that is recognized as string by the C
programming language. 

\end{itemize}

\clearpage

\subsection{Terminal Symbols}
\index{Network File!Grammar!Terminal Symbol}

{\footnotesize

\begin{verbatim}
WHITESPACE                {" "|"\n"|"\t"}                     /* whitespaces */                       
BLANKS_TABS               {" "|"\t"}                          /* only blanks or tabs */
W_COL_SEP                 (" "|"\n"|"\t") {" "|"\n"|"\t"} "|" {" "|"\n"|"\t"} 
                          /* at least one blank and the column separation */ 
COL_SEP                   {" "|"\n"|"\t"} "|" {" "|"\n"|"\t"}  /* column separation */ 
COMMA                     {" "|"\n"|"\t"} "," {" "|"\n"|"\t"}  /* at least the comma */
EOL                       {" "|"\n"|"\t"} "\n" {" "|"\n"|"\t"} /* at least "\n" */
CUT                       {" "|"\n"|"\t"} (" "|"\n"|"\t") {" "|"\n"|"\t"} 
                          /* at least a blank, "\t", or "\n" */
COLON                     ":"


/* separation lines for different tables */

TWO_COLUMN_LINE           "-"+"|""-"+
THREE_COLUMN_LINE         "-"+"|""-"+"|""-"+
FOUR_COLUMN_LINE          "-"+"|""-"+"|""-"+"|""-"+
SIX_COLUMN_LINE           "-"+"|""-"+"|""-"+"|""-"+"|""-"+"|""-"+
SEVEN_COLUMN_LINE         "-"+"|""-"+"|""-"+"|""-"+"|""-"+"|""-"+"|""-"+
TEN_COLUMN_LINE           "-"+"|""-"+"|""-"+"|""-"+"|""-"+"|""-"+"|""-"+
                          "|""-"+"|""-"+"|""-"+

COMMENT                   {{" "|"\n"|"\t"} "#" CSTRING "\n" {" "|"\n"|"\t"}} 

VERSION                   "V1.4-3D" | "V2.1" | "V3.0" /* version of SNNS */
  
SNNS                      "SNNS network definition file"  /* output file header */


/* eleven different headers */

GENERATED_AT              "generated at"
NETWORK_NAME              "network name :"
SOURCE_FILES              "source files"
NO.OF_UNITES              "no. of unites :"
NO.OF_CONNECTIONS         "no. of connections :"
NO.OF_UNIT_TYPES          "no. of unit types :"
NO.OF_SITE_TYPES          "no. of site types :"
LEARNING_FUNCTION         "learning function :"
PRUNING_FUNCTION          "pruning function :"
FF_LEARNING_FUNCTION      "subordinate learning function :"
UPDATE_FUNCTION           "update function :"


/* titles of the different sections */

UNIT_SECTION_TITLE        "unit definition section"
DEFAULT_SECTION_TITLE     "unit default section"
SITE_SECTION_TITLE        "site definition section"
TYPE_SECTION_TITLE        "type definition section"
CONNECTION_SECTION_TITLE  "connection definition section"
LAYER_SECTION_TITLE       "layer definition section"
SUBNET_SECTION_TITLE      "subnet definition section"
TRANSLATION_SECTION_TITLE "3D translation section"
TIME_DELAY_SECTION_TITLE  "time delay section"
\end{verbatim}
\clearpage
\begin{verbatim}
/* column-titles of the different tables */ 

NO                        "no."
TYPE_NAME                 "type name"
UNIT_NAME                 "unit name"
ACT                       "act"
BIAS                      "bias"
ST                        "st"
POSITION                  "position"
SUBNET                    "subnet"
LAYER                     "layer"
ACT_FUNC                  "act func"
OUT_FUNC                  "out func"
SITES                     "sites"
SITE_NAME                 "site name"
SITE_FUNCTION             "site function"
NAME                      "name"
TARGET                    "target"
SITE                      "site"
SOURCE:WEIGHT             "source:weight"
UNIT_NO                   "unitNo."
DELTA_X                   "delta x"
DELTA_Y                   "delta y"
Z                         "z"
LLN                       "LLN"
LUN                       "LUN"
TROFF                     "Troff"
SOFF                      "Soff"
CTYPE                     "Ctype"

INTEGER                   ["0"-"9"]+                                     /*integer */
SFLOAT                    ["+" | " " | "-"] ["1" | "0"] "." ["0"-"9"]{5} /*signed float*/ 
STRING                    ("A"-"Z" | "a"-"z" | "|")+                     /*string */


\end{verbatim}}
\normalsize


\subsection{Grammar:}
\index{Network File!Grammar!Grammar}

{\footnotesize
\begin{verbatim}

out_file                ::= file_header sections

file_header             ::= WHITESPACE  COMMENT h_snns EOL COMMENT h_generated_at EOL
                            COMMENT h_network_name EOL COMMENT h_source_files EOL
                            COMMENT h_no.of_unites EOL COMMENT h_no.of_connections EOL
                            COMMENT h_no.of_unit_types EOL COMMENT h_no.of_site_types EOL
                            COMMENT h_learning_function EOL COMMENT h_update_function EOL
                            COMMENT h_pruning_function EOL 
                            COMMENT ff_learning_function EOL


/* parts of the file-header */

h_snns                  ::= SNNS BLANKS_TABS VERSION 
h_generated_at          ::= GENERATED_AT BLANKS_TABS CSTRING
h_network_name          ::= NETWORK_NAME BLANKS_TABS STRING
h_source_files          ::= SOURCE_FILES [BLANKS_TABS COLON BLANKS_TABS CSTRING]
h_no.of_unites          ::= NO.OF_UNITES BLANKS_TABS INTEGER
h_no.of_connections     ::= NO.OF_CONNECTIONS BLANKS_TABS INTEGER
h_no.of_unit_types      ::= NO.OF_UNIT_TYPES BLANKS_TABS INTEGER
h_no.of_site_types      ::= NO.OF_SITE_TYPES BLANKS_TABS INTEGER
h_learning_function     ::= LEARNING_FUNCTION BLANKS_TABS STRING
h_pruning_function      ::= PRUNING_FUNCTION BLANKS_TABS STRING
h_ff_learning_function  ::= FF_LEARNING_FUNCTION BLANKS_TABS STRING
h_update_function       ::= UPDATE_FUNCTION BLANKS_TABS STRING

sections                ::= COMMENT unit_section [COMMENT default_section]
                            [COMMENT site_section] [COMMENT type_section]
                            [COMMENT subnet_section] [COMMENT conn_section]
                            [COMMENT layer_section] [COMMENT trans_section]
                            [COMMENT time_delay_section] COMMENT


/* unit default section */

default_section         ::= DEFAULT_SECTION_TITLE CUT COMMENT WHITESPACE  default_block
default_block           ::= default_header SEVEN_COLUMN_LINE EOL
                            {COMMENT default_def} SEVEN_COLUMN_LINE EOL
default_header          ::= ACT COL_SEP BIAS COL_SEP ST COL_SEP SUBNET COL_SEP
                            LAYER COL_SEP ACT_FUNC COL_SEP OUT_FUNC CUT
default_def             ::= SFLOAT W_COL_SEP SFLOAT W_COL_SEP STRING W_COL_SEP
                            INTEGER W_COL_SEP INTEGER W_COL_SEP STRING W_COL_SEP
                            STRING CUT


/* site definition section */

site_section            ::= SITE_SECTION_TITLE CUT COMMENT WHITESPACE  site_block
site_block              ::= site_header TWO_COLUMN_LINE EOL {COMMENT site_def}
                            TWO_COLUMN_LINE EOL
site_header             ::= SITE_NAME SITE_FUNCTION CUT
site_def                ::= STRING W_COL_SEP STRING CUT


/* type definition section */

type_section            ::= TYPE_SECTION_TITLE CUT COMMENT WHITESPACE  type_block
type_block              ::= type_header FOUR_COLUMN_LINE EOL {COMMENT type_def}
                            FOUR_COLUMN_LINE EOL
type_header             ::= NAME COL_SEP ACT_FUNC COL_SEP OUT_FUNC COL_SEP SITES CUT
type_def                ::= STRING W_COL_SEP STRING W_COL_SEP STRING W_COL_SEP
                            [{STRING COMMA} STRING] CUT


/* subnet definition section */

subnet_section          ::= SUBNET_SECTION_TITLE CUT COMMENT WHITESPACE  subnet_block
subnet_block            ::= subnet_header TWO_COLUMN_LINE EOL {COMMENT subnet_def}
                            TWO_COLUMN_LINE EOL
subnet_header           ::= SUBNET COL_SEP UNIT_NO CUT
subnet_def              ::= INTEGER W_COL_SEP {INTEGER COMMA} INTEGER CUT

\end{verbatim}
\clearpage
\begin{verbatim}

/* unit definition section /*

unit_section            ::= UNIT_SECTION_TITLE CUT COMMENT WHITESPACE  unit_block
unit_block              ::= unit_header TEN_COLUMN_LINE EOL {COMMENT unit_def}
                            TEN_COLUMN_LINE EOL

unit_header             ::= NO COL_SEP TYPE_NAME COL_SEP UNIT_NAME COL_SEP
                            ACT COL_SEP BIAS COL_SEP ST COL_SEP POSITION COL_SEP
                            ACT_FUNC COL_SEP OUT_FUNC COL_SEP SITES CUT
unit_def                ::= INTEGER W_COL_SEP ((STRING W_COL_SEP) | COL_SEP)
                            ((STRING W_COL_SEP) | COL_SEP) ((SFLOAT W_COL_SEP) | COL_SEP)
                            ((SFLOAT W_COL_SEP) | COL_SEP) ((STRING W_COL_SEP) | COL_SEP)
                            INTEGER COMMENT INTEGER COMMENT INTEGER W_COL_SEP
                            ((STRING W_COL_SEP) | COL_SEP) ((STRING W_COL_SEP) | COL_SEP) 
                            [{STRING COMMA} STRING]

/* connection definition section */
                     
connection_section      ::= CONNECTION_SECTION_TITLE CUT 
                            COMMENT WHITESPACE connection_block
connection_block        ::= connection_header THREE_COLUMN_LINE EOL
                            {COMMENT connection_def} THREE_COLUMN_LINE EOL
connection_header       ::= TARGET COL_SEP SITE COL_SEP SOURCE:WEIGHT CUT
connection_def          ::= ((INTEGER W_COL_SEP) | COL_SEP) STRING W_COL_SEP
                            {INTEGER WHITESPACE  COLON WHITESPACE  SFLOAT COMMA}
                            INTEGER WHITESPACE  COLON WHITESPACE  SFLOAT CUT


/* layer definition section */

layer_section           ::= LAYER_SECTION_TITLE CUT COMMENT WHITESPACE  layer_block
layer_block             ::= layer_header TWO_COLUMN_LINE EOL {COMMENT layer_def}
                            TWO_COLUMN_LINE EOL
layer_header            ::= LAYER COL_SEP UNIT_NO CUT
layer_def               ::= INTEGER W_COL_SEP {INTEGER COMMENT} INTEGER CUT


/* 3D translation section */

translation_section     ::= TRANSLATION_SECTION_TITLE CUT 
                            COMMENT WHITESPACE  translation_block
translation_block       ::= translation_header THREE_COLUMN_LINE EOL
                            {COMMENT translation_def} THREE_COLUMN_LINE EOL
translation_header      ::= DELTA_X COL_SEP DELTA_Y COL_SEP Z CUT
translation_def         ::= INTEGER W_COL_SEP INTEGER W_COL_SEP INTEGER     


/* time delay section */

td_section              ::= TIME_DELAY_SECTION_TITLE CUT COMMENT WHITESPACE  td_block
td_block                ::= td_header SIX_COLUMN_LINE EOL {COMMENT td_def}
                            SIX_COLUMN_LINE EOL
td_header               ::= NO COL_SEP LLN COL_SEP LUN COL_SEP
                            TROFF COL_SEP SOFF COL_SEP CTYPE CUT
td_def                  ::= INTEGER W_COL_SEP INTEGER W_COL_SEP INTEGER W_COL_SEP 
                            INTEGER W_COL_SEP INTEGER W_COL_SEP INTEGER W_COL_SEP 
\end{verbatim}}
\normalsize
\clearpage

\section{Grammar of the Pattern Files}
\label{patGrammar}
\index{Pattern File!Grammar}

The typographic conventions used for the pattern file grammar are the
same as for the network file grammar (see section
\ref{grammarConventions}).

\subsection{Terminal Symbols}

{\footnotesize
\begin{verbatim}

WHITE                     {" " | "\t"}
FREE                      {^"\n"}                      /* anything up to EOL */
COMMENT                   "#" FREE "\n"
L_BRACKET                 "["
R_BRACKET                 "]"
V_NUMBER                  [Vv]{INT}+"."{INT}+           /* version number */
INT                       ["0"-"9"]
NUMBER                    [-+]?{{INT}+ | {INT}+{EXP} |{INT}+"."{INT}*({EXP})? |
                          {INT}*"."{INT}+({EXP})?} 
EXP                       [Ee][-+]?{INT}+
VERSION_HEADER            "SNNS pattern definition file"
GENERATED_AT              "generated at" {FREE}* "\n"
NO_OF_PATTERN             "No. of patterns" {WHITE}* ":"
NO_OF_INPUT               "No. of input units" {WHITE}* ":"
NO_OF_OUTPUT              "No. of output units" {WHITE}* ":"
NO_OF_VAR_IDIM            "No. of variable input dimensions" {WHITE}* ":"
NO_OF_VAR_ODIM            "No. of variable output dimensions" {WHITE}* ":"
MAXIMUM_IDIM              "Maximum input dimensions" {WHITE}* ":"
MAXIMUM_ODIM              "Maximum output dimensions" {WHITE}* ":"
\end{verbatim}
}

\subsection{Grammar}


{\footnotesize
\begin{verbatim}

pattern_file              ::= header pattern_list                     
header                    ::= VERSION_HEADER V_NUMBER GENERATED_AT NO_OF_PATTERN NUMBER
                              i_head [o_head] [vi_head] [vo_head]
i_head                    ::= [Comment] NO_OF_INPUT NUMBER
o_head                    ::= [Comment] NO_OF_OUTPUT NUMBER
vi_head                   ::= [Comment] NO_OF_VAR_IDIM NUMBER MAXIMUM_IDIM actual_dim
vo_head                   ::= [Comment] NO_OF_VAR_ODIM NUMBER MAXIMUM_ODIM actual_dim
actual_dim                ::= (L_BRACKET actual_dim_rest R_BRACKET) | 
                              (L_BRACKET R_BRACKET)                
actual_dim_rest           ::= dim_entry | (actual_dim_rest dim_entry)
dim_entry                 ::= INT
pattern_list              ::= pattern | (pattern_list pattern)
pattern                   ::= pattern_start pattern_body 
pattern_start             ::= [Comment] [actual_dim]
pattern_body              ::= pattern_entry | (pattern_body pattern_entry)
pattern_entry             ::= NUMBER
\end{verbatim}
}
