Next: SL syntax, Previous: XML syntax, Up: Compiler
In this section, we describe the syntax of Intermediate Language (IL) grammar files. The IL is a record language in Mozart-Oz syntax. It is designed specifically to be dealt with easily in Mozart-Oz.
We describe the syntax of the IL in a notation similar to the Extended Backus Naur Form (EBNF). We use the record syntax of Mozart-Oz, where records look like this:
<constant>(<constant_1>:<value_1>
...
<constant_n>:<value_n>)
where <constant> is the record name, and
<constant_i>:<value_i> is a feature with field
<constant_i> and value <value_i> (1<=i<=n).
We write down the syntax of the IL as a mapping from description identifiers to descriptions. This mapping is written as a Mozart-Oz record as follows:
o(<description id_1>:<description_1>
...
<description id_n>:<description_n>)
A description can be one of the following:
n descriptions: <description_1>#...#<description_n>
'*'(<description>) (if such a description
is not given, the empty list is assumed)
'?'(<description>) (if such a description
is not given, a default depending on the description is assumed)
<description_id>
n descriptions:
disj(<description_1>
...
<description_n>)
elem(tag: <constant>
<constant_1>: <description_1>
...
<constant_n>: <description_n>)
'ID'
'IDREF'
'CDATA'
'ATOM'
'INT'
We use single quotes to escape Mozart-Oz keywords
(e.g. functor), tokens starting with an upper case letter
(Mozart-Oz variables), and tokens containing dots
(e.g. 'principle.tree').
The XDK includes the Mozart-Oz functor
Compiler/SyntaxChecker.ozf whose exported procedure
Check can be used to check whether an file fulfills its syntax
specifications. The IL syntax specification is in the functor
Compiler/ILSyntax.ozf. The file
Compiler/SyntaxCheckerTest.oz, which can be fed in the Oz
Programming Interface (OPI),
demonstrates how to use the syntax checker to check whether the output
of the UL and XML language frontends are syntactically correct.
The syntax checker will be useful if you decide to design a new grammar file input language in addition to the UL and the XML language.
We continue with giving an overview of the syntax of the IL. The start symbol of the IL syntax is 'S':
'S': 'GRAMMAR'
A grammar definition has tag grammar:
'GRAMMAR': elem(tag: grammar
principles: '*'('PRINCIPLEDEF')
outputs: '*'('OUTPUTDEF')
usedimensions: '*'('CONSTANT')
dimensions: '*'('DIMENSION')
classes: '*'('CLASSDEF')
entries: '*'('ENTRY'))
The principles feature corresponds to a list of principle
definitions ('*'('PRINCIPLEDEF')).
The outputs feature corresponds to a list of output definitions
('*'('OUTPUTDEF')).
The usedimensions feature corresponds to a list of constants
which represent the identifiers of the used dimensions
('*'('CONSTANT')).
The dimensions feature corresponds to a list of dimension
definitions ('*'('DIMENSION')).
The classes feature corresponds to a list of class definitions
('*'('CLASSDEF')).
The entries feature corresponds to a list of lexical entries
('*'('ENTRY')).
A principle definition has tag principledef. Notice that
principle definitions can only be written in the IL since they are
closed for the user. They cannot be written in the UL or the XML
language:
'PRINCIPLEDEF': elem(tag: principledef
id: 'CONSTANT'
dimensions: '*'('VARIABLE')
args: '*'('VARIABLE'#'TYPE')
defaults: '*'('VARIABLE'#'TERM')
node: '?'('TYPE')
constraints: '*'('CONSTANT'#'INTEGER'))
The id feature corresponds to the principle identifier
('CONSTANT').
The dimensions feature corresponds to a list of dimension
variables ('*'('VARIABLE')), the dimension variables which are
introduced by the principle.
The args feature corresponds to a list of pairs of argument
variables and their types ('*'('VARIABLE'#'TYPE')).
The defaults feature corresponds to a list of pairs of argument
variables and their default values ('*'('VARIABLE'#'TERM')).
The node feature corresponds to an optional model
record type '?'('TYPE'). If this feature is not given, the
empty record is assumed.
The constraints feature corresponds to a list of pairs of
constraint names and their priorities
('*'('CONSTANT'#'INTEGER')).
An output definition has tag outputdef. Notice that output
definitions can only be written in the IL since they are closed for
the user. They cannot be written in the UL or the XML language.
'OUTPUTDEF': elem(tag: outputdef
id: 'CONSTANT'
'functor': 'CONSTANT')
The id feature corresponds to the output identifier
('CONSTANT').
The 'functor' feature corresponds to the functor name of
the output ('CONSTANT').
A dimension definition has tag dimension:
'DIMENSION': elem(tag: dimension
id: 'CONSTANT'
attrs: '?'('TYPE')
entry: '?'('TYPE')
label: '?'('TYPE')
types: '*'('TYPEDEF')
principles: '*'('USEPRINCIPLE')
outputs: '*'('OUTPUT')
useoutputs: '*'('USEOUTPUT'))
The id feature corresponds to the dimension identifier
('CONSTANT').
The attrs feature corresponds to an optional attributes type
('?'('TYPE')). The default for this description is the empty
record.
The entry feature corresponds to an optional entry type
('?'('TYPE')). The default for this description is the empty
record.
The label feature corresponds to an optional label type
('?'('TYPE')). The default for this description is the empty
domain.
The types feature corresponds to a list of type definitions
('*'('TYPEDEF')).
The principles feature corresponds to a list of principle uses
('*'('USEPRINCIPLE')).
The outputs feature corresponds to a list of chosen outputs
('*'('OUTPUT')).
The useoutputs feature corresponds to a list of used outputs
('*'('USEOUTPUT')).
An output chooses has tag output:
'OUTPUT': elem(tag: output
idref: 'CONSTANT')
The idref feature corresponds to the chosen output identifier
('CONSTANT').
An output choosing has tag useoutput:
'USEOUTPUT': elem(tag: useoutput
idref: 'CONSTANT')
The idref feature corresponds to the used output identifier
('CONSTANT').
A type definition has tag typedef:
'TYPEDEF': elem(tag: typedef
id: 'CONSTANT'
type: 'TYPE')
The id feature corresponds to the type identifier
('CONSTANT').
The type feature corresponds to the type ('TYPE').
The description identifier 'TYPE' corresponds to
the following:
'TYPE': disj(elem(tag: 'type.domain'
args: '*'('CONSTANT'))
elem(tag: 'type.set'
arg: 'TYPE')
elem(tag: 'type.iset'
arg: 'TYPE')
elem(tag: 'type.tuple'
args: '*'('TYPE'))
elem(tag: 'type.list'
arg: 'TYPE')
elem(tag: 'type.record'
args: '*'('CONSTANT'#'TYPE'))
elem(tag: 'type.valency'
arg: 'TYPE')
elem(tag: 'type.card')
elem(tag: 'type.vec'
arg1: 'TYPE'
arg2: 'TYPE')
elem(tag: 'type.int')
elem(tag: 'type.ints')
elem(tag: 'type.string')
elem(tag: 'type.bool')
elem(tag: 'type.ref'
idref: 'CONSTANT')
elem(tag: 'type.labelref'
arg: 'VARIABLE')
elem(tag: 'type.variable'
data: 'ATOM'))
A domain type has tag 'type.domain'. The args feature
corresponds to the set of constants in the domain
('*'('CONSTANT')).
An accumulative set type has tag 'type.set'. The arg
feature corresponds to the type of the domain of the set
('TYPE').
An intersective set type has tag 'type.iset'. The arg
feature corresponds to the type of the domain of the set
('TYPE').
A tuple type has tag 'type.tuple'. The args feature
corresponds to the types of the projections of the tuple
('*'('TYPE')).
A list type has tag 'type.record'. The arg feature
corresponds to the type of the domain of the list ('TYPE').
A record type has tag 'type.list'. The args feature
corresponds to a list of pairs of the record fields and their types
('*'('CONSTANT'#'TYPE')).
A valency type has tag 'type.valency'. The arg feature
corresponds to the type of the domain of the valency ('TYPE').
A vector type has tag 'type.vec'. The arg1 feature
corresponds to the domain of the fields of the vector ('TYPE'),
and the arg2 feature to the type of the values ('TYPE').
An integer type has tag 'type.int'.
A set of integers type has tag 'type.ints'.
A string type has tag 'type.string'.
A boolean type has tag 'type.bool'.
A type reference has tag 'type.ref'. The idref feature
corresponds to the identifier of the referenced type
('CONSTANT').
A label reference has tag 'type.labelref'. The arg
feature corresponds to the dimension variable whose set of edge labels
is referenced ('VARIABLE').
A type variable has tag 'type.variable'.
A principle use has tag useprinciple:
'USEPRINCIPLE': elem(tag: useprinciple
idref: 'CONSTANT'
dimensions: '*'('VARIABLE'#'CONSTANT')
args: '*'('VARIABLE'#'TERM'))
The idref feature corresponds to the principle identifier of
the used principle ('CONSTANT').
The dimensions feature corresponds to the dimension mapping, a
list of pairs of dimension variables and dimension identifiers
('*'('VARIABLE'#'CONSTANT')).
The args feature corresponds to the argument mapping, a list of
pairs of argument variables and their values
('*'('VARIABLE'#'TERM')).
A class definition has tag classdef:
'CLASSDEF': elem(tag: classdef
id: 'CONSTANT'
vars: '*'('VARIABLE')
body: 'CLASS')
The id feature corresponds to the class identifier
('CONSTANT').
The vars feature corresponds to the list of variables which are
bound by the class ('*'('VARIABLE')).
The body feature corresponds to the class body ('CLASS').
The description identifier 'CLASS' corresponds to the following:
'CLASS': disj(elem(tag: 'class.dimension'
idref: 'CONSTANT'
arg: 'TERM')
elem(tag: 'class.ref'
idref: 'CONSTANT'
args: '*'('VARIABLE'#'TERM'))
elem(tag: conj
args: '*'('CLASS'))
elem(tag: disj
args: '*'('CLASS')))
An entry dimension has tag 'class.dimension'. The idref
feature corresponds to the dimension identifier ('CONSTANT'), and
the arg feature corresponds to the entry dimension itself
('TERM').
A class reference has tag 'class.ref'. The idref feature
corresponds to the class identifier of the referenced class. The
args feature corresponds to the list of pairs of variables and
values that specify the variable binding of the class reference
('*'('VARIABLE'#'TERM')).
A conjunction of class bodies has tag conj. The args
feature corresponds to the list of class bodies which are combined by
conjunction ('*'('CLASS')).
A disjunction of class bodies has tag disj. The args
feature corresponds to the list of class bodies which are combined by
disjunction ('*'('CLASS')).
A lexical entry has tag entry.
'ENTRY': elem(tag: entry
body: 'CLASS')
The body feature corresponds to the class body which specifies
the lexical entry ('CLASS').
The description identifier 'TERM' corresponds to the
following:
'TERM': disj('CONSTANT'
'VARIABLE'
'INTEGER'
'CARD'
'CONSTANT'#'CARD'
'VARIABLE'#'CARD'
elem(tag: top)
elem(tag: bot)
elem(tag: set
args: '*'('TERM'))
elem(tag: list
args: '*'('TERM'))
elem(tag: record
args: '*'('RECSPEC'))
elem(tag: setgen
arg: 'SETGEN')
elem(tag: featurepath
root: 'ROOT'
dimension: 'VARIABLE'
aspect: 'ASPECT'
fields: '*'('CONSTANT'))
elem(tag: annotation
arg1: 'TERM'
arg2: 'TYPE')
elem(tag: conj
args: '*'('TERM'))
elem(tag: disj
args: '*'('TERM'))
elem(tag: concat
args: '*'('TERM'))
elem(tag: order
args: '*'('TERM')))
'ROOT': disj('_' '^')
'ASPECT': disj('entry' 'attrs')
A constant has tag constant:
'CONSTANT': elem(tag: constant
data: 'ATOM')
The data feature corresponds to the constant itself.
A variable has tag variable.
'VARIABLE': elem(tag: variable
data: 'ATOM')
The data feature corresponds to the variable itself.
An integer has tag integer.
'INTEGER': disj(elem(tag: integer
data: 'INT')
elem(tag: integer
data: 'infty'))
An integer is either an integer or infinity.
The data feature of an integer corresponds to the integer
itself or to the special constant infty (for “infinity”).
The description identifier CARD corresponds to the following:
'CARD': disj(elem(tag: 'card.wild'
arg: 'WILD')
elem(tag: 'card.set'
args: '*'('INTEGER'))
elem(tag: 'card.interval'
arg1: 'INTEGER'
arg2: 'INTEGER'))
'WILD': disj('!' '?' '*' '+')
A wild card cardinality set has tag 'card.wild'. The arg
feature corresponds to one of the wild cards '!', '?',
'*', or '+'.
A cardinality set has tag 'card.set'. The args feature
corresponds to a list of integers which specify the set
('*'('INTEGER')).
A cardinality interval has tag 'card.interval'. The arg1
feature corresponds to the left endpoint of the closed interval
('INTEGER'), and the arg2 feature to the right endpoint
('INTEGER').
'CONSTANT'#'CARD' or 'VARIABLE'#'CARD')Cardinality specifications have the syntax 'CONSTANT'#'CARD',
or 'VARIABLE'#'CARD'.
top)Top values have tag top.
bot)Bottom values have tag bot.
set)Sets have tag set. The args feature corresponds to the
set elements ('*'('TERM')).
list)Lists have tag list. The args feature corresponds to the
list elements ('*'('TERM')).
record)Records have tag record. The args feature corresponds to
the list of record specifications for this record
'*'('RECSPEC').
A record specification (description identifier 'RECSPEC') has
the following syntax:
'RECSPEC': disj('CONSTANT'#'TERM'
'VARIABLE'#'TERM'
elem(tag: conj
args: '*'('RECSPEC'))
elem(tag: disj
args: '*'('RECSPEC')))
I.e. a record specification is either a pair of a field and a value
('CONSTANT'#'TERM'), of a variable and a value
('VARIABLE'#'TERM'), or a conjunction of record specifications
(tag: conj), or a disjunction of record specifications (tag:
disj).
setgen)A set generator expression has tag setgen. The arg
feature is the set generator expression body (description identifier
'SETGEN'):
'SETGEN': disj('CONSTANT'
elem(tag: conj
args: '*'('SETGEN'))
elem(tag: disj
args: '*'('SETGEN')))
I.e. a set generator expression body is either a constant, or a
conjunction of set generator expression bodies (tag: conj), or
a disjunction of set generator expression bodies (tag: disj).
featurepath)A feature path has tag featurepath.
The root feature corresponds to the root variable of the
feature path, either '_' or '^'.
The dimension feature corresponds to the dimension variable
of the feature path ('VARIABLE').
The aspect feature corresponds to the aspect of the feature path,
either 'entry' or 'attrs'.
The fields feature corresponds to the fields of the feature
path ('*'('CONSTANT')).
annotation)A type annotation has tag annotation.
The arg1 feature corresponds to the term ('TERM'), and
the arg2 feature to the annotated type ('TYPE').
conj)A conjunction has tag conj.
The args feature corresponds to the list of terms which are
combined by conjunction.
disj)A disjunction has tag disj.
The args feature corresponds to the list of terms which are
combined by disjunction.
concat)A concatenation has tag concat.
The args feature corresponds to the list of terms which are
to be concatenated.
Concatenation is restricted to strings.
order)An order generator
has tag order.
The args feature corresponds to the list of terms from which
a set of pairs representing an order relation is generated.
The XDK solver can also yield partial solutions in which not all values in the node record are determined; instead some of the values are still variables. In the following, we show how these variables are represented in the IL.
This is the IL syntax for undetermined cardinality sets (i.e. cardinality set variables) in valencies:
elem(tag: '_'
args: [IL1 IL2])
IL1 is the cardinality set representing the set of integers which
are already known to be in the cardinality set variable.
IL2 is the cardinality set representing the set of integers which
can still be bound to the cardinality set variable.
This is the IL syntax for undetermined constants (i.e. constant variables):
elem(tag: '_'
args: [DSpec])
DSpec is a domain specification1,
representing the set of constants which can still be bound to the
constant variable.
This is the IL syntax for undetermined integers (i.e. integer variables):
elem(tag: '_'
args: [DSpec])
DSpec is a domain specification representing the set of integers
which can still be bound to the integer variable.
This is the IL syntax for undetermined lists (i.e. list variables):
elem(tag: '_'
args: nil)
The IL syntax for undetermined sets (i.e. set variables) differs depending on the domain of the set:
elem(tag: '_'
args: [MSpec1 MSpec2 DSpec])
MSpec1 is a set specification representing the set of constants
which are already known to be in the set variable.
MSpec2 is a set specification representing the set of constants
which could still end up in the set variable.
DSpec is a domain specification representing the set of
integers which can still be bound to the integer variable representing
the cardinality of the set variable.
elem(tag: '_'
args: nil)
This is the IL syntax for undetermined strings (i.e. string variables):
elem(tag: '_'
args: nil)
The IL syntax for undetermined tuples (i.e. tuple variables) differs depending on the types of the projections of the tuple:
elem(tag: '_'
args: [DSpec])
DSpec is a domain specification representing the set of tuples
which can still be bound to the tuple variable.
elem(tag: '_'
args: nil)
[1] A domain specification can be a list of values (or pairs of values), or just a value (or a pair of values) describing the domain. Pairs of values denote closed intervals within the set.