next up previous index
Next: The Syntax of Multidimensional Up: Q Language Previous: Introduction   Index

Subsections

Syntax

The basic language element is the term. It may be either an atom, or a where clause with a single term as its subject. A term N-tuple is a list of N terms. If N is greater than one, the curly braces ( {} ) are required around the entire list.

The Q language supports recursively structured blocks of definitions, using where clauses. Each where clause may have an internally scoped set of dimensions, graphs and streams declared, which are used by one or more local definitions. A graph is typically a named where clause. The size of a where clause is defined as the number of terms in the clause subject.

Figure 1: Q Language in BNF (partial)
\begin{figure}\begin{eqnarray}
\mathit{ program } & := & \mathit{where\_body} ...
...athbf{>}\mbox{'} \mid \mbox{\lq }\mathbf{>=}\mbox{'}\
\end{eqnarray}\end{figure}

A partial BNF description of the Q language is shown in Fig. 1. The remaining portions -- the definitions of stream_decls and func_decls -- are shown in Figs. 2 and 3 respectively.

An atom is either a constant, a stream, or a task -- a func_call or operation. All atoms have a ``number of dimensions'', which may be zero or more. func_call and operation also have a ``number of arguments'' of one or more. Note that in a multidimensional language such as this one, constants may vary over one or more dimensions. Atoms may be optionally enclosed in parentheses to ensure proper interpretation.

The `if' operation is redundant, but syntactically convenient. The entire set of alu_op operators and some of the unary_op (`-' and `not') are provided mainly for semantic completeness. While supported by an integral basic stream library, they are implemented as functions. It is hoped that Q programs will use a more complex seq_function.

Comments may be embedded in the Q language by preceding them by a double slash ( `//').

Stream Declarations

Although it may be possible to determine the characteristics of a stream by examination of an algorithm, the Q language currently requires that streams be declared, along with their data type and dimensionality. The BNF declarations for their definition are in Fig. 2.

Figure 2: Q Language Stream Declarations BNF
\begin{figure}\begin{eqnarray}
\mathit{ stream\_decls } & := & \mathit{stream\_...
...\mathit{ sample\_step } & := & \mathit{ constant }\
\end{eqnarray}\end{figure}

Sequential Function Declarations

If a function is represented by a seq_function (a Q low level function), a description of the function's input and output parameters must be provided (in a manner similar to the function prototypes of the ANSI C programming language). The syntax of the function declations is specified by the BNF definitions in Fig. 3.

Figure 3: BNF for Q Language Function Declarations
\begin{figure}\begin{eqnarray}
\mathit{func\_decls} & := & [ \mathit{access\_d...
...
\mathit{ func\_step } & := & \mathit{ constant }\
\end{eqnarray}\end{figure}

If no access pattern is specified for a function input or output, a scalar access is assumed.

Intensional Primitives

Two elements of the Q language are not directly translatable into a Q dataflow level algorithm representation, yet understanding them is crucial to understanding the language. They are the direct addressing (or permutation) operator (`@') and the context query operator (`#', really a constant). They are included in the language as primitives, and are used (for example) describe the `resample' and `upsample' stream operators.

Aside from the typical numeric constants, the Q language contains an ``indexing'' constant (`#'), which is monadic (it varies along one dimension) and specifies the location along the bound dimension at which evaluation is taking place.

The direct addressing operator (`@') allows access to a stream element of a stream at a particular location (specified absolutely) along a specified dimension. It is monadic and binary. In its general form, it allows data-dependent access to any element in a stream and is difficult to support. More limited versions are provided for program use: e.g. `first', `next', `prev', `resample' and `upsample'.

Stream Operators

The `resample' and `upsample' stream operators are monadic intensional operators, represented as low level functions in the language description. They must be implemented as operators, however, as they are polymorphic and have an access pattern on their first input argument which is not constant (although fixed in extent.) A pseudo-prototype for these functions is given below, with polymorphic arguments typed as `anytype', and the non-constant access patterns represented by `resample_patt' or `upsample_patt'.

anytype resample.d( anytype resample_patt, int32, int32 );
anytype upsample.d( anytype upsample_patt, int32, int32, int8 );

A more complicated stream operator, `select', is also represented as a low level function. Although polymorphic, this operator has fixed, constant, and mostly scalar access patterns. It supports several forms, each with slightly different semantics. The semantics of the stream operators are described in the Q Instruction Set Architecture.

access_pattern select_range { 1, fixed, { 0, 3, 1, 0, 0 } }

anytype select.d( anytype, int32, int32, int32 );
anytype select.d,r( anytype, int32 select_range );
anytype select.d,t( anytype, int32, int32, int32 );
anytype select.d,t,r( anytype, int32 select_range );


next up previous index
Next: The Syntax of Multidimensional Up: Q Language Previous: Introduction   Index
magiceight-web@media.mit.edu