<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<meta name="GENERATOR" content="TtH 3.00">
<style type="text/css"><!--
td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
td div.norm {line-height:normal;}
span.roman {font-family: serif; font-style: normal; font-weight: normal;}
span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
span.overacc1 {position: relative; left: .6em; top: -1.2ex;} --></style>
<title> Vector Pascal</title>
<h1 align="center"> Vector Pascal </h1>
<p>
<h3 align="center">Paul Cockshott and Ken Renfrew </h3>
<p>
<h1>Contents </h1>
<a href="#tth_chAp1"
>1 Elements of the language</a><br />
<a href="#tth_sEc1.1"
>1.1 Alphabet</a><br />
<a href="#tth_sEc1.1.1"
>1.1.1 Extended alphabet</a><br />
<a href="#tth_sEc1.2"
>1.2 Reserved words</a><br />
<a href="#tth_sEc1.3"
>1.3 Comments</a><br />
<a href="#tth_sEc1.4"
>1.4 Identifiers</a><br />
<a href="#tth_sEc1.5"
>1.5 Literals</a><br />
<a href="#tth_sEc1.5.1"
>1.5.1 Integer numbers</a><br />
<a href="#tth_sEc1.5.2"
>1.5.2 Real numbers</a><br />
<a href="#tth_sEc1.5.3"
>1.5.3 Character strings</a><br />
<a href="#tth_chAp2"
>2 Declarations</a><br />
<a href="#tth_sEc2.1"
>2.1 Constants</a><br />
<a href="#tth_sEc2.1.1"
>2.1.1 Array constants</a><br />
<a href="#tth_sEc2.1.2"
>2.1.2 Pre-declared constants</a><br />
<a href="#tth_sEc2.2"
>2.2 Labels</a><br />
<a href="#tth_sEc2.3"
>2.3 Types</a><br />
<a href="#tth_sEc2.3.1"
>2.3.1 Simple types</a><br />
<a href="#tth_sEc2.3.2"
>2.3.2 Structured types</a><br />
<a href="#tth_sEc2.3.3"
>2.3.3 Dynamic types</a><br />
<a href="#tth_sEc2.4"
>2.4 File types</a><br />
<a href="#tth_sEc2.5"
>2.5 Variables</a><br />
<a href="#tth_sEc2.5.1"
>2.5.1 External Variables</a><br />
<a href="#tth_sEc2.5.2"
>2.5.2 Entire Variables</a><br />
<a href="#tth_sEc2.5.3"
>2.5.3 Indexed Variables</a><br />
<a href="#tth_sEc2.5.4"
>2.5.4 Field Designators</a><br />
<a href="#tth_sEc2.5.5"
>2.5.5 Referenced Variables</a><br />
<a href="#tth_sEc2.6"
>2.6 Procedures and Functions</a><br />
<a href="#tth_sEc2.6.1"
>2.6.1 Procedural Parameters to Procedures</a><br />
<a href="#tth_sEc2.6.2"
>2.6.2 Procedure types</a><br />
<a href="#tth_chAp3"
>3 Algorithms</a><br />
<a href="#tth_sEc3.1"
>3.1 Expressions</a><br />
<a href="#tth_sEc3.1.1"
>3.1.1 Mixed type expressions</a><br />
<a href="#tth_sEc3.1.2"
>3.1.2 Primary expressions</a><br />
<a href="#tth_sEc3.1.3"
>3.1.3 Unary expressions</a><br />
<a href="#tth_sEc3.1.4"
>3.1.4 Operator Reduction</a><br />
<a href="#tth_sEc3.1.5"
>3.1.5 Complex conversion</a><br />
<a href="#tth_sEc3.1.6"
>3.1.6 Conditional expressions</a><br />
<a href="#tth_sEc3.1.7"
>3.1.7 Factor</a><br />
<a href="#tth_sEc3.1.8"
>3.1.8 Multiplicative expressions</a><br />
<a href="#tth_sEc3.1.9"
>3.1.9 Additive expressions</a><br />
<a href="#tth_sEc3.1.10"
>3.1.10 Expressions</a><br />
<a href="#tth_sEc3.1.11"
>3.1.11 Operator overloading</a><br />
<a href="#tth_sEc3.2"
>3.2 Statements</a><br />
<a href="#tth_sEc3.2.1"
>3.2.1 Assignment</a><br />
<a href="#tth_sEc3.2.2"
>3.2.2 Procedure statement</a><br />
<a href="#tth_sEc3.2.3"
>3.2.3 Goto statement</a><br />
<a href="#tth_sEc3.2.4"
>3.2.4 Exit Statement</a><br />
<a href="#tth_sEc3.2.5"
>3.2.5 Compound statement</a><br />
<a href="#tth_sEc3.2.6"
>3.2.6 If statement</a><br />
<a href="#tth_sEc3.2.7"
>3.2.7 Case statement</a><br />
<a href="#tth_sEc3.2.8"
>3.2.8 With statement</a><br />
<a href="#tth_sEc3.2.9"
>3.2.9 For statement</a><br />
<a href="#tth_sEc3.2.10"
>3.2.10 While statement</a><br />
<a href="#tth_sEc3.2.11"
>3.2.11 Repeat statement</a><br />
<a href="#tth_sEc3.3"
>3.3 Input Output </a><br />
<a href="#tth_sEc3.3.1"
>3.3.1 Input</a><br />
<a href="#tth_sEc3.3.2"
>3.3.2 Output </a><br />
<a href="#tth_chAp4"
>4 Programs and Units</a><br />
<a href="#tth_sEc4.1"
>4.1 The export of identifiers from units</a><br />
<a href="#tth_sEc4.1.1"
>4.1.1 The export of procedures from libraries.</a><br />
<a href="#tth_sEc4.1.2"
>4.1.2 The export of Operators from units</a><br />
<a href="#tth_sEc4.2"
>4.2 Unit parameterisation and generic functions</a><br />
<a href="#tth_sEc4.3"
>4.3 The invocation of programs and units</a><br />
<a href="#tth_sEc4.4"
>4.4 The compilation of programs and units.</a><br />
<a href="#tth_sEc4.4.1"
>4.4.1 Linking to external libraries</a><br />
<a href="#tth_sEc4.5"
>4.5 Instantiation of parametric units</a><br />
<a href="#tth_sEc4.5.1"
>4.5.1 Direct instantiation</a><br />
<a href="#tth_sEc4.5.2"
>4.5.2 Indirect instantiation</a><br />
<a href="#tth_sEc4.6"
>4.6 The System Unit</a><br />
<a href="#tth_chAp5"
>5 Implementation issues</a><br />
<a href="#tth_sEc5.1"
>5.1 Invoking the compiler</a><br />
<a href="#tth_sEc5.1.1"
>5.1.1 Environment variable</a><br />
<a href="#tth_sEc5.1.2"
>5.1.2 Compiler options</a><br />
<a href="#tth_sEc5.1.3"
>5.1.3 Dependencies</a><br />
<a href="#tth_sEc5.2"
>5.2 Calling conventions</a><br />
<a href="#tth_sEc5.3"
>5.3 Array representation</a><br />
<a href="#tth_sEc5.3.1"
>5.3.1 Range checking</a><br />
<a href="#tth_sEcindex">Index</a><br />
<p>
<h1>Introduction</h1>
<p>
Vector Pascal is a dialect of Pascal designed to make efficient use of the multi-media
instructionsets of recent procesors. It supports data parallel operations and
saturated arithmetic. This manual describes the Vector Pascal language.
<p>
A number of widely used contemporary processors have instructionset extensions
for improved performance in multi-media applications. The aim is to allow operations
to proceed on multiple pixels each clock cycle. Such instructionsets have been
incorporated both in specialist DSP chips like the Texas C62xx[<a href="#Texas" name="CITETexas">35</a>]
and in general purpose CPU chips like the Intel IA32[<a href="#Intel00" name="CITEIntel00">14</a>] or the AMD
K6 [<a href="#AMD" name="CITEAMD">2</a>].
<p>
These instructionset extensions are typically based on the Single Instruction-stream
Multiple Data-stream (SIMD<a name="SIMD00">
</a>) model in which a single instruction
causes the same mathematical operation to be carried out on several operands,
or pairs of operands at the same time. The level or parallelism supported ranges
from 2 floating point operations at a time on the AMD<a name="AMD00">
</a> K<a name="K600">
</a>6
architecture to 16 byte operations at a time on the intel P4 architecture. Whilst
processor architectures are moving towards greater levels of parallelism, the
most widely used programming languages like C<a name="C00">
</a>, Java<a name="Java00">
</a> and
Delphi<a name="Delphi00">
</a> are structured around a model of computation in which
operations take place on a single value at a time. This was appropriate when
processors worked this way, but has become an impediment to programmers seeking
to make use of the performance offered by multi-media instructionsets. The introduction
of SIMD instruction sets[<a href="#IA32" name="CITEIA32">13</a>][<a href="#Peleg97" name="CITEPeleg97">29</a>] to Personal Computers potentially
provides substantial performance increases, but the ability of most programmers
to harness this performance is held back by two factors. The first is the limited
availability of compilers that make effective use of these instructionsets in
a machine independent manner. This remains the case despite the research efforts
to develop compilers for multi-media instructionsets[<a href="#Cheong97" name="CITECheong97">8</a>][<a href="#Leupers99" name="CITELeupers99">26</a>][<a href="#Krall00" name="CITEKrall00">24</a>][<a href="#Sreraman00" name="CITESreraman00">32</a>].
The second is the fact that most popular programming languages were designed
on the word at a time model of the classic von Neumann computer.
<p>
Vector Pascal aims to provide an efficient and concise notation for programmers
using Multi-Media enhanced CPUs. In doing so it borrows concepts for expressing
data parallelism that have a long history, dating back to Iverson's work on
APL<a name="APL00">
</a> in the early '60s[<a href="#Iverson62" name="CITEIverson62">17</a>].
<p>
Define a vector of type <em>T</em> as having type T[] . Then if we have
a binary operator <font face="symbol">w</font
>:(T<font face="symbol">Ä</font
>T)<font face="symbol">®</font
> T , in languages derived
from APL we automatically have an operator <font face="symbol">w</font
>:(T[]<font face="symbol">Ä</font
>T[])<font face="symbol">®</font
> T[]
. Thus if x,y are arrays of integers k=x+y is the array
of integers where k<sub>i</sub>=x<sub>i</sub>+y<sub>i</sub> .
<p>
The basic concept is simple, there are complications to do with the semantics
of operations between arrays of different lengths and different dimensions,
but Iverson provides a consistent treatment of these. The most recent languages
to be built round this model are J<a name="J00">
</a>, an interpretive language[<a href="#Jmanual" name="CITEJmanual">19</a>][<a href="#Burke" name="CITEBurke">5</a>][<a href="#Jintro" name="CITEJintro">20</a>],
and F[<a href="#Metcalf96" name="CITEMetcalf96">28</a>] a modernised Fortran<a name="Fortran00">
</a>. In principle though
any language with array types can be extended in a similar way. Iverson's approach
to data parallelism is machine independent. It can be implemented using scalar
instructions or using the SIMD model. The only difference is speed.
<p>
Vector Pascal incorporates Iverson's approach to data parallelism. Its aim is
to provide a notation that allows the natural and elegant expression of data
parallel algorithms within a base language that is already familiar to a considerable
body of programmers and combine this with modern compilation techniques.
<p>
By an elegant algorithm I mean one which is expressed as concisely as possible.
Elegance is a goal that one approaches asymptotically, approaching but never
attaining[<a href="#Chaitin" name="CITEChaitin">7</a>]. APL and J allow the construction of very elegant programs,
but at a cost. An inevitable consequence of elegance is the loss of redundancy.
APL programs are as concise, or even more concise than conventional mathematical
notation[<a href="#Iverson80" name="CITEIverson80">18</a>] and use a special character-set. This makes them hard
for the uninitiated to understand. J attempts to remedy this by restricting
itself to the ASCII character-set, but still looks dauntingly unfamiliar to
programmers brought up on more conventional languages. Both APL and J are interpretive
which makes them ill suited to many of the applications for which SIMD speed
is required. The aim of Vector Pascal is to provide the conceptual gains of
Iverson's notation within a framework familiar to imperative programmers.
<p>
Pascal<a name="Pascal00">
</a>[<a href="#Jensen" name="CITEJensen">21</a>]was chosen as a base language over the alternatives
of C and Java. C was rejected because notations like <tt>x+y</tt> for <tt>x</tt>
and <tt>y</tt> declared as <tt>int x[4]</tt>, <tt>y[4]</tt>, already have the
meaning of adding the addresses of the arrays together. Java was rejected because
of the difficulty of efficiently transmitting data parallel operations via its
intermediate code to a just in time code generator.
<p>
Iverson's approach to data parallelism is machine independent. It can be implemented
using scalar instructions or using the SIMD<a name="SIMD00">
</a> model. The only difference
is speed. Vector Pascal incorporates Iverson's approach to data parallelism.
<p>
<h1><a name="tth_chAp1">
Chapter 1 </a><br />Elements of the language</h1>
<p>
<h2><a name="tth_sEc1.1">
1.1</a> Alphabet</h2>
The Vector Pascal compiler accepts files in the UTF-8 encoding of
Unicode as source. Since ASCII is a subset of this, ASCII files are valid input.
<p>
Vector Pascal programs are made up of letter, digits and special
symbols. The letters digits and special symbols are draw either from a base
character set or from an extended character set. The base character set is drawn
from ASCII and restricts the letters to be from the Latin alphabet.
The extended character set allows letters from other alphabets.
<p>
The special symbols used in the base alphabet are shown in table<a href="#specials">1.1</a> .
<p>
<a name="tth_tAb1.1">
</a> <center>Table 1.1: Special symbols<a name="specials">
</a></center>
<center>
<table border="1">
<tr><td align="center">+</td><td align="center">:</td><td align="center">(</td></tr>
<tr><td align="center">-</td><td align="center">'</td><td align="center">)</td></tr>
<tr><td align="center">*</td><td align="center">=</td><td align="center">[</td></tr>
<tr><td align="center">/</td><td align="center"><></td><td align="center">]</td></tr>
<tr><td align="center">:=</td><td align="center"><</td><td align="center">{</td></tr>
<tr><td align="center">.</td><td align="center"><=</td><td align="center">}</td></tr>
<tr><td align="center">,</td><td align="center">>=</td><td align="center"></td></tr>
<tr><td align="center">;</td><td align="center">></td><td align="center">..</td></tr>
<tr><td align="center">+:</td><td align="center">@</td><td align="center">*)</td></tr>
<tr><td align="center">-:</td><td align="center">$</td><td align="center">(*</td></tr>
<tr><td align="center">_</td><td align="center">**</td><td align="center"></td></tr></table>
<p>
</center>
<p>
<h3><a name="tth_sEc1.1.1">
1.1.1</a> Extended alphabet</h3>
The extended alphabet is described in <a href="VPUnicode.htm">Using Unicode with Vector Pascal</a>.
<p>
<h2><a name="tth_sEc1.2">
1.2</a> Reserved words</h2>
<a name="resw">
</a>
The reserved words are
<p>
<tt>ABS, ADDR, AND, ARRAY,</tt>
<p>
<tt>BEGIN, BYTE2PIXEL,</tt>
<p>
<tt>CASE, CAST, CDECL, CHR, CONST, COS,</tt>
<p>
<tt> DIV, DO, DOWNTO,</tt>
<p>
<tt>END, ELSE, EXIT, EXTERNAL,</tt>
<p>
<tt>FALSE, FILE, FOR, FUNCTION,</tt>
<p>
<tt>GOTO,</tt>
<p>
<tt>IF, IMPLEMENTATION, IN, INTERFACE, IOTA,</tt>
<p>
<tt>LABEL, LIBRARY, LN,</tt>
<p>
<tt>MAX, MIN, MOD,</tt>
<p>
<tt>NAME, NDX, NOT,</tt>
<p>
<tt>OF, OR, ORD, OTHERWISE,</tt>
<p>
<tt>PACKED, PERM, PIXEL2BYTE, POW, PRED,</tt> <br /><tt>PROCEDURE, PROGRAM,</tt>
<tt>PROTECTED ,</tt>
<p>
<tt>RDU, RECORD, REPEAT, ROUND,</tt>
<p>
<tt>SET, SHL, SHR, SIN, SIZEOF, STRING, SQRT, SUCC,</tt>
<p>
<tt>TAN, THEN, TO, TRANS, TRUE, TYPE,</tt>
<p>
<tt>VAR,</tt>
<p>
<tt>WITH, WHILE, </tt>
<tt>UNIT, UNTIL, USES </tt>
<p>
Reserved words may be written in either lower case or upper case letters, or
any combination of the two.
<p>
<h2><a name="tth_sEc1.3">
1.3</a> Comments</h2>
<p>
The comment<a name="comment13">
</a> construct
<p>
<tt>{<a name="13">
</a></tt> < any sequence of characters not containing ``}''
> <tt>}</tt>
<p>
may be inserted between any two identifiers, special symbols, numbers or reserved
words without altering the semantics or syntactic correctness of the program.
The bracketing pair <tt>(* *)<a name="*)13">
</a></tt> may substitute for <tt>{
}</tt>. Where a comment starts with <tt>{</tt> it continues until the next <tt>}</tt>.
Where it starts with <tt>(*<a name="(*13">
</a></tt> it must be terminated by <tt>*)</tt><a href="#tthFtNtAAB" name="tthFrefAAB"><sup>1</sup></a>.
<p>
<h2><a name="tth_sEc1.4">
1.4</a> Identifiers</h2>
<p>
Identifiers are used to name values, storage locations, programs, program modules,
types, procedures and functions. An identifier<a name="identifier14">
</a> starts with
a letter followed by zero or more letters, digits or the special symbol <tt>_</tt>.
Case is not significant in identifiers.
ISO Pascal allows the Latin letters A-Z to be used in identifiers.
Vector Pascal extends this by allowing symbols from the Greek,
Cyrillic, Katakana and Hiragana, or CJK character sets
<p>
<h2><a name="tth_sEc1.5">
1.5</a> Literals</h2>
<p>
<h3><a name="tth_sEc1.5.1">
1.5.1</a> Integer numbers</h3>
<p>
Integer numbers are formed of a sequence of decimal digits, thus <tt>1</tt>,
<tt>23</tt>, <tt>9976</tt> etc, or as hexadecimal<a name="hexadecimal15">
</a> numbers,
or as numbers of any base between 2 and 36. A hexadecimal number takes the form
of a <tt>$</tt> followed by a sequence of hexadecimal digits thus <tt>$01,
$3ff, $5A</tt>. The letters in a hexadecimal number may be upper or lower case
and drawn from the range <tt>a..f</tt> or <tt>A..F. </tt>
<p>
A based integer<a name="integer15">
</a> is written with the base first followed by a
# character and then a sequence of letters or digits. Thus <tt>2#1101</tt>
is a binary number <tt>8#67</tt> an octal<a name="octal15">
</a> number and <tt>20#7i</tt>
a base 20 number.
<p>
The default precision for integers is 32 bits<a href="#tthFtNtAAC" name="tthFrefAAC"><sup>2</sup></a>.
<p>
<center>
<table border="1">
<tr><td align="center"><digit sequence></td><td align="center"><digit> +</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><decimal integer></td><td align="center"><digit sequence></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><hex integer></td><td align="center">`$'<hexdigit>+</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><based integer> </td><td align="center"><digit sequence>'#'<alphanumeric>+</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><unsigned integer></td><td align="center"><decimal integer></td></tr>
<tr><td align="center"></td><td align="center"><hex integer></td></tr>
<tr><td align="center"></td><td align="center"><based integer></td></tr></table>
<p>
<a name="tth_tAb1.2">
</a> <center>Table 1.2: The hexadecimal digits of Vector Pascal.</center>
<center>
<table border="1">
<tr><td align="center">Value</td><td align="center">0</td><td align="center">1</td><td align="center">2</td><td align="center">3</td><td align="center">4</td><td align="center">5</td><td align="center">6</td><td align="center">7</td><td align="center">8</td><td align="center">9</td><td align="center">10</td><td align="center">11</td><td align="center">12</td><td align="center">13</td><td align="center">14</td><td align="center">15</td></tr>
<tr><td align="center">Notation 1</td><td align="center">0</td><td align="center">1</td><td align="center">2</td><td align="center">3</td><td align="center">4</td><td align="center">5</td><td align="center">6</td><td align="center">7</td><td align="center">8</td><td align="center">9</td><td align="center">A</td><td align="center">B</td><td align="center">C</td><td align="center">D</td><td align="center">E</td><td align="center">F</td></tr>
<tr><td align="center">Notation 2</td><td align="center"></td><td align="center"></td><td align="center"></td><td align="center"></td><td align="center"></td><td align="center"></td><td align="center"></td><td align="center"></td><td align="center"></td><td align="center"></td><td align="center">a</td><td align="center">b</td><td align="center">c</td><td align="center">d</td><td align="center">e</td><td align="center">f</td></tr></table>
<p>
</center>.
<p>
</center> <h3><a name="tth_sEc1.5.2">
1.5.2</a> Real numbers</h3>
<p>
Real numbers are supported in floating point notation, thus <tt>14.7</tt>,
<tt> 9.99e5</tt>,
<tt>
38E3,</tt> <tt>3.6e-4</tt> are all valid denotations for real<a name="real15">
</a> numbers. The default
precision for real numbers is also 32 bit, though intermediate calculations
may use higher precision. The choice of 32 bits as the default precision is
influenced by the fact that 32 bit floating point vector operations are well
supported in multi-media<a name="media15">
</a> instructions.
<p>
<center>
<table border="1">
<tr><td align="center"><exp></td><td align="center">`e'</td></tr>
<tr><td align="center"></td><td align="center">`E'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><scale factor></td><td align="center">[<sign>] <unsigned integer></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><sign></td><td align="center">`-'</td></tr>
<tr><td align="center"></td><td align="center">`+'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><unsigned real></td><td align="center"><decimal integer> `.' <digit sequence></td></tr>
<tr><td align="center"></td><td align="center"><decimal integer>` .' <digit sequence> <exp><scale factor> </td></tr>
<tr><td align="center"></td><td align="center"><decimal integer><exp> <scale factor></td></tr></table>
<p>
</center>
<h4>Fixed point numbers</h4>
<p>
In Vector Pascal pixels<a name="pixels15">
</a> are represented as signed fixed point
fractions in the range -1.0 to 1.0. Within this range, fixed point literals
have the same syntactic form as real numbers.
<p>
<h3><a name="tth_sEc1.5.3">
1.5.3</a> Character strings</h3>
<p>
Sequences of characters enclosed by quotes are called literal<a name="literal15">
</a>
strings. Literal strings<a name="strings15">
</a> consisting of a single character are
constants of the standard type char. If the string is to contain a quote character
this quote character must be written twice.
<p>
<tt><font size="-1">'A' 'x' 'hello' 'John''s house'</font></tt><font size="-1">
<p>
</font>are all valid literal strings. The allowable characters in literal strings are
any of the Unicode characters above u0020. The character strings must be input
to the compiler in UTF-8 format.
<p>
<h1><a name="tth_chAp2">
Chapter 2 </a><br />Declarations</h1>
<p>
Vector Pascal is a language supporting nested declaration<a name="declaration20">
</a>
contexts. A declaration context is either a program context, and unit interface
or implementation context, or a procedure or function context. A resolution
context determines the meaning of an identifier. Within a resolution context,
identifiers can be declared to stand for constants, types, variables, procedures
or functions. When an identifier is used, the meaning taken on by the identifier
is that given in the closest containing resolution context. Resolution contexts
are any declaration context or a <tt>with</tt> statement context. The ordering
of these contexts when resolving an identifier is:
<p>
<ol type="1"><p>
<li> The declaration context identified by any <tt>with</tt> statements which nest
the current occurrence of the identifier. These <tt>with</tt> statement contexts
are searched from the innermost to the outermost.</li>
<p>
<li> The declaration context of the currently nested procedure<a name="procedure20">
</a>
declarations. These procedure contexts are searched from the innermost to the
outermost.</li>
<p>
<li> The declaration context of the current unit<a name="unit20">
</a> or program<a name="program20">
</a>.</li>
<p>
<li> The interface declaration contexts of the units mentioned in the use list of
the current unit or program. These contexts are searched from the rightmost
unit mentioned in the use list to the leftmost identifier in the use list.</li>
<p>
<li> The interface declaration context of the System<a name="System20">
</a> unit.</li>
<p>
<li> The pre-declared identifiers of the language.</li>
</ol>
<p>
<h2><a name="tth_sEc2.1">
2.1</a> Constants</h2>
<p>
A constant definition introduces an identifier as a synonym for a constant.
<p>
<center>
<table border="1">
<tr><td align="center"><constant declaration></td><td align="center"><identifier>=<expression></td></tr>
<tr><td align="center"></td><td align="center"><identifier>':'<type>'='<typed constant></td></tr></table>
<p>
</center>Constants can be simple constants or typed constants. A simple constant must
be a constant expression whose value is known at compile time. This restricts
it to expressions for which all component identifiers are other constants, and
for which the permitted operators<a name="operators21">
</a> are given in table<a href="#MMConst">2.1</a>
. This restricts simple constants to be of scalar or string types.
<p>
<p>
<a name="tth_tAb2.1">
</a> <center>Table 2.1: The operators permitted in Vector Pascal constant expressions.<a name="MMConst">
</a></center>
<center>
<table border="1">
<tr><td align="center">+</td><td align="center">-</td><td align="center">*</td><td align="center">/</td><td align="center">div</td><td align="center">mod</td><td align="center">shr</td><td align="center">shl</td><td align="center">and</td><td align="center">or</td></tr></table>
<p>
</center>
<p>
Typed constants provide the program with initialised variables which may hold
array types.
<p>
<center>
<table border="1">
<tr><td align="center"><typed constant></td><td align="center"><expression></td></tr>
<tr><td align="center"></td><td align="center"><array constant></td></tr></table>
<p>
</center> <h3><a name="tth_sEc2.1.1">
2.1.1</a> Array constants</h3>
<p>
Array constants are comma separated lists of constant expressions enclosed by
brackets. Thus
<p>
<tt>tr:array[1..3] of real =(1.0,1.0,2.0);</tt>
<p>
is a valid array constant declaration, as is:
<p>
<font size="-1"><tt>t2:array[1..2,1..3] of real=((1.0,2.0,4.0),(1.0,3.0,9.0));</tt></font>
<p>
The array constant<a name="constant21">
</a><a name="array constant21">
</a> must structurally
match the type<a name="type21">
</a> given to the identifier. That is to say it must
match with respect to number of dimensions, length of each dimension, and type
of the array elements.
<p>
<center>
<table border="1">
<tr><td align="center"><array constant></td><td align="center">'(' <typed constant> [,<typed constant>]* ')'</td></tr></table>
<p>
</center> <h3><a name="tth_sEc2.1.2">
2.1.2</a> Pre-declared constants<a name="constants21">
</a></h3>
<p>
<dl compact="compact">
<dt><b><tt>maxint<a name="maxint21">
</a></tt></b></dt>
<dd>The largest supported integer value.</dd>
<dt><b><tt>pi<a name="pi21">
</a></tt></b></dt>
<dd> A real numbered approximation to <font face="symbol">p</font
></dd>
<dt><b><tt>maxchar<a name="maxchar21">
</a></tt></b></dt>
<dd> The highest character in the character set.</dd>
<dt><b><tt>maxstring<a name="maxstring21">
</a></tt></b></dt>
<dd>The maximum number of characters allowed
in a string.</dd>
<dt><b><tt>maxreal<a name="maxreal21">
</a></tt></b></dt>
<dd>The highest representable real.</dd>
<dt><b><tt>minreal<a name="minreal21">
</a></tt></b></dt>
<dd>The smallest representable positive real number.</dd>
<dt><b><tt>epsreal<a name="epsreal21">
</a></tt></b></dt>
<dd>The smallest real number which when added
to 1.0 yields a value distinguishable from 1.0.</dd>
<dt><b><tt>maxdouble<a name="maxdouble21">
</a></tt></b></dt>
<dd>The highest representable double precision
real number.</dd>
<dt><b><tt>mindouble<a name="mindouble21">
</a></tt></b></dt>
<dd>The smallest representable positive double
precision real number.</dd>
<dt><b><tt>complexzero<a name="complexzero21">
</a></tt></b></dt>
<dd>A complex number with zero real and
imaginary parts.</dd>
<dt><b><tt>complexone</tt><a name="complexone21">
</a></b></dt>
<dd>A complex number with real part 1 and
imaginary part 0.
</dd>
</dl>
<p>
<h2><a name="tth_sEc2.2">
2.2</a> Labels</h2>
<p>
Labels are written as digit sequences. Labels must be declared before they are
used. They can be used to label the start of a statement and can be the destination
of a <tt>goto<a name="goto22">
</a></tt> statement. A <tt>goto</tt> statement must have
as its destination a label<a name="label22">
</a> declared within the current innermost
declaration context. A statement can be prefixed by a label followed by a colon.
<p>
Example
<p>
<tt>label 99;</tt>
<p>
<tt>begin read(x); if x>9 goto 99; write(x*2);99: end;</tt>
<p>
<h2><a name="tth_sEc2.3">
2.3</a> Types</h2>
<p>
A type declaration determines the set of values that expressions of this type
may assume and associates with this set an identifier.
<p>
<center>
<table border="1">
<tr><td align="center"><type></td><td align="center"><simple type></td></tr>
<tr><td align="center"></td><td align="center"><structured type></td></tr>
<tr><td align="center"></td><td align="center"><pointer type></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><type definition></td><td align="center"><identifier>'='<type> </td></tr></table>
<p>
</center> <h3><a name="tth_sEc2.3.1">
2.3.1</a> Simple types</h3>
<p>
Simple types are either scalar, standard, subrange or dimensioned types.
<p>
<center>
<table border="1">
<tr><td align="center"><simple type></td><td align="center"><scalar type></td></tr>
<tr><td align="center"></td><td align="center"><integral type></td></tr>
<tr><td align="center"></td><td align="center"><subrange type></td></tr>
<tr><td align="center"></td><td align="center"><dimensioned type></td></tr>
<tr><td align="center"></td><td align="center"><floating point type></td></tr></table>
<p>
</center>
<h4>Scalar types</h4>
<p>
A scalar<a name="scalar23">
</a> type<a name="type23">
</a> defines an ordered set of identifier
by listing these identifiers. The declaration takes the form of a comma separated
list of identifiers enclosed by brackets. The identifiers in the list are declared
simultaneously with the declared scalar type to be constants of this declared
scalar type. Thus
<pre>
colour = (red,green,blue);
day=(monday,tuesday,wednesday,thursday,
friday,saturday,sunday);
</pre>
are valid scalar type declarations.
<p>
<h4>Standard types</h4><a name="auxtypes">
</a>
<p>
The following types are provided as standard in Vector Pascal:
<p>
<a name="tth_tAb2.2">
</a> <center>Table 2.2: Categorisation of the standard types.</center>
<center>
<table border="1">
<tr><td align="center">type</td><td align="center">category</td></tr><tr><td>
<tr><td align="center">real</td><td align="center">floating point</td></tr>
<tr><td align="center">double</td><td align="center">floating point</td></tr>
<tr><td align="center">byte</td><td align="center">integral</td></tr>
<tr><td align="center">pixel</td><td align="center">fixed point</td></tr>
<tr><td align="center">shortint</td><td align="center">integral</td></tr>
<tr><td align="center">word</td><td align="center">integral</td></tr>
<tr><td align="center">integer</td><td align="center">integral</td></tr>
<tr><td align="center">cardinal</td><td align="center">integral</td></tr>
<tr><td align="center">boolean</td><td align="center">scalar</td></tr>
<tr><td align="center">char</td><td align="center">scalar</td></tr></table>
<p>
</center>
<p>
<dl compact="compact">
<dt><b><tt>integer<a name="integer23">
</a></tt></b></dt>
<dd>The numbers are in the range -maxint to +maxint.</dd>
<dt><b><tt>real<a name="real23">
</a></tt></b></dt>
<dd>These are a subset of the reals constrained by the
IEEE 32 bit floating point format.</dd>
<dt><b><tt>double<a name="double23">
</a></tt></b></dt>
<dd>These are a subset of the real numbers constrained
by the IEEE<a name="IEEE23">
</a> 64 bit floating point format.</dd>
<dt><b><tt>pixel<a name="pixel23">
</a></tt></b></dt>
<dd>These are represented as fixed<a name="fixed23">
</a> point<a name="point23">
</a>
binary<a name="binary23">
</a> fractions<a name="fractions23">
</a> in the range -1.0 to 1.0.</dd>
<dt><b><tt>boolean<a name="boolean23">
</a></tt></b></dt>
<dd>These take on the values <tt>(false<a name="false23">
</a>,true<a name="true23">
</a>)</tt>
which are ordered such that <tt>true>false</tt>.</dd>
<dt><b><tt>char<a name="char23">
</a></tt></b></dt>
<dd>These include the characters from <tt>chr(0)</tt>
to <tt>charmax</tt><a name="charmax23">
</a>. All the allowed characters for string literals
are in the type char, but the character-set may include other characters whose
printable form is country specific.</dd>
<dt><b><tt>pchar</tt><a name="pchar23">
</a></b></dt>
<dd>Defined as <tt>char</tt>.</dd>
<dt><b><tt>byte<a name="byte23">
</a></tt></b></dt>
<dd>These take on the positive integers between 0 and
255.</dd>
<dt><b><tt>shortint<a name="shortint23">
</a></tt></b></dt>
<dd>These take on the signed values between
-128 and 127.</dd>
<dt><b><tt>word<a name="word23">
</a></tt></b></dt>
<dd>These take on the positive integers from 0 to 65535.</dd>
<dt><b><tt>cardinal<a name="cardinal23">
</a></tt></b></dt>
<dd>These take on the positive integers form
0 to 4292967295, i.e., the most that can be represented in a 32 bit unsigned
number.</dd>
<dt><b><tt>longint<a name="longint23">
</a></tt></b></dt>
<dd>A 32 bit integer, retained for compatibility
with Turbo Pascal.</dd>
<dt><b><tt>int<a name="int6423">
</a>64</tt></b></dt>
<dd>A 64 bit integer.</dd>
<dt><b><tt>complex<a name="complex23">
</a></tt></b></dt>
<dd>A complex number with the real and imaginary
parts held to 32 bit precision.
</dd>
</dl>
<p>
<h4>Subrange types</h4>
<p>
A type may be declared as a subrange<a name="subrange23">
</a> of another scalar<a name="scalar23">
</a>
or integer<a name="integer23">
</a> type by indicating the largest and smallest value
in the subrange. These values must be constants known at compile time.
<p>
<center>
<table border="1">
<tr><td align="center"><subrange type></td><td align="center"><constant> '..' <constant></td></tr></table>
<p>
</center>Examples: 1..10, 'a'..'f', monday..thursday.
<p>
<h4>Pixels</h4>
<p>
The <em>conceptual model</em> of pixels in Vector Pascal is that they are real
numbers in the range <font face="symbol">-</font
>1.0..1.0 . As a signed representation it lends itself
to subtraction. As an unbiased representation, it makes the adjustment of contrast
easier. For example, one can reduce contrast 50% simply by multiplying an image
by 0.5 <a href="#tthFtNtAAD" name="tthFrefAAD"><sup>3</sup></a>. Assignment to pixel variables in Vector Pascal is defined to be saturating
- real numbers outside the range <font face="symbol">-</font
>1..1 are clipped to it. The multiplications
involved in convolution operations fall naturally into place.
<p>
The <em>implementation model</em> of pixels used in Vector Pascal is of 8 bit
signed integers treated as fixed point binary fractions. All the conversions
necessary to preserve the monotonicity of addition, the range of multiplication
etc, are delegated to the code generator which, where possible, will implement
the semantics using efficient, saturated multi-media arithmetic instructions.
<p>
<h4>Dimensioned types</h4>
<p>
These provide a means by which floating point types can be specialised to represent
dimensioned numbers as is required in physics calculations. For example:
<p>
<tt>kms =(mass,distance,time);</tt>
<p>
<tt>meter=real of distance;</tt>
<p>
<tt>kilo=real of mass;</tt>
<p>
<tt>second=real of time;</tt>
<p>
<tt>newton=real of mass * distance * time POW -2;</tt>
<p>
<tt>meterpersecond = real of distance *time POW -1;</tt>
<p>
The grammar is given by:
<p>
<center>
<table border="1">
<tr><td align="center"><dimensioned type></td><td align="center"><real type> <dimension >['*' <dimension>]*</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><real type></td><td align="center">'real'</td></tr>
<tr><td align="center"></td><td align="center">'double'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><dimension></td><td align="center"><identifier> ['POW' [<sign>] <unsigned integer>]</td></tr></table>
<p>
</center>The identifier<a name="identifier23">
</a> must be a member of a scalar type, and that
scalar type is then referred to as the basis space of the dimensioned type.
The identifiers of the basis<a name="basis23">
</a> space are referred to as the dimensions
of the dimensioned type<a name="type23">
</a>. Associated with each dimension of a dimensioned
type there is an integer number referred to as the power of that dimension.
This is either introduced explicitly at type declaration time, or determined
implicitly for the dimensional type of expressions.
<p>
A value of a dimensioned type is a dimensioned value. Let log<sub>d</sub>t
of a dimensioned type t be the power to which the dimension d
of type t is raised. Thus for t = newton in the example above, and
d = time, log<sub>d</sub>t=<font face="symbol">-</font
>2
<p>
If x and y are values of dimensioned<a name="dimensioned23">
</a> types
t<sub>x</sub> and t<sub>y</sub> respectively, then the following operators are only
permissible if t<sub>x</sub>=t<sub>y</sub>
<p>
<center>
<table border="1">
<tr><td align="center">+</td><td align="center">-</td><td align="center"><</td><td align="center">></td><td align="center"><></td><td align="center">=</td><td align="center"><=</td><td align="center">>=</td></tr></table>
<p>
</center>For + and -, the dimensional<a name="dimensional23">
</a> type of the result is the same
as that of the arguments. The operations
<p>
<center>
<table border="1">
<tr><td align="center">*</td><td align="center">/</td></tr></table>
<p>
</center>are permitted if the types t<sub>x</sub> and t<sub>y</sub> share the same basis
space, or if the basis space of one of the types is a subrange of the basis
space of the other.
<p>
The operation <tt>POW</tt> is permitted between dimensioned types and integers.
<p>
<b>* </b>Dimension deduction rules
<p>
<ol type="1"><p>
<li> If x=y*z for x:t<sub>1</sub>,y:t<sub>2</sub>,z:t<sub>3</sub> with basis space B
then
<p>
<br clear="all" /><table border="0" width="95%"><tr><td>
<table align="center"><tr><td nowrap="nowrap" align="center">
<font face="symbol">"</font
><sub> d <font face="symbol">Î</font
> B </sub> log<sub>d</sub>t<sub>1</sub> = log<sub>d</sub>t<sub>2</sub>+log<sub>d</sub>t<sub>3</sub> </td></tr></table>
</td></tr></table>
</li>
<p>
<li> If x=y/z for x:t<sub>1</sub>,y:t<sub>2</sub>,z:t<sub>3</sub> with basis space B
then
<p>
<br clear="all" /><table border="0" width="95%"><tr><td>
<table align="center"><tr><td nowrap="nowrap" align="center">
<font face="symbol">"</font
><sub>d <font face="symbol">Î</font
> B</sub>log<sub>d</sub>t<sub>1</sub>=log<sub>d</sub>t<sub>2</sub><font face="symbol">-</font
>log<sub>d</sub>t<sub>3</sub> </td></tr></table>
</td></tr></table>
</li>
<p>
<li> If x=y <tt>POW</tt> z for x:t<sub>1</sub>,y:t<sub>2</sub>,z:integer with
basis space for t<sub>2</sub> , B then
<p>
<br clear="all" /><table border="0" width="95%"><tr><td>
<table align="center"><tr><td nowrap="nowrap" align="center">
<font face="symbol">"</font
><sub>d <font face="symbol">Î</font
> B</sub>log<sub>d</sub>t<sub>1</sub>=log<sub>d</sub>t<sub>2</sub>×z </td></tr></table>
</td></tr></table>
.</li>
</ol>
<p>
<h3><a name="tth_sEc2.3.2">
2.3.2</a> Structured types</h3>
<p>
<h4>Static Array<a name="array23">
</a><a name="array, static23">
</a> types</h4>
<p>
An array type is a structure consisting of a fixed number of elements all of
which are the same type. The type of the elements is referred to as the element
type. The elements of an array value are indicated by bracketed indexing expressions.
The definition of an array<a name="array23">
</a> type<a name="type23">
</a> simultaneously defines
the permitted type of indexing expression and the element type.
<p>
The index<a name="index23">
</a> type<a name="type23">
</a> of a static<a name="static23">
</a> array<a name="array, static23">
</a>
must be a scalar<a name="scalar23">
</a> or subrange<a name="subrange23">
</a> type. This implies
that the bounds of a static array are known at compile time.
<p>
<center>
<table border="1">
<tr><td align="center"><array type></td><td align="center">'array' '[' <index type>[,<index type>]* ']' 'of' <type></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><index type></td><td align="center"><subrange type></td></tr>
<tr><td align="center"></td><td align="center"><scalar type></td></tr>
<tr><td align="center"></td><td align="center"><integral type></td></tr></table>
<p>
</center>Examples
<p>
<tt>array[colour] of boolean;</tt>
<p>
<tt>array[1..100] of integer;</tt>
<p>
<tt>array[1..2,4..6] of byte;</tt>
<p>
<tt>array[1..2] of array[4..6] of byte;</tt>
<p>
The notation [<em>b,c</em>] in an array declaration is shorthand for the notation
[<em>b</em>] <tt>of array</tt> [ <em>c</em> ]. The number of dimensions of an
array type is referred to as its rank. Scalar types have rank 0.
<p>
<h4>String types</h4>
<p>
A string<a name="string23">
</a> type denotes the set of all sequences of characters
up to some finite length and must have the syntactic form:
<p>
<center>
<table border="1">
<tr><td align="center"><string-type></td><td align="center">'string[' <integer constant>']'</td></tr>
<tr><td align="center"></td><td align="center">'string'</td></tr>
<tr><td align="center"></td><td align="center">'string(' <ingeger constant>')'</td></tr></table>
<p>
</center>the integer constant indicates the maximum number of characters that may be
held in the string type. The maximum number of characters that can be held in
any string is indicated by the pre-declared constant <tt>maxstring</tt>. The
type <tt>string</tt> is shorthand for <tt>string[maxstring]</tt>.
<p>
<h4>Record types</h4>
<p>
A record type defines a set of similar data structures. Each member of this
set, a record instance, is a Cartesian product of number of components or <em>fields</em>
specified in the record<a name="record23">
</a> type definition. Each field has an identifier
and a type. The scope of these identifiers is the record itself.
<p>
A record type may have as a final component a <em>variant<a name="variant23">
</a>
part</em>. The variant part, if a variant part exists, is a union of several variants,
each of which may itself be a Cartesian product of a set of fields. If a variant
part exists there may be a tag field whose value indicates which variant is
assumed by the record instance.
<p>
All field identifiers even if they occur within different variant parts, must
be unique within the record type.
<p>
<center>
<table border="1">
<tr><td align="center"><record type></td><td align="center">'record' <field list> 'end'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><field list></td><td align="center"><fixed part></td></tr>
<tr><td align="center"></td><td align="center"><fixed part>';' <variant part></td></tr>
<tr><td align="center"></td><td align="center"><variant part></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><fixed part></td><td align="center"><record section> [ ';' <record section.]*</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><record section></td><td align="center"><identifier>[',' <identifier>]* ':' <type></td></tr>
<tr><td align="center"></td><td align="center"><empty></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><variant part></td><td align="center">'case' [<tag field> ':'] <type identifier> 'of'<variant>[';' <variant>]*</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><variant></td><td align="center"><constant> [',' <constant>]*':' '(' <field list> ')'</td></tr>
<tr><td align="center"></td><td align="center"><empty></td></tr></table>
<p>
</center>
<h4>Set types</h4>
<p>
A set<a name="set23">
</a> type defines the range of values which is the power-set of
its base type. The base type must be an ordered type, that is a type on which the
operations < , = and > are defined<a href="#tthFtNtAAE" name="tthFrefAAE"><sup>4</sup></a>.
Thus sets may be declared whose base types are characters, numbers, ordinals, or strings. Any user
defined type on which the comparison operators have been defined can also be the base type
of a set.
<p>
<center>
<table border="1">
<tr><td align="center"><set type></td><td align="center">'set' 'of' <base type></td></tr></table>
<p>
</center> <h3><a name="tth_sEc2.3.3">
2.3.3</a> Dynamic<a name="Dynamic23">
</a> types</h3>
<p>
Variables declared within the program are accessed by their identifier. These
variables exist throughout the existence of the scope within which they are
declared, be this unit, program or procedure. These variables are assigned storage
locations whose addresses, either absolute or relative to some register, can
be determined at compile time. Such locations a referred to as static<a name="static23">
</a><a href="#tthFtNtAAF" name="tthFrefAAF"><sup>5</sup></a>. Storage locations may also be allocated dynamically. Given a type <tt>t</tt>,
the type of a pointer<a name="pointer23">
</a> to an instance of type <tt>t</tt> is <tt>t</tt>.
<p>
A pointer of type <tt>t</tt> can be initialised to point to
a new store location of type t by use of the built in procedure <tt>new</tt>.
Thus if <tt>p:t</tt>,
<p>
<tt>new(p);</tt>
<p>
causes <tt>p</tt> to point at a store location of type <tt>t</tt>.
<p>
<h4>Pointers to dynamic<a name="dynamic23">
</a><a name="dynamic array23">
</a> arrays<a name="array, dynamic23">
</a><a name="array23">
</a></h4>
<p>
The types pointed to by pointer types can be any of the types mentioned so far,
that is to say, any of the types allowed for static<a name="static23">
</a> variables.
In addition however, pointer types can be declared to point at dynamic arrays.
A dynamic array is an array whose bounds are determined at run time.
<p>
Pascal<a name="Pascal9023">
</a> 90[<a href="#ISO90" name="CITEISO90">15</a>] introduced the notion of schematic or
parameterised types as a means of creating dynamic arrays. Thus where <tt>r</tt>
is some integral or ordinal type one can write
<p>
<tt>type z(a,b:r)=array[a..b] of t;</tt>
<p>
If <tt>p:z</tt>, then
<p>
<tt>new(p,n,m)</tt>
<p>
where <tt>n,m:r</tt> initialises <tt>p</tt> to point to an array of bounds <tt>n..m</tt>.
The bounds of the array can then be accessed as <tt>p.a,
p.b</tt>. In this case <tt>a, b</tt> are the formal parameters of
the array type. Vector Pascal currently only allows
parameterised types to be allocated on the heap via <tt>new</tt>. The extended form of the procedure <tt>new </tt> must be passed an actual
parameter for each formal parameter in the array type.
<p>
<h4>Dynamic arrays<a name="dynamic array23">
</a></h4>
Vector Pascal also allows the use of Delphi style declarations for dynamic arrays. Thus one
can declare:
<pre>
type vector = array of real;
matrix = array of array of real;
</pre>
The size of such arrays has to be explicitly initialised at runtime by a call to the
library procedure <tt>setlength</tt>.
Thus one might have:
<pre>
function readtotal:real;
var len:integer;
v:vector;
begin
readln(len);
setlength(v,len);
readln(v);
readtotal := \+ v;
end;
</pre>
The function <tt>readtotal</tt> reads the number of elements in a vector from
the standard input. It then calls <tt>setlength</tt> to initialise the vector length.
Next it reads in the vector and computes its total using the reduction operator <tt> \+</tt>.
<p>
In the example, the variable <tt>v</tt> denotes an array of reals not a pointer
to an array of reals. However, since the array size is not known at compile time
<tt>setlength</tt> will allocate space for the array on the heap not in the local stack
frame. The use of <tt>setlength</tt> is thus restricted to programs which have been
compiled with the garbage collection flag enabled (see section <a href="#BOEHM">5.1.2</a>).
The procedure <tt>setlength </tt> must be passed a parameter for each dimension of
the dynamic array. The bounds of the array <tt>a</tt> formed by <tt><br />setlength(a,i,j,k)<br /></tt>
would then be <tt>0..i-1, 0..j-1, 0..k-1</tt>.
<p>
<h4>Low <a name="low23">
</a> and High <a name="high23">
</a></h4>
The build in functions <tt>low </tt> and <tt>high</tt> return the lower and upper bounds
of an array respectively. They work with both static and dynamic arrays.
Consider the following examples.
<pre>
program arrays;
type z(a,b:integer)=array[a..b] of real;
vec = array of real;
line= array [1..80] of char;
matrix = array of array of real;
var i:^z; v:vec; l:line; m:matrix;
begin
setlength(v,10);setlength(m,5,4);
new(i,11,13);
writeln(low(v), high(v));
writeln(low(m), high(m));
writeln(low(m[0]),high(m[0]));
writeln(low(l),high(l));
writeln(low(i^),high(i^));
end.
</pre>
would print
<pre>
0 9
0 4
0 3
1 80
11 13
</pre>
<h2><a name="tth_sEc2.4">
2.4</a> File types</h2>
<p>
A type may be declared to be a file of a type. This form of definition is kept
only for backward compatibility. All file types are treated as being equivalent.
A file type corresponds to a handle to an operating system file. A file variable
must be associated with the operating system file by using the procedures <tt>assign,
rewrite, append</tt>, and <tt>reset</tt> provided by the system unit. A pre-declared
file type <tt>text</tt> exists.
<p>
Text files are assumed to be in Unicode UTF-8 format. Conversions are performed between
the internal representation of characters and UTF-8 on input/output from/to a text file.
<p>
<h2><a name="tth_sEc2.5">
2.5</a> Variables<a name="Variables25">
</a></h2>
<p>
Variable declarations consist of a list of identifiers denoting the new variables,
followed by their types.
<p>
<center>
<table border="1">
<tr><td align="center"><variable declaration></td><td align="center"><identifier> [',' <identifier>]* ':' <type><extmod></td></tr></table>
<p>
</center>Variables are abstractions over values. They can be either simple identifiers,
components or ranges of components of arrays, fields of records or referenced
dynamic variables.
<p>
<center>
<table border="1">
<tr><td align="center"><variable></td><td align="center"><identifier></td></tr>
<tr><td align="center"></td><td align="center"><indexed variable></td></tr>
<tr><td align="center"></td><td align="center"><indexed range></td></tr>
<tr><td align="center"></td><td align="center"><field designator></td></tr>
<tr><td align="center"></td><td align="center"><referenced variable></td></tr></table>
<p>
</center>Examples
<p>
<tt>x,y:real;</tt>
<p>
<tt>i:integer;</tt>
<p>
<tt>point:real;</tt>
<p>
<tt>dataset:array[1..n]of integer;</tt>
<p>
<tt>twoDdata:array[1..n,4..7] of real;</tt>
<p>
<h3><a name="tth_sEc2.5.1">
2.5.1</a> External Variables</h3>
<p>
A variable may be declared to be external by appending the external modifier.
<p>
<center>
<table border="1">
<tr><td align="center"><extmod></td><td align="center">';' 'external' 'name' <stringlit></td></tr></table>
<p>
</center>This indicates that the variable is declared in a non Vector Pascal external
library. The name by which the variable is known in the external library is
specified in a string literal.
<p>
Example
<p>
<tt>count:integer; external name '_count';</tt>
<p>
<h3><a name="tth_sEc2.5.2">
2.5.2</a> Entire Variables</h3><a name="entire">
</a>
<p>
An entire variable is denoted by its identifier. Examples <tt>x,y,point</tt>,
<p>
<h3><a name="tth_sEc2.5.3">
2.5.3</a> Indexed Variables</h3>
<p>
A component of an <em>n</em> dimensional array variable is denoted by the variable
followed by <em>n</em> index expressions in brackets.
<p>
<center>
<table border="1">
<tr><td align="center"><indexed variable></td><td align="center"><variable>'[' <expression>[','<expression>]* ']'</td></tr></table>
<p>
</center>The type of the indexing expression must conform to the index type of the array
variable. The type of the indexed variable is the component type of the array.
<p>
Examples
<p>
<tt>twoDdata[2,6]</tt>
<p>
<tt>dataset[i]</tt>
<p>
Given the declaration
<p>
<tt>a=array[p] of q</tt>
<p>
then the elements of arrays of type <tt>a</tt>, will have type <tt>q</tt> and
will be identified by indices<a name="indices25">
</a> of type <tt>p</tt> thus:
<p>
<tt>b[i]</tt>
<p>
where <tt>i:p</tt>, <tt>b:a</tt>.
<p>
Given the declaration
<p>
<tt>z = string[x]</tt>
<p>
for some integer x <tt> <font face="symbol">£</font
> maxstring</tt>, then the characters within
strings<a name="strings25">
</a> of type <tt>z</tt> will be identified by indices in
the range <tt>1..x,</tt> thus:
<p>
<tt>y[j]</tt>
<p>
where <tt>y:z</tt>, <tt>j:1..x</tt>.
<p>
<h4>Indexed Ranges</h4>
<p>
A range of components of an array variable are denoted by the variable followed
by a range expression in brackets.
<p>
<center>
<table border="1">
<tr><td align="center"><indexed range></td><td align="center"><variable> '[' <range expression>[',' <range expression>]* ']'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><range expression></td><td align="center"><expression> '..' <expression></td></tr></table>
<p>
</center>The expressions within the range<a name="range25">
</a> expression must conform to the
index type of the array variable. The type of a range expression <tt>a[i..j]</tt>
where <tt>a: array[p..q] of t</tt> is <tt>array[0..j-i] of t.</tt>
<p>
Examples:
<p>
<tt>dataset[i..i+2]:=blank;</tt>
<p>
<tt>twoDdata[2..3,5..6]:=twoDdata[4..5,11..12]*0.5;</tt>
<p>
Subranges<a name="Subranges25">
</a> may be passed in as actual parameters to procedures
whose corresponding formal parameters<a name="parameters25">
</a> are declared as variables
of a schematic<a name="schematic25">
</a> type. Hence given the following declarations:
<p>
<tt>type image(miny,maxy,minx,maxx:integer)=array[miny..maxy,minx..maxx]
of byte;</tt>
<p>
<tt>procedure invert(var im:image);begin im:=255-im; end;</tt>
<p>
<tt>var screen:array[0..319,0..199] of byte;</tt>
<p>
then the following statement would be valid:
<p>
<tt>invert(screen[40..60,20..30]);</tt>
<p>
<h4>Indexing arrays with arrays</h4>
<p>
If an array<a name="array25">
</a> variable occurs on the right hand side of an assignment
statement, there is a further form of indexing possible. An array may be indexed
by another array. If <tt>x:array[t0] of t1</tt> and <tt>y:array[t1]
of t2</tt>, then <tt>y[x]</tt> denotes the virtual array of type <tt>array[t0]
of t2</tt> such that <tt>y[x][i]=y[x[i]]</tt>. This construct is
useful for performing permutations. To fully understand the following example
refer to sections <a href="#iota">3.1.3</a>,<a href="#manimplicitindices">3.2.1</a>.
<p>
<b>Example </b>
<p>
Given the declarations
<p>
<tt>const perms:array[0..3] of integer=(3,1,2,0);</tt>
<p>
<tt>var ma,m0:array[0..3] of integer; </tt>
<p>
then the statements
<p>
<tt>m0:= (iota 0)+1;</tt>
<p>
<tt>write('m0=');for j:=0 to 3 do write(m0[j]);writeln;</tt>
<p>
<tt>ma:=m0[perms]; </tt>
<p>
<tt>write('perms=');for j:=0 to 3 do write(perms[j]);writeln; </tt>
<p>
<tt>writeln('ma:=m0[perms]');for j:=0 to 3 do write(ma[j]);writeln;</tt>
<p>
would produce the output
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
m0= 1 2 3 4
<p>
perms= 3 1 2 0
<p>
ma:=m0[perms]
<p>
4 2 3 1
</dd>
</dl>
<p>
This basic method can also be applied to multi-dimensional array. Consider the
following example of an image warp:
<pre>
type pos = 0..255;
image = array[pos,pos] of pixel;
warper = array[pos,pos,0..1] of pos;
var im1 ,im2 :image;
warp :warper;
begin
....
getbackwardswarp(warp);
im2 := im1 [ warp ];
....
</pre>
The procedure <tt>getbackwardswarp </tt> determines for each pixel position <tt>x, y</tt> in an
image the position in the source image from which it is to be obtained.
After the assignment we have the postcondition
<br clear="all" /><table border="0" width="100%"><tr><td>
<table align="center"><tr><td nowrap="nowrap" align="center">
<tt>im</tt><tt>2</tt><tt>[</tt><tt>x</tt><tt>,</tt><tt>y</tt><tt>]</tt> = <tt>im</tt><tt>1</tt><tt>[</tt><tt>warp</tt><tt>[</tt><tt>x</tt><tt>,</tt><tt>y</tt><tt>,</tt><tt>0</tt><tt>]</tt><tt>,</tt><tt>warp</tt><tt>[</tt><tt>x</tt><tt>,</tt><tt>y</tt><tt>,</tt><tt>1</tt><tt>]</tt><tt>]</tt> <font face="symbol">"</font
> <tt>x</tt><tt>,</tt><tt>y</tt> <font face="symbol">Î</font
> <tt>pos</tt></td></tr></table>
</td></tr></table>
<h3><a name="tth_sEc2.5.4">
2.5.4</a> Field<a name="Field25">
</a> Designators</h3>
<p>
A component of an instance of a record type, or the parameters of an instance
of a schematic type are denoted by the record or schematic type instance followed
by the field or parameter name.
<p>
<center>
<table border="1">
<tr><td align="center"><field designator></td><td align="center"><variable>'.'<identifier></td></tr></table>
<p>
</center> <h3><a name="tth_sEc2.5.5">
2.5.5</a> Referenced Variables<a name="Variables25">
</a></h3>
<p>
If <tt>p:t</tt>, then <tt>p</tt> denotes
the dynamic variable of type <tt>t</tt> referenced by <tt>p</tt>.
<p>
<center>
<table border="1">
<tr><td align="center"><referenced variable></td><td align="center"><variable> ''</td></tr></table>
<p>
</center> <h2><a name="tth_sEc2.6">
2.6</a> Procedures and Functions</h2>
<p>
Procedure and function declarations allow algorithms to be identified by name
and have arguments associated with them so that they may be invoked by procedure
statements or function calls.
<p>
<table border="1">
<tr><td><procedure declaration></td><td><procedure heading>';'[<proc tail>]</td></tr><tr><td>
<tr><td><proc tail></td><td>'forward' </td></tr>
<tr><td></td><td>'external' [ 'name' <string>]</td></tr>
<tr><td></td><td><block></td></tr>
<tr><td><paramlist></td><td>'('<formal parameter sec>[';'<formal parameter sec>]*')'</td></tr>
<tr><td><procedure heading> </td><td>'procedure' <identifier> [<paramlist>]</td></tr>
<tr><td></td><td>'function'<identifier> [<paramlist>]':'<type></td></tr><tr><td>
<tr><td><formal parameter sec></td><td>['var']<identifier>[','<identifier>]':'<type>
</td><td><procedure heading>
</tr><tr><td>
<procedure type></td><td>'procedure' [<paramlist>]
</td><td>'function' [<paramlist>]':'<type>
</td></tr></table>
<p>
The parameters declared in the procedure heading are local to the scope of the
procedure. The parameters in the procedure heading are termed formal<a name="formal parameter26">
</a>
parameters. If the identifiers in a formal parameter section are preceded by
the word <tt>var</tt>, then the formal parameters are termed variable parameters.
The block<a href="#tthFtNtAAG" name="tthFrefAAG"><sup>6</sup></a> of a procedure or function constitutes a scope local to its executable compound
statement. Within a function declaration there must be at least one statement
assigning a value to the function identifier. This assignment determines the
result of a function, but assignment to this identifier does not cause an immediate
return from the function.
<p>
Function return values can be scalars, pointers, records, strings, static arrays or sets. Arrays whose size is determined at run time
may not be returned from a function.
<p>
Where a procedure is declared as forward it
must be followed by a full definition of procedure lower in the current scope.
<p>
The external declaration form allows calls to be made to libraries written in other languages.
<p>
<b>Examples </b>
<p>
The function sba is the mirror image of the abs function.
<p>
<tt>function sba(i:integer):integer; </tt>
<p>
<tt>begin if i>o then sba:=-i else sba:=i end;</tt>
<p>
<tt>type stack:array[0..100] of integer;</tt>
<p>
<tt>procedure push(var s:stack;i:integer);</tt>
<p>
<tt>begin s[s[0]]:=i;s[0]:=s[0]+1; end;</tt>
<p>
<pre>
procedure append(var f:fileptr);external;
procedure close (var f:fileptr); external name 'pasclose';
</pre>
<p>
<h3><a name="tth_sEc2.6.1">
2.6.1</a> Procedural Parameters to Procedures</h3>
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
<p>
</dd>
</dl>A procedure may have parameters that are themselves procedures as
shown in the following example.
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
<p>
program CONF103(output);
<p>
var
<p>
i : integer;
<p>
procedure alsoconforms(x : integer);
<p>
begin
<p>
writeln(' PASS...6.6.3.1-4 (CONF103)')
<p>
end;
<p>
procedure conforms(procedure alsoconforms(x : integer));
<p>
var x : boolean;
<p>
begin
<p>
x:=true;
<p>
alsoconforms(1)
<p>
end;
<p>
begin
<p>
i:=2;
<p>
conforms(alsoconforms)
<p>
end.
<p>
</dd>
</dl> <h3><a name="tth_sEc2.6.2">
2.6.2</a> Procedure types</h3>
<p>
Procedural types may be declared. This in turn allows procedure variables.
These store the address of a procedure or function and can be assigned
to using the address operator @.
<p>
<b>Example </b>
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
program procvar;
<p>
type t=procedure (x:integer);
<p>
var v:t;
<p>
procedure f(a:integer);begin writeln(a);end;
<p>
begin
<p>
v:= @f;
<p>
v(3);
<p>
end.
<p>
</dd>
</dl> <h1><a name="tth_chAp3">
Chapter 3 </a><br />Algorithms</h1>
<p>
<h2><a name="tth_sEc3.1">
3.1</a> Expressions<a name="Expressions31">
</a></h2>
<p>
An expression is a rule for computing a value by the application of operators
and functions to other values. These operators can be <em>monadic</em> - taking
a single argument, or <em>dyadic</em> - taking two arguments.
<p>
<h3><a name="tth_sEc3.1.1">
3.1.1</a> Mixed type expressions</h3>
<p>
The arithmetic operators are defined over the base types integer and real. If
a dyadic operator that can take either real<a name="real31">
</a> or integer<a name="integer31">
</a>
arguments is applied to arguments one of which is an integer and the other a
real, the integer argument is first implicitly converted to a real before the
operator is applied. Similarly, if a dyadic operator is applied to two integral
numbers of different precision, the number of lower precision is initially converted
to the higher precisions, and the result is of the higher precision. Higher
precision of types <em>t,u</em> is defined such that the type with the greater
precision is the one which can represent the largest range of numbers. Hence
reals<a name="reals31">
</a> are taken to be higher precision than longints even though
the number of significant bits in a real may be less than in a longint.
<p>
When performing mixed type arithmetic between pixels and another numeric data
type, the values of both types are converted to reals before the arithmetic
is performed. If the result of such a mixed type expression is subsequently
assigned to a pixel<a name="pixel31">
</a> variable, all values greater than 1.0 are
mapped to 1.0 and all values below -1.0 are mapped to -1.0.
<p>
<h3><a name="tth_sEc3.1.2">
3.1.2</a> Primary expressions</h3>
<p>
<center>
<table border="1">
<tr><td align="center"><primary expression> </td><td align="center">'(' <expression> ')'</td></tr>
<tr><td align="center"></td><td align="center"><literal string></td></tr>
<tr><td align="center"></td><td align="center">'true'</td></tr>
<tr><td align="center"></td><td align="center">'false'</td></tr>
<tr><td align="center"></td><td align="center"><unsigned integer></td></tr>
<tr><td align="center"></td><td align="center"><unsigned real></td></tr>
<tr><td align="center"></td><td align="center"><variable></td></tr>
<tr><td align="center"></td><td align="center"><constant id></td></tr>
<tr><td align="center"></td><td align="center"><function call></td></tr>
<tr><td align="center"></td><td align="center"><set construction></td></tr></table>
<p>
</center>The most primitive expressions are instances of the literals defined in the
language: literal strings, boolean literals, literal reals and literal integers.
'Salerno', <tt>true</tt>, 12, $ea8f, 1.2e9 are all primary expressions. The
next level of abstraction is provided by symbolic identifiers for values. <tt>X</tt>,
<tt>left</tt>, <tt>a.max</tt>, <tt>p.next</tt>, <tt>z[1]</tt>,
<tt>image[4..200,100..150]</tt> are all primary expressions provided that
the identifiers have been declared as variables or constants.
<p>
An expression surrounded by brackets <tt>( )</tt> is also a primary expression.
Thus if <em>e</em> is an expression so is <tt>(</tt> <em>e</em> <tt>)</tt>.
<p>
<center>
<table border="1">
<tr><td align="center"><function call></td><td align="center"><function id> [ '(' <expression> [,<expression>]* ')' ]</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><element></td><td align="center"><expression></td></tr>
<tr><td align="center"></td><td align="center"><range expression></td></tr></table>
<p>
</center>Let <em>e</em> be an expression of type t<sub>1</sub> and if <tt>f</tt> is an identifier
of type <tt>function<a name="function31">
</a>( t<sub>1</sub> ): t<sub>2</sub> </tt>, then
<tt>f(</tt> <em>e</em> <tt>)</tt> is a primary expression of type t<sub>2</sub> .
A function which takes no parameters is invoked without following its identifier
by brackets. It will be an error if any of the actual parameters supplied to
a function are incompatible with the formal parameters declared for the function.
<p>
<center>
<table border="1">
<tr><td align="center"><set construction></td><td align="center">'[' [<element>[,<element>]*] ']'</td></tr></table>
<p>
</center>Finally a primary expression may be a set construction. A set construction is
written as a sequence of zero or more elements enclosed in brackets <tt>[
]</tt> and separated by commas. The elements themselves are either expressions
evaluating to single values or range expressions denoting a sequence of consecutive
values. The type of a set construction is deduced by the compiler from the context
in which it occurs. A set construction occurring on the right hand side of an
assignment inherits the type of the variable to which it is being assigned.
The following are all valid set constructions:
<p>
<tt>[], [1..9], [z..j,9], [a,b,c,]</tt>
<p>
<tt>[]</tt> denotes the empty set.
<p>
<h3><a name="tth_sEc3.1.3">
3.1.3</a> Unary expressions</h3>
<p>
A unary expression is formed by applying a unary operator to another unary or
primary expression. The unary operators supported are <tt>+, -, *, /,
div<a name="div31">
</a>, mod<a name="mod31">
</a>, and<a name="and31">
</a>, or<a name="or31">
</a>, not<a name="not31">
</a>,
round<a name="round31">
</a>, sqrt<a name="sqrt31">
</a>, sin<a name="sin31">
</a>, cos<a name="cos31">
</a>, tan<a name="tan31">
</a>,
abs<a name="abs31">
</a>, ln<a name="ln31">
</a>, ord<a name="ord31">
</a>, chr<a name="chr31">
</a>, byte2pixel<a name="pixel31">
</a>,
pixel2byte<a name="byte31">
</a>, succ<a name="succ31">
</a>, pred<a name="pred31">
</a>, iota<a name="iota31">
</a>,
trans<a name="trans31">
</a>, addr<a name="addr31">
</a></tt> and <tt>@</tt><a name="31">
</a>.
<p>
Thus the following are valid unary expressions<tt>: -1</tt>, <tt>+b, not true</tt>, <tt>sqrt
abs x</tt>, <tt>sin theta.</tt><a name="primfns">
</a> In standard Pascal some of these operators are treated as
functions,. Syntactically this means that their arguments must be enclosed in
brackets, as in <tt>sin(theta)</tt>. This usage remains syntactically correct
in Vector Pascal.
<p>
The dyadic operators <tt>+, -, *, /, div, mod , and or</tt> are all extended
to unary context by the insertion of an implicit value under the operation.
Thus just as <tt>-a = 0-a</tt> so too <tt>/2 = 1/2</tt>. For sets the notation
<tt>-s</tt> means the complement of the set <tt>s</tt>. The implicit value inserted
are given below.
<p>
<center>
<table border="1">
<tr><td align="center">type</td><td align="center">operator<tt>s</tt></td><td align="center"><tt>implicit value</tt></td></tr><tr><td>
<tr><td align="center"><tt>number</tt></td><td align="center"><tt>+,-</tt></td><td align="center">0</td></tr>
<tr><td align="center">string</td><td align="center"><tt>+</tt></td><td align="center">''</td></tr>
<tr><td align="center">set<a name="set31">
</a></td><td align="center"><tt>+</tt></td><td align="center">empty set</td></tr>
<tr><td align="center">number</td><td align="center"><tt>*,/ ,div,mod</tt></td><td align="center">1</td></tr>
<tr><td align="center">number</td><td align="center"><tt>max</tt></td><td align="center">lowest representable number of the type</td></tr>
<tr><td align="center">number</td><td align="center"><tt>min</tt></td><td align="center">highest representable number of the type</td></tr>
<tr><td align="center">boolean<a name="boolean31">
</a></td><td align="center"><tt>and</tt></td><td align="center">true</td></tr>
<tr><td align="center">boolean</td><td align="center"><tt>or</tt> </td><td align="center">false</td></tr></table>
<p>
</center>A unary operator can be applied to an array<a name="array31">
</a> argument and returns
an array result. Similarly any user declared function over a scalar<a name="scalar31">
</a>
type can be applied to an array type and return an array. If <tt>f</tt> is a
function or unary operator mapping from type <tt>r</tt> to type <tt>t</tt> then
if <tt>x</tt> is an array of <tt>r,</tt> and <tt>a</tt> an array of <tt>t</tt>,
then <tt>a:=f(x)</tt> assigns an array of <tt>t</tt> such that <tt>a[i]=f(x[i])</tt>
<p>
<p>
<a name="tth_tAb3.1">
</a> <center>Table 3.1: Unary operators</center><a name="tab:unops">
</a>
<center>
<table border="1">
<tr><td align="center"><font size="-1">lhs </font></td><td align="center"><font size="-1">rhs</font></td><td><font size="-1">meaning</font></td></tr>
<tr><td align="center"><font size="-1"><unaryop></font></td><td align="center"><font size="-1">'+'</font></td><td><font size="-1">+x = 0+x identity operator</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'-'</font></td><td><font size="-1">-x = 0-x, </font></td></tr>
<tr><td align="center"></td><td align="center"></td><td><font size="-1">note: this is defined on integer, real and complex</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'*', '×'</font></td><td><font size="-1">*x=1*x identity operator</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'/'</font></td><td><font size="-1">/x=1.0/x </font></td></tr>
<tr><td align="center"></td><td align="center"></td><td><font size="-1">note: this is defined on integer, real and complex</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'div', '<font face="symbol">¸</font
>'</font></td><td><font size="-1">div x =1 div x</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'mod'</font></td><td><font size="-1">mod x = 1 mod x</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'and'</font></td><td><font size="-1">and x = true and x</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'or'</font></td><td><font size="-1">or x = false or x</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'not', '<font face="symbol">Ø</font
>'</font></td><td><font size="-1">complements booleans</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'round'</font></td><td><font size="-1">rounds a real to the closest integer</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'sqrt', '<font face="symbol">Ö</font>{} '</font> </td><td><font size="-1">returns square root as a real<a name="real31">
</a> number.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'sin'</font></td><td><font size="-1">sine of its argument. Argument in radians. Result is real.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'cos'</font></td><td><font size="-1">cosine of its argument. Argument in radians. Result is real.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'tan'</font></td><td><font size="-1">tangent of its argument. Argument in radians. Result is real.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'abs'</font></td><td><font size="-1">if x<0 then abs x = -x else abs x= x</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'ln'</font></td><td><font size="-1"> log<sub>e</sub> of its argument. Result is real.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'ord'</font></td><td><font size="-1">argument scalar type, returns ordinal </font></td></tr>
<tr><td align="center"></td><td align="center"></td><td><font size="-1">number of the argument.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'chr'</font></td><td><font size="-1">converts an integer<a name="integer31">
</a> into a character<a name="character31">
</a>.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'succ'</font></td><td><font size="-1">argument scalar type,</font></td></tr>
<tr><td align="center"></td><td align="center"></td><td><font size="-1">returns the next scalar in the type.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'pred'</font></td><td><font size="-1">argument scalar type, </font></td></tr>
<tr><td align="center"></td><td align="center"></td><td><font size="-1">returns the previous scalar in the type.</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'iota', '<font face="symbol">i</font
>'</font></td><td><font size="-1">iota i returns the ith current index<a name="index31">
</a></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'trans'</font></td><td><font size="-1">transposes a matrix<a name="matrix31">
</a> or vector<a name="vector31">
</a></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'pixel2byte'</font></td><td><font size="-1">convert pixel in range -1.0..1.0 to byte in range 0..255</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'byte2pixel'</font></td><td><font size="-1">convert a byte in range 0..255 to a pixel in</font></td></tr>
<tr><td align="center"></td><td align="center"></td><td><font size="-1">the range -1.0..1.0</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'@','addr'</font></td><td><font size="-1">Given a variable, this returns an</font> </td></tr>
<tr><td align="center"></td><td align="center"></td><td><font size="-1">untyped pointer<a name="pointer31">
</a> to the variable.</font></td></tr></table>
<font size="-1">
<p>
</font></center>
<p>
<center>
<table border="1">
<tr><td align="center"><unary expression></td><td align="center"><unaryop> <unary expression></td></tr>
<tr><td align="center"></td><td align="center">'sizeof' '(' <type> ')'</td></tr>
<tr><td align="center"></td><td align="center"><operator reduction></td></tr>
<tr><td align="center"></td><td align="center"><primary expression></td></tr>
<tr><td align="center"></td><td align="center">'if'<expression> 'then' <expression> 'else' <expression></td></tr></table>
<p>
</center>
<h4>sizeof</h4>
<p>
The construct <tt>sizeof<a name="sizeof31">
</a>(</tt> <em>t</em> <tt>)</tt> where <em>t</em>
is a type, returns the number of bytes<a name="bytes31">
</a> occupied by an instance
of the type.
<p>
<h4>iota<a name="iota">
</a></h4>
<p>
The operator iota i returns the ith current implicit index<a href="#tthFtNtAAH" name="tthFrefAAH"><sup>7</sup></a>.
<p>
<b>Examples </b>
<p>
Thus given the definitions
<p>
<tt>var v1:array[1..3]of integer; </tt>
<p>
<tt>v2:array[0..4] of integer;</tt>
<p>
then the program fragment
<p>
<tt>v1:=iota 0;</tt>
<p>
<tt>v2:=iota 0 *2;</tt>
<p>
<tt></tt><tt>for i:=1 to 3 do write( v1[i]); writeln; </tt>
<p>
<tt>writeln('v2'); </tt>
<p>
<tt>for i:=0 to 4 do write( v2[i]); writeln; </tt>
<p>
would produce the output
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
v1
<p>
1 2 3
<p>
v2
<p>
0 2 4 6 8
</dd>
</dl>
whilst given the definitions
<p>
<tt>m1:array[1..3,0..4] of integer;m2:array[0..4,1..3]of integer;</tt>
<p>
then the program fragment
<p>
<tt>m2:= iota 0 +2*iota 1; </tt>
<p>
<tt>writeln('m2:= iota 0 +2*iota 1 '); </tt>
<p>
<tt>for i:=0 to 4 do begin for j:=1 to 3 do write(m2[i,j]); writeln;
end; </tt>
<p>
would produce the output
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
m2:= iota 0 +2*iota 1
<p>
2 4 6
<p>
3 5 7
<p>
4 6 8
<p>
5 7 9
<p>
6 8 10
</dd>
</dl>
The argument to <tt>iota</tt><a name="iota31">
</a> must be an integer known at compile
time within the range of implicit indices in the current context. The reserved
word <tt>ndx<a name="ndx31">
</a></tt> is a synonym for <tt>iota</tt>.
<p>
<b>perm </b>
<p>
A generalised permutation of the implicit indices is performed using the syntactic
form:
<p>
<blockquote><tt>perm</tt><tt>[</tt><tt><i>index-sel[,index-sel]* ]expression </i></tt>
</blockquote>
The <i>index-sel</i>s are integers known at compile time which specify a permutation
on the implicit indices. Thus in e evaluated in context <tt>perm</tt><tt>[ i,j,k ] e </tt>,
then:
<p>
<blockquote><tt>iota 0 = iota</tt> <tt> i, </tt> <tt>iota 1= iota</tt> <tt> j, </tt>
<tt>iota 2= iota</tt> <tt> k </tt>
</blockquote>
This is particularly useful in converting between different image formats. Hardware
frame buffers typically represent images with the pixels in the red, green,
blue, and alpha channels adjacent in memory. For image processing it is convenient
to hold them in distinct planes. The <tt>perm</tt> operator provides a concise
notation for translation between these formats:
<pre>
type rowindex=0..479;
colindex=0..639;
var channel=red..alpha;
screen:array[rowindex,colindex,channel] of pixel;
img:array[channel,colindex,rowindex] of pixel;
...
screen:=perm[2,0,1]img;
</pre>
<p>
<tt>trans<a name="trans31">
</a></tt> and <tt>diag</tt> <a name="diag">
</a> provide shorthand
notions for expressions in terms of <tt>perm</tt><a name="perm31">
</a>. Thus in an assignment
context of rank 2, <tt>trans = perm[1,0]</tt> and <tt>diag = perm[0,0]</tt>.
<p>
<h4>trans</h4>
<p>
The operator trans<a name="trans31">
</a> transposes a vector or matrix. It achieves
this by cyclic rotation of the implicit indices<a name="indices31">
</a><a name="implicit indices31">
</a>.
Thus if <tt>trans</tt> <em>e</em> is evaluated in a context with implicit indices
<p>
<tt>iota</tt> <em>0</em>.. <tt>iota</tt> <em>n </em>
<p>
then the expression e is evaluated in a context with implicit indices
<p>
<tt>iota</tt>'<em>0</em>.. <tt>iota</tt>'<em>n</em>
<p>
where
<p>
<tt>iota</tt>'<em>x</em> = <tt>iota</tt> ( (<em>x+1</em>)<tt>mod</tt> <em>n+1</em>)
<p>
It should be noted that transposition is generalised to arrays of rank greater
than 2.
<p>
<b>Examples </b>
<p>
Given the definitions used above in section <a href="#iota">3.1.3</a>, the program fragment:
<p>
<tt>m1:= (trans v1)*v2; </tt>
<p>
<tt>writeln('(trans v1)*v2'); </tt>
<p>
<tt>for i:=1 to 3 do begin for j:=0 to 4 do write(m1[i,j]); writeln;
end; </tt>
<p>
<tt>m2 := trans m1; </tt>
<p>
<tt>writeln('transpose 1..3,0..4 matrix'); </tt>
<p>
<tt>for i:=0 to 4 do begin for j:=1 to 3 do write(m2[i,j]); writeln;
end;</tt>
<p>
will produce the output:
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
(trans v1)*v2
<p>
0 2 4 6 8
<p>
0 4 8 12 16
<p>
0 6 12 18 24
<p>
transpose 1..3,0..4 matrix
<p>
0 0 0
<p>
2 4 6
<p>
4 8 12
<p>
6 12 18
<p>
8 16 24
</dd>
</dl>
<p>
<h3><a name="tth_sEc3.1.4">
3.1.4</a> Operator Reduction</h3>
<p>
Any dyadic operator can be converted to a monadic<a name="monadic31">
</a> reduction<a name="reduction31">
</a>
operator by the functional . Thus if <tt>a</tt> is an array,
<tt>+a</tt> denotes the sum over the array. More generally \<font face="symbol">F</font
>x
for some dyadic operator <font face="symbol">F</font
> means x<sub>0</sub><font face="symbol">F</font
>(x<sub>1</sub><font face="symbol">F</font
>..(x<sub>n</sub><font face="symbol">F</font
><font face="symbol">i</font
>))
where <font face="symbol">i</font
> is the implicit value given the operator and the type. Thus
we can write <tt>+</tt> for summation, <tt>*</tt> for nary product
etc. The dot product of two vectors can thus be written as
<pre>
x:= \+ y*x;
</pre>
<p>
instead of
<p>
<tt>x:=0;</tt>
<p>
<tt>for i:=0 to n do x:= x+ y[i]*z[i];</tt>
<p>
A reduction operation takes an argument of rank<a name="rank31">
</a> <em>r</em> and returns
an argument of rank <em>r-1</em> except in the case where its argument is of rank
0, in which case it acts as the identity operation. Reduction is always performed
along the last array<a name="array31">
</a> dimension<a name="dimension31">
</a> of its argument.
<p>
The operations of summation and product can be be written eithter as the two
functional forms \ +
and \ * or as the prefix operators <font face="symbol">å</font
> (Unicode 2211) and <font face="symbol">Õ</font
> (Unicode 220f).
<p>
<center>
<table border="1">
<tr><td align="center"><operator reduction></td><td align="center">''<dyadic op> <multiplicative expression></td></tr>
<tr><td align="center"></td><td align="center">'<font face="symbol">å</font
>' <mutliplicative expression></td></tr>
<tr><td align="center"></td><td align="center">'<font face="symbol">Õ</font
>' < multiplicative expression></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><dyadic op></td><td align="center"><expop></td></tr>
<tr><td align="center"></td><td align="center"><multop></td></tr>
<tr><td align="center"></td><td align="center"><addop></td></tr></table>
<p>
</center>The reserved word <tt>rdu<a name="rdu31">
</a></tt> is available as a lexical alternative
to , so + is equivalent to <tt>rdu</tt>+.
<p>
<h3><a name="tth_sEc3.1.5">
3.1.5</a> Complex conversion</h3>
<p>
Complex<a name="Complex31">
</a> numbers can be produced from reals using the function
<tt>cmplx</tt><a name="cmplx31">
</a>. <tt>cmplx(</tt><em>re,im</em><tt>)</tt> is the complex
number with real part <em>re</em>, and imaginaray part <em>im</em>.
<p>
The real and imaginary parts of a complex number can be obtained by the functions
<tt>re</tt> and <tt>im</tt>. <tt>re</tt>(<em>c</em>) is the real part of the complex
number <em>c</em>. <tt>im</tt>(<em>c</em>) is the imaginary part of the complex
number <em>c</em>.
<p>
<h3><a name="tth_sEc3.1.6">
3.1.6</a> Conditional expressions</h3>
<p>
The conditional expression allows two different values to be returned depenent
upon a boolean expression.
<p>
<pre>
var a:array[0..63] of real;
...
a:=if a>0 then a else -a;
...
</pre>
<p>
The <tt>if</tt> expression can be compiled in two ways:
<p>
<ol type="1"><p>
<li> Where the two arms of the if expression are parallelisable, the condition and
both arms are evaluated and then merged under a boolean mask. Thus, the above
assignment would be equivalent to:
<p>
<tt>a:= (a and (a > 0))or(not (a > 0) and -a);</tt>
<p>
were the above legal Pascal<a href="#tthFtNtAAI" name="tthFrefAAI"><sup>8</sup></a>.</li>
<p>
<li> If the code is not paralleliseable it is translated as equivalent to a standard
if statement. Thus, the previous example would be equivalent to:
<p>
<tt>for i:=0 to 63 do if a[i] > 0 then a[i]:=a[i] else
a[i]:=-a[i];</tt>
<p>
Expressions are non parallelisable if they include function calls.</li>
</ol>
The dual compilation strategy allows the same linguistic construct to be used
in recursive function definitions and parallel data selection.
<p>
<h4>Use of boolean mask vectors</h4>
In array programming many operations can be efficiently be expressed in terms
of boolean mask vectors.
Given the declarations:
<pre>
i:array[1..4] of integer;
r:array[1..4] of real;
c:array[1..4] of complex;
b:array[1..4] of boolean;
s:array[1..4] of string;
</pre>
and if
<p>
<h3><a name="tth_sEc3.1.7">
3.1.7</a> Factor<a name="Factor31">
</a></h3>
<p>
A factor is an expression that optionally performs exponentiation. Vector Pascal
supports exponentiation either by integer exponents or by real exponents. A
number <em>x</em> can be raised to an integral power <em>y</em> by using the construction
<em>x</em> <tt>pow<a name="pow31">
</a></tt> <em>y</em>. A number can be raised to an arbitrary
real power by the <tt>**</tt> operator. The result of <tt>**<a name="**31">
</a></tt>
is always real valued.
<p>
<center>
<table border="1">
<tr><td align="center"><expop></td><td align="center">'pow'</td></tr>
<tr><td align="center"></td><td align="center">'**'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><factor></td><td align="center"><unary expression> [ <expop> <unary expression>]</td></tr></table>
<p>
</center> <h3><a name="tth_sEc3.1.8">
3.1.8</a> Multiplicative expressions</h3>
<p>
Multiplicative expressions consist of factors linked by the multiplicative operators
<tt>*, ×, /, div, <font face="symbol">¸</font
>,<a name="div31">
</a>, mod<a name="mod31">
</a>, shr<a name="shr31">
</a>, shl<a name="shl31">
</a>
and</tt><a name="and31">
</a>. The use of these operators is summarised in table <a href="#multop">3.2</a>.
<p>
<p>
<a name="tth_tAb3.2">
</a> <center>Table 3.2: Multiplicative operators<a name="multop">
</a></center>
<center>
<table>
<tr><td align="center"><font size="-1">Operator</font></td><td align="center"><font size="-1">Left</font></td><td align="center"><font size="-1">Right</font></td><td align="center"><font size="-1">Result</font></td><td align="center"><font size="-1">Effect of</font> <em><font size="-1">a</font></em> <tt><font size="-1">op</font></tt> <em><font size="-1">b</font></em><font size="-1"></font></td></tr>
<tr><td align="center"><tt><font size="-1">*, ×</font></tt><font size="-1"></font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">multiply</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">real</font></td><td align="center"><font size="-1">real</font></td><td align="center"><font size="-1">real</font></td><td align="center"><font size="-1">multiply</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">complex</font></td><td align="center"><font size="-1">complex</font></td><td align="center"><font size="-1">complex</font></td><td align="center"><font size="-1">multiply</font></td></tr>
<tr><td align="center"><tt><font size="-1">/</font></tt><font size="-1"></font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">real</font></td><td align="center"><font size="-1">division</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">real</font></td><td align="center"><font size="-1">real</font></td><td align="center"><font size="-1">real</font></td><td align="center"><font size="-1">division</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">complex</font></td><td align="center"><font size="-1">complex</font></td><td align="center"><font size="-1">complex</font></td><td align="center"><font size="-1">division</font></td></tr>
<tr><td align="center"><tt><font size="-1">div, <font face="symbol">¸</font
></font></tt><font size="-1"></font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">division</font></td></tr>
<tr><td align="center"><tt><font size="-1">mod</font></tt><font size="-1"></font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">remainder</font></td></tr>
<tr><td align="center"><tt><font size="-1">and</font></tt><font size="-1"></font></td><td align="center"><font size="-1">boolean</font></td><td align="center"><font size="-1">boolean</font></td><td align="center"><font size="-1">boolean</font></td><td align="center"><font size="-1">logical and</font></td></tr>
<tr><td align="center"><tt><font size="-1">shr</font></tt><font size="-1"></font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">shift</font> <em><font size="-1">a</font></em> <font size="-1">by</font> <em><font size="-1">b</font></em> <font size="-1">bits right</font></td></tr>
<tr><td align="center"><tt><font size="-1">shl</font></tt><font size="-1"></font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">integer</font></td><td align="center"><font size="-1">shift</font> <em><font size="-1">a</font></em> <font size="-1">by</font> <em><font size="-1">b</font></em> <font size="-1">bits left</font></td></tr>
<tr><td align="center"><tt><font size="-1">in, <font face="symbol">Î</font
> </font></tt><font size="-1"></font></td><td align="center"><em><font size="-1">t</font></em><font size="-1"></font></td><td align="center"><tt><font size="-1">set of</font></tt> <em><font size="-1">t</font></em><font size="-1"></font></td><td align="center"><font size="-1">boolean</font></td><td align="center"><font size="-1">true if</font> <em><font size="-1">a</font></em> <font size="-1">is member of</font> <em><font size="-1">b</font></em></td></tr></table>
<font size="-1">
<p>
</font></center>
<p>
<center>
<table border="1">
<tr><td align="center"><multop></td><td align="center">'*'</td></tr>
<tr><td align="center"></td><td align="center">'×'</td></tr>
<tr><td align="center"></td><td align="center">'/'</td></tr>
<tr><td align="center"></td><td align="center">'div'</td></tr>
<tr><td align="center"></td><td align="center">'<font face="symbol">¸</font
>'</td></tr>
<tr><td align="center"></td><td align="center">'shr'</td></tr>
<tr><td align="center"></td><td align="center">'shl'</td></tr>
<tr><td align="center"></td><td align="center">'and'</td></tr>
<tr><td align="center"></td><td align="center">'mod'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><multiplicative expression></td><td align="center"><factor> [ <multop> <factor> ]*</td></tr>
<tr><td align="center"></td><td align="center"><factor>'in'<multiplicative expression></td></tr></table>
<p>
</center> <h3><a name="tth_sEc3.1.9">
3.1.9</a> Additive expressions</h3>
<p>
An additive expression allows multiplicative expressions to be combined using
the addition operators <tt>+<a name="+31">
</a>, -<a name="-31">
</a>, or, +:<a name="+:31">
</a><a name="or31">
</a>,max<a name="max31">
</a>,
min<a name="min31">
</a>, -:</tt><a name="-:31">
</a>,
<tt>><</tt><a name="\verb+><+31">
</a>. The additive operations are summarised in table<a href="#addops">3.3</a>
.
<p>
<p>
<a name="tth_tAb3.3">
</a> <center>Table 3.3: Addition operations<a name="addops">
</a></center>
<center>
<table>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">Left</font></td><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">Right</font></td><td align="center"><font size="-1">Result</font></td><td align="center"><font size="-1">Effect of</font> <em><font size="-1">a</font></em> <tt><font size="-1">op</font></tt> <em><font size="-1">b</font></em><font size="-1"></font></td></tr><tr><td>
<tr><td align="center"><tt><font size="-2">+</font></tt><font size="-2"></font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2">sum of</font> <em><font size="-2">a</font></em> <font size="-2">and</font> <em><font size="-2">b</font></em><font size="-2"></font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2">sum of</font> <em><font size="-2">a</font></em> <font size="-2">and</font> <em><font size="-2">b</font></em><font size="-2"></font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">complex</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">complex</font></td><td align="center"><font size="-2">complex</font></td><td align="center"><font size="-2">sum of</font> <em><font size="-2">a</font></em> <font size="-2">and</font> <em><font size="-2">b</font></em><font size="-2"></font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2">union of</font> <em><font size="-2">a</font></em> <font size="-2">and</font> <em><font size="-2">b</font></em><font size="-2"></font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">string</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">string</font></td><td align="center"><font size="-2">string</font></td><td align="center"><font size="-2">concatenate<a name="concatenate31">
</a></font> <em><font size="-2">a</font></em> <font size="-2">with</font>
<em><font size="-2">b</font></em> <font size="-2">'ac'+'de'='acde'</font></td></tr>
<tr><td align="center"><tt><font size="-2">-</font></tt><font size="-2"></font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2">result of subtracting</font> <em><font size="-2">b</font></em> <font size="-2">from</font>
<em><font size="-2">a</font></em><font size="-2"></font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2">result of subtracting</font> <em><font size="-2">b</font></em> <font size="-2">from</font>
<em><font size="-2">a</font></em><font size="-2"></font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">complex</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">complex</font></td><td align="center"><font size="-2">complex</font></td><td align="center"><font size="-2">result of subtracting</font> <em><font size="-2">b</font></em> <font size="-2">from</font>
<em><font size="-2">a</font></em><font size="-2"></font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2">complement<a name="complement31">
</a> of</font> <em><font size="-2">b</font></em> <font size="-2">relative
to</font> <em><font size="-2">a</font></em><font size="-2"></font></td></tr>
<tr><td align="center"><tt><font size="-2">+:</font></tt><font size="-2"></font></td><td align="center"><font size="-2">0..255</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">0..255</font></td><td align="center"><font size="-2">0..255</font></td><td align="center"><font size="-2">saturated + clipped to 0..255 </font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">-128..127</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">-128..127</font></td><td align="center"><font size="-2">-128..127</font></td><td align="center"><font size="-2">saturated + clipped to -128..127</font></td></tr>
<tr><td align="center"><tt><font size="-2">-:</font></tt><font size="-2"></font></td><td align="center"><font size="-2">0..255</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">0..255</font></td><td align="center"><font size="-2">0..255</font></td><td align="center"><font size="-2">saturated<a name="saturated31">
</a> - clipped to 0..255</font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">-128..127</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">-128..127</font></td><td align="center"><font size="-2">-128..127</font></td><td align="center"><font size="-2">saturated - clipped to -128..127</font></td></tr>
<tr><td align="center"><tt><font size="-2">min<a name="min31">
</a></font></tt><font size="-2"></font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2">returns the lesser of the numbers</font></td></tr>
<tr><td align="center"></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2">returns the lesser of the numbers</font></td></tr>
<tr><td align="center"><tt><font size="-2">max<a name="max31">
</a></font></tt><font size="-2"></font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2">integer</font></td><td align="center"><font size="-2">returns the greater of the numbers</font></td></tr>
<tr><td align="center"></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2">real</font></td><td align="center"><font size="-2">returns the greater of the numbers</font></td></tr>
<tr><td align="center"><tt><font size="-2">or</font></tt><font size="-2"></font></td><td align="center"><font size="-2">boolean</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">boolean</font></td><td align="center"><font size="-2">boolean</font></td><td align="center"><font size="-2">logical or</font></td></tr>
<tr><td align="center"> <tt>><</tt></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2">set</font></td><td align="center"><font size="-2">symetric difference</font></td></tr></table>
<font size="-2">
<p>
</font></center>
<p>
<center>
<table border="1">
<tr><td align="center"><font size="-2"><addop></font></td><td align="center"><font size="-2">'+'</font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">'-'</font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">'or'</font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">'max'</font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">'min'</font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">'+:'</font></td></tr>
<tr><td align="center"><font size="-2"></font></td><td align="center"><font size="-2">'-:'</font></td></tr></table>
<font size="-2">
<p>
</font></center><center>
<table border="1">
<tr><td align="center"><font size="-2"><additive expression></font></td><td align="center"><font size="-2"><multiplicative expression> [ <addop> <multiplicative expression>
]*</font></td></tr></table>
<font size="-2">
<p>
</font></center><center>
<table border="1">
<tr><td align="center"><font size="-2"><expression></font></td><td align="center"><font size="-2"><additive expression> <relational operator> <expression></font></td></tr></table>
<font size="-2">
<p>
</font></center> <h3><a name="tth_sEc3.1.10">
3.1.10</a> Expressions</h3>
An expression can optionally involve the use of a relational operator
to compare the results of two additive expressions. Relational operators
always return boolean results and are listed in table <a href="#relop">3.4</a>.
<p>
<a name="tth_tAb3.4">
</a> <center>Table 3.4: Relational operators</center><a name="relop">
</a>
<table>
<tr><td align="center"><tt><</tt></td><td align="center">Less than</td></tr>
<tr><td align="center"><tt>></tt></td><td align="center">Greater than</td></tr>
<tr><td align="center"><tt><=</tt></td><td align="center">Less than or equal to</td></tr>
<tr><td align="center"><tt>>=</tt></td><td align="center">Greater than or equal to</td></tr>
<tr><td align="center"><tt><></tt> </td><td align="center">Not equal to</td></tr>
<tr><td align="center"><tt>=</tt></td><td align="center">Equal to</td></tr></table>
<p>
<p>
<h3><a name="tth_sEc3.1.11">
3.1.11</a> Operator overloading</h3>
<p>
The dyadic operators<a name="operator31">
</a>
<a name="operator, overloadin31">
</a> can be extended to operate on new types by operator overloading.
Figure <a href="#complex">3.1</a> shows how arithmetic on the type <tt>complex</tt> required
by Extended Pascal [<a href="#ISO90" name="CITEISO90">15</a>] is defined in Vector Pascal. Each operator
is associated with a semantic function and
if it is a non-relational operator,
an identity element. The operator
symbols must be drawn from the set of predefined Vector Pascal operators, and
when expressions involving them are parsed, priorities are inherited from the
predefined operators. The type signature of the operator is deduced from the
type of the function<a href="#tthFtNtAAJ" name="tthFrefAAJ"><sup>9</sup></a>.
<p>
<center>
<table border="1">
<tr><td align="center"><font size="-2"><operator-declaration></font></td><td align="center"><font size="-2">'operator' 'cast' '=' <identifier></font></td></tr>
<tr><td align="center"></td><td align="center"><font size="-2">'operator' <dyadicop> '=' <identifier>','<identifier></font></td></tr>
<tr><td align="center"></td><td align="center"><font size="-2">'operator' <relational operator> '=' <identifier></font></td></tr></table>
<font size="-2">
<p>
</font></center>
<p>
<a name="tth_fIg3.1">
</a> <font size="-1">***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯
<br /><table align="left" border="0"><tr><td width="553">
<tt>interface </tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt>type </tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt>Complex = record data : array [0..1] of real ;</tt></td></tr></table><!--hbox-->
<br />\<<br /><table align="left" border="0"><tr><td width="553">
<tt>end ;</tt></td></tr></table><!--hbox-->
<br /><br />\<<br /><table align="left" border="0"><tr><td width="553">
<tt>var </tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt> complexzero, complexone : complex;</tt></td></tr></table><!--hbox-->
<br /><br />\<<tt>function real2cmplx
( realpart :real ):complex ;</tt> <br />
\<<tt>function cmplx
( realpart ,imag :real ):complex ;</tt> <br />
\<<tt>function complex_add
( A ,B :Complex ):complex ;</tt> <br />
\<<tt>function complex_conjugate
( A :Complex ):complex ;</tt> <br />
\<<tt>function complex_subtract
( A ,B :Complex ):complex ;</tt> <br />
\<<tt>function complex_multiply
( A ,B :Complex ):complex ;</tt> <br />
\<<tt>function complex_divide
( A ,B :Complex ):complex ;</tt> <br />
<br /><table align="left" border="0"><tr><td width="553">
<tt><font size="-1">{ Standard operators on complex numbers }</font></tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt><font size="-1">{ symbol function identity element }</font></tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt>operator + = Complex_add , complexzero ;</tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt>operator / = complex_divide , complexone ;</tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt>operator * = complex_multiply , complexone ;</tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt>operator - = complex_subtract , complexzero ;</tt></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<tt>operator cast = real2cmplx ;</tt></td></tr></table><!--hbox-->
<br /><br /></font>
<center>Figure 3.1: Defining operations on complex numbers</center>
<p>
<a name="complex">
</a><font size="-1">Note that only the function headers are given here as
this code comes from the interface part of the system unit. The function bodies
and the initialisation of the variables complexone and complexzero are handled
in the implementation part of the unit.</font><font size="-1">
<p>
</font>
<p>
When parsing expressions, the compiler first tries to resolve operations in
terms of the predefined operators of the language, taking into account the standard
mechanisms allowing operators to work on arrays. Only if these fail does it
search for an overloaded operator whose type signature matches the context.
<p>
In the example in figure <a href="#complex">3.1</a>, complex numbers are defined to be records
containing an array of reals, rather than simply as an array of reals. Had they
been so defined, the operators <tt>+,*,-,/</tt> on reals would have masked
the corresponding operators on complex numbers.
<p>
The provision of an identity element for complex addition and subtraction ensures
that unary minus, as in <font face="symbol">-</font
>x for x: complex, is well defined, and
correspondingly that unary / denotes complex reciprocal. Overloaded operators
can be used in array maps and array reductions.
<p>
<h4>Implicit casts</h4><a name="cast31">
</a>
The Vector Pascal language already contains a number of implicit type
conversions that are context determind. An example is the promotion of
integers to reals in the context of arithmetic expressions. The set of
implicit casts can be added to by declaring an operator to be a cast
as is shown in the line:
<p>
<table align="left" border="0"><tr><td width="553">
<tt><i>operator</i> <i>cast</i> = <i>real2cmplx</i> ;</tt></td></tr></table><!--hbox-->
<br clear="all" /><br />Given an implict cast from type t<sub>0</sub><font face="symbol">®</font
> t<sub>1</sub>,
the function associated with the implicit cast is then called
on the result
of any expression e:t<sub>0</sub> whose expression context requires
it to be of type t<sub>1</sub>.
<h2><a name="tth_sEc3.2">
3.2</a> Statements</h2>
<p>
<center>
<table border="1">
<tr><td align="center"><statement></td><td align="center"><font size="-1"><variable>':='<expression></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1"><procedure statement></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1"><empty statement></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'goto' <label>;</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'exit'['('<expression>')']</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'begin' <statement>[;<statement>]*'end'</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'if'<expression>'then'<statement>['else'<statement>]</font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1"><case statement></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'for' <variable>:= <expression> 'to' <expression> 'do' <statement></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'for' <variable>:= <expression> 'downto' <expression> 'do' <statement></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'repeat' <statement> 'until' <expression></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'with' <record variable> 'do' < statement></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1"><io statement></font></td></tr>
<tr><td align="center"><font size="-1"></font></td><td align="center"><font size="-1">'while' <expression> 'do' <statement></font></td></tr></table>
<font size="-1">
<p>
</font></center> <h3><a name="tth_sEc3.2.1">
3.2.1</a> Assignment<a name="assignment">
</a></h3>
<p>
An assignment replaces the current value of a variable by a new value specified
by an expression. The assignment operator<a name="operator32">
</a> is<a name="is32">
</a> :=<a name=":=32">
</a>.
Standard Pascal allows assignment<a name="assignment32">
</a> of whole arrays<a name="array32">
</a>.
Vector Pascal extends this to allow consistent use of mixed rank<a name="rank32">
</a>
expressions on the right hand side of an assignment. Given
<p>
<tt>r0:real; r1:array[0..7] of real; </tt>
<p>
<tt>r2:array[0..7,0..7] of real</tt>
<p>
then we can write
<p>
<ol type="1"><p>
<li> r<tt>1:= r2[3]; { supported in standard Pascal }</tt></li>
<p>
<li> <tt>r1:= /2; { assign 0.5 to each element of r1 }</tt></li>
<p>
<li> <tt>r2:= r1*3; { assign 1.5 to every element of r2}</tt></li>
<p>
<li> <tt>r1:= + r2; { r1 gets the totals along the rows of r2}</tt></li>
<p>
<li> <tt>r1:= r1+r2[1];{ r1 gets the corresponding elements of row 1 of
r2 added to it}</tt></li>
</ol>
The assignment of arrays is a generalisation of what standard Pascal allows.
Consider the first examples above, they are equivalent to:
<p>
<ol type="1"><p>
<li> <tt>for i:=0 to 7 do r1[i]:=r2[3,i];</tt></li>
<p>
<li> <tt>for i:=0 to 7 do r1[i]:=/2;</tt></li>
<p>
<li> <tt>for i:=0 to 7 do
<p>
for j:=0 to 7 do r2[i,j]:=r1[j]*3;</tt></li>
<p>
<li> <tt>for i:=0 to 7 do
<p>
begin
<p>
t:=0;
<p>
for j:=7 downto 0 do t:=r2[i,j]+t;
<p>
r1[i]:=t;
<p>
end;</tt></li>
<p>
<li> <tt>for i:=0 to 7 do r1[i]:=r1[i]+r2[1,i];</tt></li>
</ol>
In other words the compiler has to generate an implicit loop<a name="loop32">
</a> over
the elements of the array being assigned to and over the elements of the array
acting as the data-source. In the above <tt>i,j,t</tt> are assumed to be temporary
variables not referred to anywhere else in the program. The loop variables are
called implicit indices<a name="indices32">
</a><a name="implicit indices32">
</a> <a name="manimplicitindices">
</a>and
may be accessed using <tt>iota</tt>.
<p>
The variable on the left hand side of an assignment defines an array<a name="array32">
</a>
context within which expressions on the right hand side are evaluated. Each
array context has a rank given by the number of dimensions<a name="dimensions32">
</a>
of the array on the left hand side. A scalar variable has rank<a name="rank32">
</a>
0. Variables occurring in expressions with an array context of rank <em>r</em>
must have <em>r</em> or fewer dimensions. The <em>n</em> bounds of any <em>n</em>
dimensional array variable, with n <font face="symbol">£</font
> r occurring within an expression
evaluated in an array context of rank <em>r</em> must match with the rightmost
<em>n</em> bounds of the array on the left hand side of the assignment statement.
<p>
Where a variable is of lower rank than its array context, the variable is replicated
to fill the array context<a name="array context32">
</a>. This is shown in examples 2
and 3 above. Because the rank of any assignment is constrained by the variable
on the left hand side, no temporary arrays, other than machine registers, need
be allocated to store the intermediate array results of expressions.
<p>
<h3><a name="tth_sEc3.2.2">
3.2.2</a> Procedure statement</h3>
<p>
A procedure statement executes a named procedure<a name="procedure32">
</a>. A procedure
statement may, in the case where the named procedure has formal parameters,
contain a list of actual parameters. These are substituted in place of the formal
parameters contained in the declaration. Parameters may be value parameters
or variable parameters.
<p>
Semantically the effect of a value parameter is that a copy is taken of the
actual parameter<a name="parameter32">
</a> and this copy substituted into the body of
the procedure. Value parameters may be structured values such as records and
arrays. For scalar values, expressions may be passed as actual parameters. Array
expressions are not currently allowed as actual parameters.
<p>
A variable parameter is passed by reference, and any alteration of the formal
parameter induces a corresponding change in the actual parameter. Actual variable
parameters must be variables.
<p>
<center>
<table border="1">
<tr><td align="center"><parameter></td><td align="center"><variable></td><td align="center">for formal parameters declared as var</td></tr>
<tr><td align="center"></td><td align="center"><expression></td><td align="center">for other formal parameters </td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><procedure statement></td><td align="center"><identifier></td></tr>
<tr><td align="center"></td><td align="center"><identifier> '(' <parameter> [','<parameter>]* ')'</td></tr></table>
<p>
</center>
<b>Examples </b>
<p>
<ol type="1"><p>
<li> <tt>printlist;</tt></li>
<p>
<li> <tt>compare(avec,bvec,result);</tt></li>
</ol>
<p>
<h3><a name="tth_sEc3.2.3">
3.2.3</a> Goto statement</h3>
<p>
A goto statement transfers control to a labelled statement. The destination
label must be declared in a label<a name="label32">
</a> declaration. It is illegal to
jump into or out of a procedure.
<p>
<b>Example </b>
<p>
<tt>goto<a name="goto32">
</a> 99;</tt>
<p>
<h3><a name="tth_sEc3.2.4">
3.2.4</a> Exit<a name="Exit32">
</a> Statement</h3>
<p>
An exit statement transfers control to the calling point of the current procedure
or function. If the exit statement is within a function then the exit statement
can have a parameter: an expression whose value is returned from the function.
<p>
<b>Examples </b>
<p>
<ol type="1"><p>
<li> <tt>exit;</tt></li>
<p>
<li> <tt>exit(5);</tt></li>
</ol>
<p>
<h3><a name="tth_sEc3.2.5">
3.2.5</a> Compound statement</h3>
<p>
A list of statements separated by semicolons may be grouped into a compound
statement by bracketing them with <tt>begin</tt> and <tt>end</tt> .
<p>
<b>Example </b>
<p>
<tt>begin<a name="begin32">
</a> a:=x*3; b:=sqrt a end<a name="end32">
</a>;</tt>
<p>
<h3><a name="tth_sEc3.2.6">
3.2.6</a> If statement</h3>
<p>
The basic control flow construct is the if statement. If the boolean expression
between <tt>if<a name="if32">
</a></tt> and <tt>then<a name="then32">
</a></tt> is true then the
statement following <tt>then</tt> is followed. If it is false and an else part
is present, the statement following <tt>else<a name="else32">
</a></tt> is executed.
<p>
<h3><a name="tth_sEc3.2.7">
3.2.7</a> Case statement</h3>
<p>
The case<a name="case32">
</a> statement specifies an expression which is evaluated and
which must be of integral or ordinal type. Dependent upon the value of the expression
control transfers to the statement labelled by the matching constant.
<p>
<center>
<table border="1">
<tr><td align="center"><case statement></td><td align="center">'case'<expression>'of'<case actions>'end'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><case actions></td><td align="center"><case list></td></tr>
<tr><td align="center"></td><td align="center"><case list> 'else' <statement></td></tr>
<tr><td align="center"></td><td align="center"><case list> 'otherwise' <statement></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><case list></td><td align="center"><case list element>[';'<case list element.]*</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><case list element></td><td align="center"><case label>[',' <case label>]':'<statement></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><case label></td><td align="center"><constant></td></tr>
<tr><td align="center"></td><td align="center"><constant> '..' <constant></td></tr></table>
<p>
</center>
<b>Examples </b>
<p>
<table>
<tr><td><tt>case</tt> i <tt>of</tt></td><td><tt>case</tt> c <tt>of</tt></td></tr>
<tr><td><tt>1:s:=abs s;</tt></td><td><tt>'a':write('A');</tt></td></tr>
<tr><td><tt>2:s:= sqrt s;</tt></td><td><tt>'b','B':write('B');</tt></td></tr>
<tr><td><tt>3: s:=0</tt></td><td><tt>'A','C'..'Z','c'..'z':write(' ');</tt></td></tr>
<tr><td><tt>end</tt></td><td><tt>end</tt></td></tr></table>
<p>
<h3><a name="tth_sEc3.2.8">
3.2.8</a> With statement</h3>
<p>
Within the component statement of the with<a name="with32">
</a> statement the fields
of the record variable can be referred to without prefixing them by the name
of the record variable. The effect is to import the component statement into
the scope defined by the record<a name="record32">
</a> variable declaration so that
the field-names appear as simple variable names.
<p>
<b>Example </b>
<p>
<tt>var s:record x,y:real end;</tt>
<p>
<tt>begin</tt>
<p>
<tt>with s do begin x:=0;y:=1 end ;</tt>
<p>
<tt>end</tt>
<p>
<h3><a name="tth_sEc3.2.9">
3.2.9</a> For statement</h3>
<p>
A for<a name="for32">
</a> statement executes its component statement repeatedly under
the control of an iteration<a name="iteration32">
</a> variable. The iteration variable
must be of an integral or ordinal type. The variable is either set to count
up through a range or down through a range.
<p>
<tt>for i:= e1 to<a name="to32">
</a> e2 do s</tt>
<p>
is equivalent to
<p>
<tt>i:=e1; temp:=e2;while i<=temp do s;</tt>
<p>
whilst
<p>
<tt>for i:= e1 downto<a name="downto32">
</a> e2 do s</tt>
<p>
is equivalent to
<p>
<tt>i:=e1; temp:=e2;while i>= temp do s;</tt>
<p>
<h3><a name="tth_sEc3.2.10">
3.2.10</a> While statement</h3>
<p>
A while<a name="while32">
</a> statement executes its component statement whilst its
boolean expression is true. The statement
<p>
<tt>while e do s</tt>
<p>
is equivalent to
<p>
<tt>10: if not e then goto 99; s; goto 10; 99:</tt>
<p>
<h3><a name="tth_sEc3.2.11">
3.2.11</a> Repeat statement</h3>
<p>
A repeat<a name="repeat32">
</a> statement executes its component statement at least
once, and then continues to execute the component statement until its component
expression becomes true.
<p>
<tt>repeat s until e</tt>
<p>
is equivalent to
<p>
<tt>10: s;if e then goto 99; goto 10;99:</tt>
<p>
<h2><a name="tth_sEc3.3">
3.3</a> Input Output </h2>
<p>
<center>
<table border="1">
<tr><td align="center"><io statement></td><td align="center">'writeln'[<outparamlist>]</td></tr>
<tr><td align="center"></td><td align="center">'write'<outparamlist></td></tr>
<tr><td align="center"></td><td align="center">'readln'[<inparamlist>]</td></tr>
<tr><td align="center"></td><td align="center">'read'<inparamlist></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><outparamlist></td><td align="center">'('<outparam>[','<outparam>]*')'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><outparam></td><td align="center"><expression>[':' <expression>] [':'<expression>] </td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><inparamlist></td><td align="center">'('<variable>[','<variable>]*')'</td></tr></table>
<p>
</center>Input and output are supported from and to the console and also from and to
files.
<p>
<h3><a name="tth_sEc3.3.1">
3.3.1</a> Input</h3>
<p>
The basic form of input is the <tt>read</tt> statement. This takes a list of
parameters the first of which may optionally be a file variable. If this file
variable is present it is the input file. In the absence of a leading file variable
the input file is the standard input stream. The parameters take the form of
variables into which appropriate translations of textual representations of
values in the file are read. The statement
<p>
<tt>read<a name="read33">
</a>(</tt><em>a,b,c</em><tt>) </tt>
<p>
where <em>a,b,c</em> are non file parameters is exactly equivalent to the sequence
of statements
<p>
<tt>read(</tt><em>a</em><tt>);read(</tt><em>b</em><tt>);read(</tt><em>c</em><tt>) </tt>
<p>
The <tt>readln</tt><a name="readln33">
</a> statement has the same effect as the read
statement but finishes by reading a new line from the input file. The representation
of the new line is operating system dependent. The statement
<p>
<tt>readln(</tt><em>a,b,c</em><tt>) </tt>
<p>
where <em>a,b,c</em> are non file parameters is thus exactly equivalent to the
sequence of statements
<p>
<tt>read(</tt><em>a</em><tt>);read(</tt><em>b</em><tt>);read(</tt><em>c</em><tt>);readln; </tt>
<p>
Allowed typed for read statements are: integers, reals, strings and enumerated
types.
<p>
<h3><a name="tth_sEc3.3.2">
3.3.2</a> Output </h3>
<p>
The basic form of output is the <tt>write<a name="write33">
</a></tt> statement. This
takes a list of parameters the first of which may optionally be a file variable.
If this file variable is present it is the output file. In the absence of a
leading file variable the output file is the console. The parameters take the
form of expressions whose values whose textual representations are written to
the output file. The statement
<p>
<tt>write(</tt><em>a,b,c</em><tt>) </tt>
<p>
where <em>a,b,c</em> are non file parameters is exactly equivalent to the sequence
of statements
<p>
<tt>write(</tt><em>a</em><tt>);write(</tt><em>b</em><tt>);write(</tt><em>c</em><tt>) </tt>
<p>
The <tt>writeln<a name="writeln33">
</a></tt> statement has the same effect as the write
statement but finishes by writing a new line to the output file. The representation
of the new line is operating system dependent. The statement
<p>
<tt>writeln(</tt><em>a,b,c</em><tt>) </tt>
<p>
where <em>a,b,c</em> are non file parameters is thus exactly equivalent to the
sequence of statements
<p>
<tt>write(</tt><em>a</em><tt>);write(</tt><em>b</em><tt>);write(</tt><em>c</em><tt>);writeln; </tt>
<p>
Allowed types for write statements are integers, reals, strings and enumerated
types.
<p>
<h4>Parameter formating<a name="formating33">
</a> </h4>
<p>
A non file parameter can be followed by up to two integer expressions prefixed
by colons which specify the field widths to be used in the output. The write
parameters can thus have the following forms:
<p>
<em>e e</em>:<em>m e</em>:<em>m</em>:<em>n </em>
<p>
<ol type="1"><p>
<li> If <em>e</em> is an integral type its decimal expansion will be written preceeded
by sufficient blanks to ensure that the total textual field width produced is
not less than <em>m</em>.</li>
<p>
<li> If <em>e</em> is a real its decimal expansion will be written preceeded by sufficient
blanks to ensure that the total textual field width produced is not less than
<em>m</em>. If <em>n</em> is present the total number of digits after the decimal
point will be <em>n</em>. If <em>n</em> is omitted then the number will be written
out in exponent and mantissa form with 6 digits after the decimal point</li>
<p>
<li> If <em>e</em> is boolean the strings 'true' or 'false' will be written into a
field of width not less than m.</li>
<p>
<li> If <em>e</em> is a string then the string will be written into a field of width
not less than <em>m</em>.</li>
</ol>
<p>
<h1><a name="tth_chAp4">
Chapter 4 </a><br />Programs and Units</h1>
<a name="progunit">
</a>
Vector Pascal supports the popular system of separate compilation units<a name="units40">
</a>
found in Turbo<a name="Turbo Pascal40">
</a> Pascal. A compilation unit can be either
a program, a unit or a library<a name="library40">
</a>.
<p>
<center>
<table border="1">
<tr><td align="center"><program></td><td align="center">'program' <identifier>';'[<uses>';']<block>'.'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><invocation></td><td align="center"><unitid>['(' <type identifier>[','<type identifier>]*')']</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><unitid>
</td><td align="center"><identifier>[ ':' 'apu' <identifier> '[' <intconst>']' ]</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><uses></td><td align="center">'uses' <invocation>[','<invocation>]*</td></tr></table>
<p>
</center><center>
<table border="1"><a name="block">
</a>
<tr><td align="center"><block></td><td align="center">[<decls>';']*'begin' <statement>[';'<statement>]*'end'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><decls></td><td align="center">'const' <constant declaration>[';'<constant declaration>]*</td></tr>
<tr><td align="center"></td><td align="center">'type'<type definition>[';'<type definition>]*</td></tr>
<tr><td align="center"></td><td align="center">'label' <label>[',' <label>]</td></tr>
<tr><td align="center"></td><td align="center"><procedure declaration></td></tr>
<tr><td align="center"></td><td align="center">'var' <variable declaration>[ ';' <variable declaration> ]</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><unit></td><td align="center"><unit header> <unit body></td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><unit body></td><td align="center">'interface'[<uses>][<decls>] 'implementation'<block>'.'</td></tr>
<tr><td align="center"></td><td align="center">'interface'[ <uses>][<decls>] 'in' <invocation> ';'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><unit header></td><td align="center"><unit type><identifier></td></tr>
<tr><td align="center"></td><td align="center">'unit' <identifier> '(' <type identifier> [',' <type identifier>]* ')'</td></tr></table>
<p>
</center><center>
<table border="1">
<tr><td align="center"><unit type></td><td align="center">'unit'</td></tr>
<tr><td align="center"></td><td align="center">'library'</td></tr></table>
<p>
</center>An executable compilation unit must be declared as a program<a name="program40">
</a>.
The program can use several other compilation units all of which must be either
units or libraries. The units or libraries that it directly uses are specified
by a list of identifiers in an optional use list at the start of the program.
A unit or library has two declaration portions and an executable block.
<p>
<h2><a name="tth_sEc4.1">
4.1</a> The export of identifiers from units</h2>
<p>
The first declaration portion is the interface part and is preceded by the reserved
word <tt>interface</tt><a name="interface41">
</a>.
<p>
The definitions in the interface section of unit files constitute a sequence
of enclosing scopes, such that successive units in the with list ever more closely
contain the program itself. Thus when resolving an identifier, if the identifier
can not be resolved within the program scope, the declaration of the identifier
within the interface section of the rightmost unit in the uses list is taken
as the defining occurrence. It follows that rightmost occurrence of an identifier
definition within the interface parts of units on the uses list overrides all
occurrences in interface parts of units to its left in the uses list.
<p>
The implementation part of a unit consists of declarations<a name="declarations41">
</a>,
preceded by the reserved word <tt>implementatio</tt>n<a name="implementation41">
</a>
that are private to the unit with the exception that a function or procedure
declared in an interface context can omit the procedure body, provided that
the function or procedure is redeclared in the implementation part of the unit.
In that case the function or procedure heading given in the interface part is
taken to refer to the function or procedure of the same name whose body is declared
in the implementation part. The function or procedure headings sharing the same
name in the interface and implementation parts must correspond with respect
to parameter types, parameter order and, in the case of functions, with respect
to return types.
<p>
A unit may itself contain a use list, which is treated in the same way as the
use lists of a program. That is to say, the use list of a unit makes accessible
identifiers declared within the interface parts of the units named within the
use list to the unit itself.
<p>
<h3><a name="tth_sEc4.1.1">
4.1.1</a> The export of procedures from libraries.</h3>
<p>
If a compilation unit is prefixed by the reserved word <tt>library</tt> rather
than the words <tt>program</tt> or <tt>unit</tt>, then the procedure and function
declarations in its interface part are made accessible to routines written in
other languages.
<p>
<h3><a name="tth_sEc4.1.2">
4.1.2</a> The export of Operators from units</h3>
<p>
A unit can declare a type and export operators for that type.
<p>
<h2><a name="tth_sEc4.2">
4.2</a> Unit parameterisation and generic functions</h2>
Standard Pascal provides es some limited support for polymorphism<a name="polymorphism42">
</a>
in its <tt>read</tt> and <tt>write</tt> functions.
Vector Pascal allows the writing of polymorphic functions and
procedures through the use of parameteric units.
<p>
A unit header can include an optional parameter list. The parameters identifiers which are
interepreted as type names. These can be used to declare polymorphic procedures and
functions, parameterised by these type names.
This is shown in figure <a href="#unit:genericsort">4.1</a>.
<p>
<p>
<a name="tth_fIg4.1">
</a> ***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯
<br /><table align="left" border="0"><tr><td width="138">
<font size="-3"></font></td></tr></table><!--hbox-->
\'<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>unit</b> <i>genericsort(t)</i> ;</font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>interface</b> </font></td></tr></table><!--hbox-->
<br />\<<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>type</b> </font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><i>dataarray</i> <i>(</i> <i>n</i> ,<i>m</i> :<i>integer</i> )=<b>array</b> [<i>n</i> ..<i>m</i> ] <b>of</b> <i>t</i> ;</font></td></tr></table><!--hbox-->
<br />\<<font face="helvetica"><b>procedure</b> <i>sort</i> <i>(</i> <b>var</b> <i>a</i> :<i>dataarray</i> );</font> (see Figure <a href="#sec:./genericsortsort">4.2</a> )<br />
<br />
\<<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>implementation</b> </font></td></tr></table><!--hbox-->
<br /><br />\<<font face="helvetica"><b>procedure</b> <i>sort</i> <i>(</i> <b>var</b> <i>a</i> :<i>dataarray</i> );</font> (see Figure <a href="#sec:./genericsortsort">4.2</a> )<br />
\<<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>begin</b> </font></td></tr></table><!--hbox-->
<br />\<<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>end</b> .</font></td></tr></table><!--hbox-->
<br />
<center>Figure 4.1: A polymorphic sorting unit.</center><a name="unit:genericsort">
</a>
<p>
<p>
<p>
<a name="tth_fIg4.2">
</a> ***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯
<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>procedure </b> <font face="helvetica"> <i>sort</i> <i>(</i> </font> <b> var </b> <font face="helvetica"> <i>a</i> :<i>dataarray</i> );</font></font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>var</b> </font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica">Let <i>i</i>, <i>j</i> <font face="symbol">Î</font
> integer;</font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica">Let <i>temp</i> <font face="symbol">Î</font
> t;</font></td></tr></table><!--hbox-->
<br />\<<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>begin</b> </font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>for </b> <font face="helvetica"><i>i</i><font face="symbol">¬</font
> <i>a.n</i></font> <b> to </b> <font face="helvetica"><i>a.m</i> - 1</font> <b> do </b> </font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>for </b> <font face="helvetica"><i>j</i><font face="symbol">¬</font
> <i>a.n</i></font> <b> to </b> <font face="helvetica"><i>a.m</i> - 1</font> <b> do </b> </font></td></tr></table><!--hbox-->
<br />\<<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>if </b> <font face="helvetica"><i>a</i><sub><i>j</i></sub> > <i>a</i><sub><i>j</i> + 1</sub></font> <b> then </b> <font face="helvetica"><i>begin</i></font> <b> begin </b> </font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><i>temp</i><font face="symbol">¬</font
> <i>a</i><sub><i>j</i></sub></font>; </td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><i>a</i><sub><i>j</i></sub> <font face="symbol">¬</font
> <i>a</i><sub><i>j</i> + 1</sub></font>; </td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><i>a</i><sub><i>j</i> + 1</sub> <font face="symbol">¬</font
> <i>temp</i></font>; </td></tr></table><!--hbox-->
<br />\<<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>end</b> ;</font></td></tr></table><!--hbox-->
<br />\<\<\<<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>end</b> ;</font></td></tr></table><!--hbox-->
<br />
<center>Figure 4.2: procedure sort</center><a name="sec:./genericsortsort">
</a>
<p>
<p>
<h2><a name="tth_sEc4.3">
4.3</a> The invocation of programs and units</h2>
<p>
Programs and units contain an executable block<a name="block43">
</a>. The rules for
the execution of these are as follows:
<p>
<ol type="1"><p>
<li> When a program is invoked by the operating system, the units or libraries in
its use list are invoked first followed by the executable block of the program
itself.</li>
<p>
<li> When a unit or library is invoked, the units or libraries in its use list are
invoked first followed by the executable block of the unit or library itself.</li>
<p>
<li> The order of invocation of the units or libraries in a use list is left to right
with the exception provided by rule 4.</li>
<p>
<li> No unit or library may be invoked more than once.</li>
</ol>
Note that rule 4 implies that a unit <em>x</em> to the right of a unit <em>y</em>
within a use list, may be invoked before the unit <em>y,</em> if the unit <em>y</em>
or some other unit to <em>y</em>'s left names <em>x</em> in its use list.
<p>
Note that the executable part of a library will only be invoked if the library
in the context of a Vector Pascal program. If the library is linked to a main
program in some other language, then the library and any units that it uses
will not be invoked. Care should thus be taken to ensure that Vector Pascal
libraries to be called from main programs written in other languages do not
depend upon initialisation code contained within the executable blocks of units.
<p>
<h2><a name="tth_sEc4.4">
4.4</a> The compilation of programs and units.</h2>
<p>
When the compiler<a name="compiler44">
</a> processes the use list of a unit or a program
then, from left to right, for each identifier in the use list it attempts to
find an already compiled unit whose filename prefix is equal to the identifier.
If such a file exists, it then looks for a source<a name="source44">
</a> file whose
filename prefix is equal to the identifier, and whose suffix<a name="suffix44">
</a>
is <tt>.pas</tt><a name="'.pas'44">
</a>. If such a file exists and is older than the
already compiled file, the already compiled unit, the compiler loads the definitions
contained in the pre-compiled unit. If such a file exists and is newer than
the pre-compiled unit, then the compiler attempts to re-compile the unit source
file. If this recompilation proceeds without the detection of any errors the
compiler loads the definitions of the newly compiled unit. The definitions in
a unit are saved to a file with the suffix <tt>.mpu,</tt> and prefix given by
the unit name. The compiler also generates an assembler file for each unit compiled.
<p>
<h3><a name="tth_sEc4.4.1">
4.4.1</a> Linking to external libraries</h3>
<p>
It is possible to specify to which external libraries - that is to say libraries
written in another languge, a program should be linked by placing in the main
program linkage directives. For example
<p>
<tt>{$linklib ncurses}</tt>
<p>
would cause the program to be linked to the ncurses library.
<p>
<h2><a name="tth_sEc4.5">
4.5</a> Instantiation of parametric units</h2>
Instantiation of a parametric unit refers to the process by which the unbound type variables introduced
in the parameter list of the unit are bound to actual types.
In Vector Pascal all instantiation of parametric units and all type polymorphism are resolved<a name="polymorphism45">
</a>
at compile time.
Two mechanisms are provided by which a parametric unit may be instantiated.
<h3><a name="tth_sEc4.5.1">
4.5.1</a> Direct instantiation</h3>
If a generic unit is invoked in the use list of a program or unit, then the unit name
must be followed by a list of type identifiers. Thus given the generic sort unit
in figure <a href="#unit:genericsort">4.1</a>, one could instantiate it to sort arrays of reals by
writing
<p>
<font face="helvetica"><b>uses </b> <i>genericsort</i>(<i>real</i>);</font>
<p>
at the head of a program. Following this header, the
procedure <font face="helvetica"><i>sort</i></font> would be declared as operating
on arrays of reals.
<h3><a name="tth_sEc4.5.2">
4.5.2</a> Indirect instantiation</h3>
A named unit file can indirectly instantiate a generic unit where its unit body
uses the syntax
<p>
'interface' <uses><decls> 'in' <invocation> ';'
<p>
For example
<p>
***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯***¯
<br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>unit</b> <i>intsort</i> ;</font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>interface</b> </font></td></tr></table><!--hbox-->
<br /><br /><table align="left" border="0"><tr><td width="553">
<font face="helvetica"><b>in </b> <font face="helvetica"><i>genericsort</i> (<i>integer</i>)</font>; </font></td></tr></table><!--hbox-->
<br /><br />would create a named unit to sort integers. The naming of the parametric
units allows more than one instance of a given parametric unit to be used
in a program. The generic sort unit could be used to provide both integer and
real sorting procedures. The different variants of the procedures would be
distinquished by using fully qualified names - e.g., <font face="helvetica"><i> intsort.sort</i></font>.
<h2><a name="tth_sEc4.6">
4.6</a> The System Unit</h2>
<a name="sysunit">
</a>
All programs and units include by default the unit system.pas as an implicit
member of their with list. This contains declarations of private run time routines
needed by Vector Pascal and also the following user accessible routines.
<p>
<dl compact="compact">
<dt><b><tt>function</tt></b></dt>
<dd><tt>abs<a name="abs46">
</a></tt> Return absolute value of a real or integer.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>append<a name="append46">
</a>(var f:file);</tt> This opens a
file in append mode.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>arctan<a name="arctan46">
</a>(x:Real):Real;</tt></dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>assign<a name="assign46">
</a>(var f:file;var fname:string);</tt>
Associates a file name with a file. It does not open the file.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>blockread<a name="blockread46">
</a>(var f:file;var buf;count:integer;
var resultcount:integer);</tt> Trys to read count bytes from the file into the buffer.
Resultcount contains the number actually read.</dd>
<dt><b><tt>LatexCommand</tt></b></dt>
<dd><tt>index{blockwrite}procedure
blockwrite(var f:file;var buf;count:integer; var resultcount:integer);</tt> Write
count bytes from the buffer. Resultcount gives the number actually read.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>close</tt><a name="close46">
</a>(var f:file); Closes a file.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>eof</tt><a name="eof46">
</a>(var f:file):boolean; True if we
are at the end of file f.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>erase</tt><a name="erase46">
</a>(var f:file); Delete file f.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>eoln</tt><a name="eoln46">
</a>(var f:file):boolean; True if at
the end of a line.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>exp</tt><a name="exp46">
</a>(d:real):real; Return e<sup>x</sup> </dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>filesize</tt><a name="filesize46">
</a>(var f: fileptr):integer;
Return number of bytes in a file.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>filepos</tt><a name="filepos46">
</a>(var f:fileptr):integer;
Return current position in a file.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>freemem<a name="freemem46">
</a>(var p:pointer; num:integer);</tt>
Free num bytes of heap store. Called by dispose.</dd>
<dt><b>bold</b></dt>
<dd>procedure getmem<a name="getmem46">
</a>(var p:pointer; num:integer); Allocate
num bytes of heap. Called by new.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>gettime<a name="gettime46">
</a>(var hour,min,sec,hundredth:integer);</tt>
Return time of day.</dd>
<dt><b><tt></tt></b></dt>
<dd>Return the integer part of r as a real.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>ioresult:integer;</tt> Returns a code indicating if the
previous file operation completed ok. Zero if no error occurred.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>length<a name="length46">
</a>(var s:string):integer;</tt> Returns
the length of s.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>pascalexit<a name="pascalexit46">
</a>(code:integer);</tt> Terminate
the program with code.</dd>
<dt><b><tt></tt></b></dt>
<dd>Time in 1/100 seconds since program started.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>random<a name="random46">
</a>:integer;</tt> Returns a random
integer.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>randomize<a name="randomize46">
</a>;</tt> Assign a new time
dependent seed to the random number generator.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>reset<a name="reset46">
</a>(var f:file);</tt> Open a file for
reading.</dd>
<dt><b><tt>procedure</tt></b></dt>
<dd><tt>rewrite<a name="rewrite46">
</a>(var f :file);</tt> Open a file
for writing.</dd>
<dt><b><tt>function</tt></b></dt>
<dd><tt>trunc(r:real):integer;</tt> Truncates a real to an integer.
</dd>
</dl>
<p>
<h1><a name="tth_chAp5">
Chapter 5 </a><br />Implementation issues</h1>
<p>
The compiler is implemented in java to ease portability between operating systems.
<p>
<h2><a name="tth_sEc5.1">
5.1</a> Invoking the compiler</h2>
<p>
The compiler is invoked with the command <a name="commandline">
</a>
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
vpc<a name="vpc51">
</a> filename
</dd>
</dl>
where filename is the name of a Pascal program or unit. For example
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
vpc test
</dd>
</dl>
will compile the program test.pas and generate an executable file <tt>test</tt>,
(<tt>test.exe</tt> under windows).
<p>
The command <tt>vpc</tt> is a shell script which invokes the java runtime system
to execute a <tt>.jar</tt> file containing the compiler classes. Instead of
running vpc the java interpreter can be directly invoked as follows
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
java -jar mmpc.jar filename
</dd>
</dl>
The <tt>vpc</tt> script sets various compiler options appropriate to the operating
system being used.
<p>
<h3><a name="tth_sEc5.1.1">
5.1.1</a> Environment variable</h3>
<p>
The environment variable <tt>mmpcdir<a name="mmpcdir51">
</a></tt> must be set to the
directory which contains the <tt>mmpc<a name="mmpc51">
</a>.jar</tt> file, the runtime
library <tt>rtl.o</tt> and the <tt>system.pas</tt> file.
<p>
<h3><a name="tth_sEc5.1.2">
5.1.2</a> Compiler options</h3>
<a name="comp:opt">
</a>
The following flags<a name="flags51">
</a> can be supplied to the compiler :
<p>
<dl compact="compact">
<dt><b><tt>-L</tt></b></dt>
<dd> Causes a latex listing to be produced of
all files compiled. The level of detail can be controled
using the codes -L1 to -L3, otherwise the maximum detail level is used.</dd>
<dt><b><tt>-OPTn</tt></b></dt>
<dd> Sets the optimisation level attempted.
-OPT0 is no optimisation, -OPT3 is the maximum level attempted.
The default is -OPT1.</dd>
<dt><b><tt>-Afilename<a name="-Afilename51">
</a></tt></b></dt>
<dd>Defines the assembler file to be created.
In the absence of this option the assembler file is <tt>p.asm.</tt></dd>
<dt><b><tt>-Ddirname<a name="-Ddirname51">
</a></tt></b></dt>
<dd>Defines the directory in which to find
<tt>rtl.o</tt> and <tt>system.pas</tt>.</dd>
<dt><b><tt>-BOEHM</tt><a name="-BOEHM51">
</a><a name="garbage collection51">
</a><a name="garbage">
</a><a name="BOEHM">
</a></b></dt>
<dd>
Causes the program to be linked with the Boehm conservative garbage
collector.</dd>
<dt><b><tt>-V<a name="-V51">
</a></tt></b></dt>
<dd>Causes the code generator to produce a verbose diagnostic
listing to <tt>foo.lst</tt> when compiling <tt>foo.pas</tt>.</dd>
<dt><b><tt>-oexefile<a name="-oexefile51">
</a></tt></b></dt>
<dd>Causes the linker to output to <tt>exefile</tt>
instead of the default output of <tt>p.exe.</tt></dd>
<dt><b><tt>-U<a name="-U51">
</a></tt></b></dt>
<dd>Defines whether references to external procedures in
the assembler file should be preceded by an under-bar '_'. This is required
for the coff object format but not for elf.</dd>
<dt><b><tt>-S<a name="-S51">
</a></tt></b></dt>
<dd>Suppresses assembly and linking of the program. An assembler
file is still generated.</dd>
<dt><b><tt>-fFORMAT<a name="-fFORMAT51">
</a></tt></b></dt>
<dd>Specifies the object format to be generated
by the assembler. The object formats currently used are elf when compiling under
Unix or when compiling under windows using the cygwin version of the gcc linker,
or coff when using the djgpp version of the gcc linker. for other formats consult
the NASM documentation.</dd>
<dt><b><tt>-cpuCGFLAG<a name="-cpuCGFLAG51">
</a></tt></b></dt>
<dd>Specifies the code generator to be used.
Currently the code generators shown in table <a href="#cgs">5.1</a> are supported.</dd>
<dt><b></b></dt>
<dd>
<p>
<a name="tth_tAb5.1">
</a> <center>Table 5.1: Code generators supported<a name="cgs">
</a></center>
<center>
<table border="1">
<tr><td align="center"><tt>CGFLAG</tt></td><td><tt>description</tt></td></tr><tr><td>
<tr><td align="center"><tt>IA<a name="IA3251">
</a>32</tt></td><td>generates code for the Intel 486 instruction-set</td></tr>
<tr><td align="center"></td><td>uses the NASM assembler</td></tr>
<tr><td align="center"><tt>Pentium<a name="Pentium51">
</a></tt></td><td>generates code for the Intel P6 with MMX instruction-set</td></tr>
<tr><td align="center"></td><td>uses the NASM <a name="NASM51">
</a> assembler</td></tr><tr><td>
<tr><td align="center"><tt>gnuPentium<a name="Pentium51">
</a></tt></td><td>generates code for the Intel P6 with MMX instruction-set</td></tr>
<tr><td align="center"></td><td>using the <tt>as</tt> <a name="as51">
</a> assembler in the gcc package</td></tr>
<tr><td align="center"><tt>K6<a name="K651">
</a></tt></td><td>generates code for the AMD<a name="AMD51">
</a> K6 instruction-set, use for Athlon</td></tr>
<tr><td align="center"></td><td>uses the NASM assembler</td></tr>
<tr><td align="center"><tt>P3<a name="P351">
</a></tt></td><td>generates code for the Intel<a name="Intel51">
</a> PIII processor family<tt></tt></td></tr>
<tr><td align="center"></td><td>uses the NASM assembler</td></tr>
<tr><td align="center"><tt>P4</tt> </td><td>generates code for the Intel PIV family and Athlon XP</td></tr>
<tr><td align="center"></td><td>uses the NASM assembler</td></tr></table>
<p>
</center>
<p>
</dd>
</dl> <h3><a name="tth_sEc5.1.3">
5.1.3</a> Dependencies</h3>
<p>
The Vector Pascal compiler depends upon a number of other utilities which are
usually pre-installed on Linux systems, and are freely available for Windows
systems.
<p>
<dl compact="compact">
<dt><b>NASM</b></dt>
<dd>The net-wide assembler. This is used to convert the output of the code
generator to linkable modules. It is freely available on the web for Windows.
For the Pentium processor it is possible to use the <tt>as</tt> assembler instead.</dd>
<dt><b>gcc</b></dt>
<dd>The GNU C Compiler, used to compile the run time library and to link modules
produced by the assembler to the run time library.</dd>
<dt><b>java</b></dt>
<dd>The java virtual machine must be available to interpret the compiler.
There are number of java interpreters and just in time compilers are freely available
for Windows.
</dd>
</dl>
<p>
<h2><a name="tth_sEc5.2">
5.2</a> Calling conventions</h2>
<p>
Procedure parameters are passed using a modified C calling convention to facilitate
calls to external C procedures. Parameters are pushed on to the stack from right
to left. Value parameters are pushed entire onto the stack, var parameters are
pushed as addresses.
<p>
<b>Example </b>
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
<span class="roman"><tt><font size="-1">unit callconv;</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">interface</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">type intarr= array[1..8] of integer;</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">procedure foo(var a:intarr; b:intarr; c:integer);</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">implementation</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">procedure foo(var a:intarr; b:intarr; c:integer);</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">begin</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">end;</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">var x,y:intarr;</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">begin</font></tt></span><font size="-1">
<p>
</font> <span class="roman"><tt><font size="-1"> foo(x,y,3);</font></tt></span><font size="-1">
<p>
</font><span class="roman"><tt><font size="-1">end.</font></tt></span><font size="-1">
<p>
</font></dd>
</dl>This would generate the following code for the procedure foo.
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
<tt><font size="-2">; procedure generated by code generator class ilcg.tree.PentiumCG</font></tt><font size="-2">
<p>
</font><tt><font size="-2">le8e68de10c5:</font></tt><font size="-2">
<p>
</font><tt><font size="-2">; foo</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">enter spaceforfoo-4*1,1</font></tt><font size="-2">
<p>
</font><tt><font size="-2">;8</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">le8e68de118a:</font></tt><font size="-2">
<p>
</font><tt><font size="-2">spaceforfoo equ 4</font></tt><font size="-2">
<p>
</font><tt><font size="-2">;.... code for foo goes here</font></tt><font size="-2">
<p>
</font><tt><font size="-2">fooexit:</font></tt><font size="-2">
<p>
</font><tt><font size="-2">leave</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">ret 0</font></tt><font size="-2">
<p>
</font></dd>
</dl>and the calling code is
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
<tt><font size="-2">push DWORD 3 ; push rightmost argument</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">lea esp,[ esp-32] ; create space for the array</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">mov DWORD [ ebp -52],0 ; for loop to copy the array</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">le8e68de87fd: ; the loop is </font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> ; unrolled twice and</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">cmp DWORD [ ebp-52], 7 ; parallelised to copy </font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> ; 16 bytes per cycle</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">jg near le8e68de87fe</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">mov ebx,DWORD [ ebp -52]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">imul ebx, 4</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">movq MM1, [ ebx+ le8e68dddaa2-48]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">movq [ esp+ebx],MM1</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">mov eax,DWORD [ ebp+ -52]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">lea ebx,[ eax+ 2]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">imul ebx, 4</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">movq MM1, [ ebx+ le8e68dddaa2 -48]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">movq [ esp+ebx],MM1</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">lea ebx,[ ebp+ -52]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">add DWORD [ ebx], 4</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">jmp le8e68de87fd</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">le8e68de87fe: ; end of array </font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> ; copying loop</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">push DWORD le8e68dddaa2-32 ; push the address of the </font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> ; var parameter</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">EMMS ; clear MMX state</font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> call le8e68de10c5 ; call the local </font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> ; label for foo</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">add esp, 40 ; free space on the stack</font></tt><font size="-2">
<p>
</font></dd>
</dl>
<h4>Function results</h4>
<p>
Function results are returned in registers for scalars following the C calling
convention for the operating system on which the compiler is implemented. Records,
strings and sets are returned by the caller passing an implicit parameter containing
the address of a temporary buffer in the calling environment into which the
result can be assigned. Given the following program
<p>
<tt>program</tt>
<p>
<tt>type t1= set of char;</tt>
<p>
<tt>var x,y:t1;</tt>
<p>
<tt>function bar:t1;begin bar:=y;end;</tt>
<p>
<tt> </tt>
<p>
<tt>begin</tt>
<p>
<tt> x:=bar;</tt>
<p>
<tt>end.</tt>
<p>
The call of bar would generate
<p>
<dl compact="compact">
<dt><b></b></dt>
<dd>
<font size="-2"></font><tt><font size="-2">push ebp</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">add dword[esp] , -128 ; address of buffer on stack</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">call le8eb6156ca8 ; call bar to place </font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> ; result in buffer</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">add esp, 4 ; discard the address</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">mov DWORD [ ebp+ -132], 0; for loop to copy </font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> ; the set 16 bytes</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">le8eb615d99f: ; at a time into x using the </font></tt><font size="-2">
<p>
</font> <tt><font size="-2"> ; MMX registers</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">cmp DWORD [ ebp+ -132], 31</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">jg near le8eb615d9910</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">mov ebx,DWORD [ ebp+ -132]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">movq MM1, [ ebx+ebp + -128]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">movq [ ebx+ebp + -64],MM1</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">mov eax,DWORD [ ebp+ -132]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">lea ebx,[ eax+ 8]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">movq MM1, [ ebx+ebp + -128]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">movq [ ebx+ebp + -64],MM1</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">lea ebx,[ ebp+ -132]</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">add DWORD [ ebx], 16</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">jmp le8eb615d99f</font></tt><font size="-2">
<p>
</font> <tt><font size="-2">le8eb615d9910:</font></tt><font size="-2">
<p>
</font></dd>
</dl> <h2><a name="tth_sEc5.3">
5.3</a> Array representation</h2>
<p>
The maximum number of array dimensions supported in the compiler is 5.
<p>
A static<a name="static53">
</a> array<a name="array, static53">
</a> is represented simply by
the number of bytes required to store the array being allocated in the global
segment or on the stack.
<p>
A dynamic array<a name="array53">
</a><a name="array, dynamic53">
</a> is always represented on
the heap<a name="heap53">
</a>. Since its rank<a name="rank53">
</a> is known to the compiler
what needs to be stored at run time are the bounds and the means to access it.
For simplicity we make the format of dynamic and conformant arrays the same.
Thus for schema<a name="schema53">
</a>
<p>
<tt>s(a,b,c,d:integer)= array[a..b,c..d] of integer </tt>
<p>
whose run time bounds are evaluated to be 2..4,3..7 we would have the following
structure:
<p>
<center>
<table border="1">
<tr><td align="center">address</td><td align="center">field</td><td align="center">value</td></tr><tr><td>
<tr><td align="center">x</td><td align="center">base of data</td><td align="center">address of first integer in the array</td></tr>
<tr><td align="center">x+4</td><td align="center">a</td><td align="center">2</td></tr>
<tr><td align="center">x+8</td><td align="center">b</td><td align="center">4</td></tr>
<tr><td align="center">x+12</td><td align="center">step</td><td align="center">20</td></tr>
<tr><td align="center">x+16</td><td align="center">c</td><td align="center">3</td></tr>
<tr><td align="center">x+20</td><td align="center">d</td><td align="center">7</td></tr></table>
<p>
</center>The base address for a schematic array on the heap, will point at the first
byte after the array header show. For a conformant array, it will point at the
first data byte of the array or array range<a name="range53">
</a> being passed as a
parameter. The step field specifies the length of an element of the second dimension
in bytes. It is included to allow for the case where we have a conformant<a name="conformant53">
</a>
array<a name="array, conformant53">
</a> formal parameter
<p>
<tt>x:array[a..b:integer,c..d:integer] of integer</tt>
<p>
to which we pass as actual parameter<a name="parameter53">
</a> the range
<p>
<tt>p[2..4,3..7] </tt>
<p>
as actual parameter, where <tt>p:array[1..10,1..10] of integer</tt>
<p>
In this case the base address would point at @p[2,3] and the step would
be 40 - the length of 10 integers.
<p>
<h3><a name="tth_sEc5.3.1">
5.3.1</a> Range<a name="range53">
</a> checking</h3>
<p>
When arrays are indexed, the compiler plants run time checks to see if the indices
are within bounds<a name="bounds53">
</a>. In many cases the optimiser is able to remove
these checks, but in those cases where it is unable to do so, some performance
degradation can occur. Range checks can be disabled or enabled by the compiler
directives.
<p>
{$r-} { disable range checks }
<p>
{$r+} { enable range checks }
<p>
Performance can be further enhanced by the practice of declaring arrays to have
lower bounds of zero. The optimiser is generally able to generate more efficient
code for zero based arrays.
<p>
<a name="ilcg">
</a>
<p>
<p>
<p>
<a name="tth_sEcindex"></a>
<h2> Index (showing section)</h2>
<table width="100%"><tr><td width="48%" valign="top">
<dl compact="compact">
<dt><b></b></dt>
<dd>'.pas', <a href="#'.pas'44">4-4</a></dd>
<dt><b></b></dt>
<dd>(*, <a href="#(*13">1-3</a></dd>
<dt><b></b></dt>
<dd>*), <a href="#*)13">1-3</a></dd>
<dt><b></b></dt>
<dd>**, <a href="#**31">3-1</a></dd>
<dt><b></b></dt>
<dd>+, <a href="#+31">3-1</a></dd>
<dt><b></b></dt>
<dd>+:, <a href="#+:31">3-1</a></dd>
<dt><b></b></dt>
<dd>-, <a href="#-31">3-1</a></dd>
<dt><b></b></dt>
<dd>-:, <a href="#-:31">3-1</a></dd>
<dt><b></b></dt>
<dd>-Afilename, <a href="#-Afilename51">5-1</a></dd>
<dt><b></b></dt>
<dd>-BOEHM, <a href="#-BOEHM51">5-1</a></dd>
<dt><b></b></dt>
<dd>-Ddirname, <a href="#-Ddirname51">5-1</a></dd>
<dt><b></b></dt>
<dd>-S, <a href="#-S51">5-1</a></dd>
<dt><b></b></dt>
<dd>-U, <a href="#-U51">5-1</a></dd>
<dt><b></b></dt>
<dd>-V, <a href="#-V51">5-1</a></dd>
<dt><b></b></dt>
<dd>-cpuCGFLAG, <a href="#-cpuCGFLAG51">5-1</a></dd>
<dt><b></b></dt>
<dd>-fFORMAT, <a href="#-fFORMAT51">5-1</a></dd>
<dt><b></b></dt>
<dd>-oexefile, <a href="#-oexefile51">5-1</a></dd>
<dt><b></b></dt>
<dd>:=, <a href="#:=32">3-2</a></dd>
<dt><b></b></dt>
<dd><tt>><</tt>, <a href="#\verb+><+31">3-1</a><br /><br /></dd>
<dt><b></b></dt>
<dd>abs, <a href="#abs31">3-1</a>, <a href="#abs46">4-6</a></dd>
<dt><b></b></dt>
<dd>addr, <a href="#addr31">3-1</a></dd>
<dt><b></b></dt>
<dd>AMD, <a href="#AMD00">0-0</a>, <a href="#AMD51">5-1</a></dd>
<dt><b></b></dt>
<dd>and, <a href="#and31">3-1</a></dd>
<dt><b></b></dt>
<dd>APL, <a href="#APL00">0-0</a></dd>
<dt><b></b></dt>
<dd>append, <a href="#append46">4-6</a></dd>
<dt><b></b></dt>
<dd>arctan, <a href="#arctan46">4-6</a></dd>
<dt><b></b></dt>
<dd>array, <a href="#array23">2-3</a>, <a href="#array25">2-5</a>,
<a href="#array31">3-1</a>, <a href="#array32">3-2</a>,
<a href="#array53">5-3</a></dd>
<dt><b></b></dt>
<dd>array constant, <a href="#array constant21">2-1</a></dd>
<dt><b></b></dt>
<dd>array context, <a href="#array context32">3-2</a></dd>
<dt><b></b></dt>
<dd>array, conformant, <a href="#array, conformant53">5-3</a></dd>
<dt><b></b></dt>
<dd>array, dynamic, <a href="#array, dynamic23">2-3</a>,
<a href="#array, dynamic53">5-3</a></dd>
<dt><b></b></dt>
<dd>array, static, <a href="#array, static23">2-3</a>,
<a href="#array, static53">5-3</a></dd>
<dt><b></b></dt>
<dd>as, <a href="#as51">5-1</a></dd>
<dt><b></b></dt>
<dd>assign, <a href="#assign46">4-6</a></dd>
<dt><b></b></dt>
<dd>assignment, <a href="#assignment32">3-2</a></dl></td><td width="8%" valign="top">
<dl compact="compact">
</dd>
<dt><b></b></dt>
<dd>basis, <a href="#basis23">2-3</a></dd>
<dt><b></b></dt>
<dd>begin, <a href="#begin32">3-2</a></dd>
<dt><b></b></dt>
<dd>binary, <a href="#binary23">2-3</a></dd>
<dt><b></b></dt>
<dd>block, <a href="#block43">4-3</a></dd>
<dt><b></b></dt>
<dd>blockread, <a href="#blockread46">4-6</a></dd>
<dt><b></b></dt>
<dd>boolean, <a href="#boolean23">2-3</a>, <a href="#boolean31">3-1</a></dd>
<dt><b></b></dt>
<dd>bounds, <a href="#bounds53">5-3</a></dd>
<dt><b></b></dt>
<dd>byte, <a href="#byte23">2-3</a>, <a href="#byte31">3-1</a></dd>
<dt><b></b></dt>
<dd>bytes, <a href="#bytes31">3-1</a><br /><br /></dd>
<dt><b></b></dt>
<dd>C, <a href="#C00">0-0</a></dd>
<dt><b></b></dt>
<dd>cardinal, <a href="#cardinal23">2-3</a></dd>
<dt><b></b></dt>
<dd>case, <a href="#case32">3-2</a></dd>
<dt><b></b></dt>
<dd>cast, <a href="#cast31">3-1</a></dd>
<dt><b></b></dt>
<dd>char, <a href="#char23">2-3</a></dd>
<dt><b></b></dt>
<dd>character, <a href="#character31">3-1</a></dd>
<dt><b></b></dt>
<dd>charmax, <a href="#charmax23">2-3</a></dd>
<dt><b></b></dt>
<dd>chr, <a href="#chr31">3-1</a></dd>
<dt><b></b></dt>
<dd>close, <a href="#close46">4-6</a></dd>
<dt><b></b></dt>
<dd>cmplx, <a href="#cmplx31">3-1</a></dd>
<dt><b></b></dt>
<dd>comment, <a href="#comment13">1-3</a></dd>
<dt><b></b></dt>
<dd>compiler, <a href="#compiler44">4-4</a></dd>
<dt><b></b></dt>
<dd>complement, <a href="#complement31">3-1</a></dd>
<dt><b></b></dt>
<dd>Complex, <a href="#Complex31">3-1</a></dd>
<dt><b></b></dt>
<dd>complex, <a href="#complex23">2-3</a></dd>
<dt><b></b></dt>
<dd>complexone, <a href="#complexone21">2-1</a></dd>
<dt><b></b></dt>
<dd>complexzero, <a href="#complexzero21">2-1</a></dd>
<dt><b></b></dt>
<dd>concatenate, <a href="#concatenate31">3-1</a></dd>
<dt><b></b></dt>
<dd>conformant, <a href="#conformant53">5-3</a></dd>
<dt><b></b></dt>
<dd>constant, <a href="#constant21">2-1</a></dd>
<dt><b></b></dt>
<dd>constants, <a href="#constants21">2-1</a></dd>
<dt><b></b></dt>
<dd>cos, <a href="#cos31">3-1</a></dl></td></tr><tr><td width="48%" valign="top">
<dl compact="compact">
</dd>
<dt><b></b></dt>
<dd>declaration, <a href="#declaration20">2-0</a></dd>
<dt><b></b></dt>
<dd>declarations, <a href="#declarations41">4-1</a></dd>
<dt><b></b></dt>
<dd>Delphi, <a href="#Delphi00">0-0</a></dd>
<dt><b></b></dt>
<dd>dimension, <a href="#dimension31">3-1</a></dd>
<dt><b></b></dt>
<dd>dimensional, <a href="#dimensional23">2-3</a></dd>
<dt><b></b></dt>
<dd>dimensioned, <a href="#dimensioned23">2-3</a></dd>
<dt><b></b></dt>
<dd>dimensions, <a href="#dimensions32">3-2</a></dd>
<dt><b></b></dt>
<dd>div, <a href="#div31">3-1</a></dd>
<dt><b></b></dt>
<dd>double, <a href="#double23">2-3</a></dd>
<dt><b></b></dt>
<dd>downto, <a href="#downto32">3-2</a></dd>
<dt><b></b></dt>
<dd>Dynamic, <a href="#Dynamic23">2-3</a></dd>
<dt><b></b></dt>
<dd>dynamic, <a href="#dynamic23">2-3</a></dd>
<dt><b></b></dt>
<dd>dynamic array, <a href="#dynamic array23">2-3</a><br /><br /></dd>
<dt><b></b></dt>
<dd>else, <a href="#else32">3-2</a></dd>
<dt><b></b></dt>
<dd>end, <a href="#end32">3-2</a></dd>
<dt><b></b></dt>
<dd>eof, <a href="#eof46">4-6</a></dd>
<dt><b></b></dt>
<dd>eoln, <a href="#eoln46">4-6</a></dd>
<dt><b></b></dt>
<dd>epsreal, <a href="#epsreal21">2-1</a></dd>
<dt><b></b></dt>
<dd>erase, <a href="#erase46">4-6</a></dd>
<dt><b></b></dt>
<dd>Exit, <a href="#Exit32">3-2</a></dd>
<dt><b></b></dt>
<dd>exp, <a href="#exp46">4-6</a></dd>
<dt><b></b></dt>
<dd>Expressions, <a href="#Expressions31">3-1</a></dl></td><td width="8%" valign="top">
<dl compact="compact">
</dd>
<dt><b></b></dt>
<dd>Factor, <a href="#Factor31">3-1</a></dd>
<dt><b></b></dt>
<dd>false, <a href="#false23">2-3</a></dd>
<dt><b></b></dt>
<dd>Field, <a href="#Field25">2-5</a></dd>
<dt><b></b></dt>
<dd>filepos, <a href="#filepos46">4-6</a></dd>
<dt><b></b></dt>
<dd>filesize, <a href="#filesize46">4-6</a></dd>
<dt><b></b></dt>
<dd>fixed, <a href="#fixed23">2-3</a></dd>
<dt><b></b></dt>
<dd>flags, <a href="#flags51">5-1</a></dd>
<dt><b></b></dt>
<dd>for, <a href="#for32">3-2</a></dd>
<dt><b></b></dt>
<dd>formal parameter, <a href="#formal parameter26">2-6</a></dd>
<dt><b></b></dt>
<dd>formating, <a href="#formating33">3-3</a></dd>
<dt><b></b></dt>
<dd>Fortran, <a href="#Fortran00">0-0</a></dd>
<dt><b></b></dt>
<dd>fractions, <a href="#fractions23">2-3</a></dd>
<dt><b></b></dt>
<dd>freemem, <a href="#freemem46">4-6</a></dd>
<dt><b></b></dt>
<dd>function, <a href="#function31">3-1</a><br /><br /></dd>
<dt><b></b></dt>
<dd>garbage collection, <a href="#garbage collection51">5-1</a></dd>
<dt><b></b></dt>
<dd>getmem, <a href="#getmem46">4-6</a></dd>
<dt><b></b></dt>
<dd>gettime, <a href="#gettime46">4-6</a></dd>
<dt><b></b></dt>
<dd>goto, <a href="#goto22">2-2</a>, <a href="#goto32">3-2</a><br /><br /></dd>
<dt><b></b></dt>
<dd>heap, <a href="#heap53">5-3</a></dd>
<dt><b></b></dt>
<dd>hexadecimal, <a href="#hexadecimal15">1-5</a></dd>
<dt><b></b></dt>
<dd>high, <a href="#high23">2-3</a></dl></td></tr><tr><td width="48%" valign="top">
<dl compact="compact">
</dd>
<dt><b></b></dt>
<dd>IA32, <a href="#IA3251">5-1</a></dd>
<dt><b></b></dt>
<dd>identifier, <a href="#identifier14">1-4</a>,
<a href="#identifier23">2-3</a></dd>
<dt><b></b></dt>
<dd>IEEE, <a href="#IEEE23">2-3</a></dd>
<dt><b></b></dt>
<dd>if, <a href="#if32">3-2</a></dd>
<dt><b></b></dt>
<dd>implementation, <a href="#implementation41">4-1</a></dd>
<dt><b></b></dt>
<dd>implicit indices, <a href="#implicit indices31">3-1</a>,
<a href="#implicit indices32">3-2</a></dd>
<dt><b></b></dt>
<dd>index, <a href="#index23">2-3</a>, <a href="#index31">3-1</a></dd>
<dt><b></b></dt>
<dd>indices, <a href="#indices25">2-5</a>, <a href="#indices31">3-1</a>,
<a href="#indices32">3-2</a></dd>
<dt><b></b></dt>
<dd>int64, <a href="#int6423">2-3</a></dd>
<dt><b></b></dt>
<dd>integer, <a href="#integer15">1-5</a>, <a href="#integer23">2-3</a>,
<a href="#integer31">3-1</a></dd>
<dt><b></b></dt>
<dd>Intel, <a href="#Intel51">5-1</a></dd>
<dt><b></b></dt>
<dd>interface, <a href="#interface41">4-1</a></dd>
<dt><b></b></dt>
<dd>iota, <a href="#iota31">3-1</a></dd>
<dt><b></b></dt>
<dd>is, <a href="#is32">3-2</a></dd>
<dt><b></b></dt>
<dd>iteration, <a href="#iteration32">3-2</a><br /><br /></dd>
<dt><b></b></dt>
<dd>J, <a href="#J00">0-0</a></dd>
<dt><b></b></dt>
<dd>Java, <a href="#Java00">0-0</a><br /><br /></dd>
<dt><b></b></dt>
<dd>K6, <a href="#K600">0-0</a>, <a href="#K651">5-1</a><br /><br /></dd>
<dt><b></b></dt>
<dd>label, <a href="#label22">2-2</a>, <a href="#label32">3-2</a></dd>
<dt><b></b></dt>
<dd>length, <a href="#length46">4-6</a></dd>
<dt><b></b></dt>
<dd>library, <a href="#library40">4-0</a></dd>
<dt><b></b></dt>
<dd>literal, <a href="#literal15">1-5</a></dd>
<dt><b></b></dt>
<dd>ln, <a href="#ln31">3-1</a></dd>
<dt><b></b></dt>
<dd>longint, <a href="#longint23">2-3</a></dd>
<dt><b></b></dt>
<dd>loop, <a href="#loop32">3-2</a></dd>
<dt><b></b></dt>
<dd>low, <a href="#low23">2-3</a></dl></td><td width="8%" valign="top">
<dl compact="compact">
</dd>
<dt><b></b></dt>
<dd>matrix, <a href="#matrix31">3-1</a></dd>
<dt><b></b></dt>
<dd>max, <a href="#max31">3-1</a></dd>
<dt><b></b></dt>
<dd>maxchar, <a href="#maxchar21">2-1</a></dd>
<dt><b></b></dt>
<dd>maxdouble, <a href="#maxdouble21">2-1</a></dd>
<dt><b></b></dt>
<dd>maxint, <a href="#maxint21">2-1</a></dd>
<dt><b></b></dt>
<dd>maxreal, <a href="#maxreal21">2-1</a></dd>
<dt><b></b></dt>
<dd>maxstring, <a href="#maxstring21">2-1</a></dd>
<dt><b></b></dt>
<dd>media, <a href="#media15">1-5</a></dd>
<dt><b></b></dt>
<dd>min, <a href="#min31">3-1</a></dd>
<dt><b></b></dt>
<dd>mindouble, <a href="#mindouble21">2-1</a></dd>
<dt><b></b></dt>
<dd>minreal, <a href="#minreal21">2-1</a></dd>
<dt><b></b></dt>
<dd>mmpc, <a href="#mmpc51">5-1</a></dd>
<dt><b></b></dt>
<dd>mmpcdir, <a href="#mmpcdir51">5-1</a></dd>
<dt><b></b></dt>
<dd>mod, <a href="#mod31">3-1</a></dd>
<dt><b></b></dt>
<dd>monadic, <a href="#monadic31">3-1</a><br /><br /></dd>
<dt><b></b></dt>
<dd>NASM, <a href="#NASM51">5-1</a></dd>
<dt><b></b></dt>
<dd>ndx, <a href="#ndx31">3-1</a></dd>
<dt><b></b></dt>
<dd>not, <a href="#not31">3-1</a><br /><br /></dd>
<dt><b></b></dt>
<dd>octal, <a href="#octal15">1-5</a></dd>
<dt><b></b></dt>
<dd>operator, <a href="#operator31">3-1</a>, <a href="#operator32">3-2</a></dd>
<dt><b></b></dt>
<dd>operator, overloadin, <a href="#operator, overloadin31">3-1</a></dd>
<dt><b></b></dt>
<dd>operators, <a href="#operators21">2-1</a></dd>
<dt><b></b></dt>
<dd>or, <a href="#or31">3-1</a></dd>
<dt><b></b></dt>
<dd>ord, <a href="#ord31">3-1</a></dl></td></tr><tr><td width="48%" valign="top">
<dl compact="compact">
</dd>
<dt><b></b></dt>
<dd>P3, <a href="#P351">5-1</a></dd>
<dt><b></b></dt>
<dd>parameter, <a href="#parameter32">3-2</a>, <a href="#parameter53">5-3</a></dd>
<dt><b></b></dt>
<dd>parameters, <a href="#parameters25">2-5</a></dd>
<dt><b></b></dt>
<dd>Pascal, <a href="#Pascal00">0-0</a></dd>
<dt><b></b></dt>
<dd>Pascal90, <a href="#Pascal9023">2-3</a></dd>
<dt><b></b></dt>
<dd>pascalexit, <a href="#pascalexit46">4-6</a></dd>
<dt><b></b></dt>
<dd>pchar, <a href="#pchar23">2-3</a></dd>
<dt><b></b></dt>
<dd>Pentium, <a href="#Pentium51">5-1</a></dd>
<dt><b></b></dt>
<dd>perm, <a href="#perm31">3-1</a></dd>
<dt><b></b></dt>
<dd>pi, <a href="#pi21">2-1</a></dd>
<dt><b></b></dt>
<dd>pixel, <a href="#pixel23">2-3</a>, <a href="#pixel31">3-1</a></dd>
<dt><b></b></dt>
<dd>pixels, <a href="#pixels15">1-5</a></dd>
<dt><b></b></dt>
<dd>point, <a href="#point23">2-3</a></dd>
<dt><b></b></dt>
<dd>pointer, <a href="#pointer23">2-3</a>, <a href="#pointer31">3-1</a></dd>
<dt><b></b></dt>
<dd>polymorphism, <a href="#polymorphism42">4-2</a>,
<a href="#polymorphism45">4-5</a></dd>
<dt><b></b></dt>
<dd>pow, <a href="#pow31">3-1</a></dd>
<dt><b></b></dt>
<dd>pred, <a href="#pred31">3-1</a></dd>
<dt><b></b></dt>
<dd>procedure, <a href="#procedure20">2-0</a>, <a href="#procedure32">3-2</a></dd>
<dt><b></b></dt>
<dd>program, <a href="#program20">2-0</a>, <a href="#program40">4-0</a><br /><br /></dd>
<dt><b></b></dt>
<dd>random, <a href="#random46">4-6</a></dd>
<dt><b></b></dt>
<dd>randomize, <a href="#randomize46">4-6</a></dd>
<dt><b></b></dt>
<dd>range, <a href="#range25">2-5</a>, <a href="#range53">5-3</a></dd>
<dt><b></b></dt>
<dd>rank, <a href="#rank31">3-1</a>, <a href="#rank32">3-2</a>,
<a href="#rank53">5-3</a></dd>
<dt><b></b></dt>
<dd>rdu, <a href="#rdu31">3-1</a></dd>
<dt><b></b></dt>
<dd>read, <a href="#read33">3-3</a></dd>
<dt><b></b></dt>
<dd>readln, <a href="#readln33">3-3</a></dd>
<dt><b></b></dt>
<dd>real, <a href="#real15">1-5</a>, <a href="#real23">2-3</a>,
<a href="#real31">3-1</a></dd>
<dt><b></b></dt>
<dd>reals, <a href="#reals31">3-1</a></dd>
<dt><b></b></dt>
<dd>record, <a href="#record23">2-3</a>, <a href="#record32">3-2</a></dd>
<dt><b></b></dt>
<dd>reduction, <a href="#reduction31">3-1</a></dd>
<dt><b></b></dt>
<dd>repeat, <a href="#repeat32">3-2</a></dd>
<dt><b></b></dt>
<dd>reset, <a href="#reset46">4-6</a></dd>
<dt><b></b></dt>
<dd>rewrite, <a href="#rewrite46">4-6</a></dd>
<dt><b></b></dt>
<dd>round, <a href="#round31">3-1</a></dl></td><td width="8%" valign="top">
<dl compact="compact">
</dd>
<dt><b></b></dt>
<dd>saturated, <a href="#saturated31">3-1</a></dd>
<dt><b></b></dt>
<dd>scalar, <a href="#scalar23">2-3</a>, <a href="#scalar31">3-1</a></dd>
<dt><b></b></dt>
<dd>schema, <a href="#schema53">5-3</a></dd>
<dt><b></b></dt>
<dd>schematic, <a href="#schematic25">2-5</a></dd>
<dt><b></b></dt>
<dd>set, <a href="#set23">2-3</a>, <a href="#set31">3-1</a></dd>
<dt><b></b></dt>
<dd>shl, <a href="#shl31">3-1</a></dd>
<dt><b></b></dt>
<dd>shortint, <a href="#shortint23">2-3</a></dd>
<dt><b></b></dt>
<dd>shr, <a href="#shr31">3-1</a></dd>
<dt><b></b></dt>
<dd>SIMD, <a href="#SIMD00">0-0</a></dd>
<dt><b></b></dt>
<dd>sin, <a href="#sin31">3-1</a></dd>
<dt><b></b></dt>
<dd>sizeof, <a href="#sizeof31">3-1</a></dd>
<dt><b></b></dt>
<dd>source, <a href="#source44">4-4</a></dd>
<dt><b></b></dt>
<dd>sqrt, <a href="#sqrt31">3-1</a></dd>
<dt><b></b></dt>
<dd>static, <a href="#static23">2-3</a>, <a href="#static53">5-3</a></dd>
<dt><b></b></dt>
<dd>string, <a href="#string23">2-3</a></dd>
<dt><b></b></dt>
<dd>strings, <a href="#strings15">1-5</a>, <a href="#strings25">2-5</a></dd>
<dt><b></b></dt>
<dd>subrange, <a href="#subrange23">2-3</a></dd>
<dt><b></b></dt>
<dd>Subranges, <a href="#Subranges25">2-5</a></dd>
<dt><b></b></dt>
<dd>succ, <a href="#succ31">3-1</a></dd>
<dt><b></b></dt>
<dd>suffix, <a href="#suffix44">4-4</a></dd>
<dt><b></b></dt>
<dd>System, <a href="#System20">2-0</a></dl></td></tr><tr><td width="48%" valign="top">
<dl compact="compact">
</dd>
<dt><b></b></dt>
<dd>tan, <a href="#tan31">3-1</a></dd>
<dt><b></b></dt>
<dd>then, <a href="#then32">3-2</a></dd>
<dt><b></b></dt>
<dd>to, <a href="#to32">3-2</a></dd>
<dt><b></b></dt>
<dd>trans, <a href="#trans31">3-1</a></dd>
<dt><b></b></dt>
<dd>true, <a href="#true23">2-3</a></dd>
<dt><b></b></dt>
<dd>Turbo Pascal, <a href="#Turbo Pascal40">4-0</a></dd>
<dt><b></b></dt>
<dd>type, <a href="#type21">2-1</a>, <a href="#type23">2-3</a><br /><br /></dd>
<dt><b></b></dt>
<dd>unit, <a href="#unit20">2-0</a></dd>
<dt><b></b></dt>
<dd>units, <a href="#units40">4-0</a><br /><br /></dd>
<dt><b></b></dt>
<dd>Variables, <a href="#Variables25">2-5</a></dd>
<dt><b></b></dt>
<dd>variant, <a href="#variant23">2-3</a></dd>
<dt><b></b></dt>
<dd>vector, <a href="#vector31">3-1</a></dd>
<dt><b></b></dt>
<dd>vpc, <a href="#vpc51">5-1</a><br /><br /></dd>
<dt><b></b></dt>
<dd>while, <a href="#while32">3-2</a></dd>
<dt><b></b></dt>
<dd>with, <a href="#with32">3-2</a></dd>
<dt><b></b></dt>
<dd>word, <a href="#word23">2-3</a></dd>
<dt><b></b></dt>
<dd>write, <a href="#write33">3-3</a></dd>
<dt><b></b></dt>
<dd>writeln, <a href="#writeln33">3-3</a></dd>
</dl></td></tr></table>
<p>
<h2>Bibliography</h2>
<dl compact="compact">
<dt><a href="#CITEThreeL" name="ThreeL">[1]</a></dt><dd>
3L Limited, Parallel C V2.2, Software Product Description, 1995.
<p>
</dd>
<dt><a href="#CITEAMD" name="AMD">[2]</a></dt><dd>Advanced Micro Devices, 3DNow! Technology Manual, 1999.
</dd>
<dt><a href="#CITE2" name="2">[3]</a></dt><dd>Aho, A.V., Ganapathi, M, TJiang S.W.K., Code Generation Using Tree Matching
and Dynamic Programming, ACM Trans, Programming Languages and Systems 11, no.4,
1989, pp.491-516.
<p>
</dd>
<dt><a href="#CITEblelloch" name="blelloch">[4]</a></dt><dd>
Blelloch, G. E., Nesl: A Nested Data-Parallel Language, Carnegie
Mellon University, CMU-CS-95-170, Sept 1995.
<p>
</dd>
<dt><a href="#CITEBurke" name="Burke">[5]</a></dt><dd>Burke, Chris, J User Manual, ISI, 1995.
</dd>
<dt><a href="#CITECattel80" name="Cattel80">[6]</a></dt><dd>Cattell R. G. G., Automatic derivation of code generators from machine descriptions,
ACM Transactions on Programming Languages and Systems, 2(2), pp. 173-190, April
1980.
</dd>
<dt><a href="#CITEChaitin" name="Chaitin">[7]</a></dt><dd>Chaitin. G., Elegant Lisp Programs, in The Limits of Mathematics, pp. 29-56,
Springer, 1997.
</dd>
<dt><a href="#CITECheong97" name="Cheong97">[8]</a></dt><dd>Cheong, G., and Lam, M., An Optimizer for Multimedia Instruction Sets, 2nd SUIF
Workshop, Stanford University, August 1997.
</dd>
<dt><a href="#CITECherry" name="Cherry">[9]</a></dt><dd> Cherry, G., W., Pascal Programming Structures, Reston Publishing, Reston, 1980.
</dd>
<dt><a href="#CITECockshott00" name="Cockshott00">[10]</a></dt><dd>Cockshott, Paul, Direct Compilation of High Level Languages for Multi-media
Instruction-sets, Department of Computer Science, University of Glasgow, Nov
2000.
<p>
</dd>
<dt><a href="#CITEEwing" name="Ewing">[11]</a></dt><dd>
Ewing, A. K., Richardson, H., Simpson, A. D., Kulkarni, R., Writing Data
Parallel Programs with High Performance Fortran, Edinburgh Parallel Computing
Centre, Ver 1.3.1.
<p>
</dd>
<dt><a href="#CITEgraham80" name="graham80">[12]</a></dt><dd>Susan L. Graham, Table Driven Code Generation, IEEE Computer, Vol 13, No. 8,
August 1980, pp 25..37.
</dd>
<dt><a href="#CITEIA32" name="IA32">[13]</a></dt><dd>Intel, Intel Architecture Software Developers Manual Volumes 1 and 2, 1999.
</dd>
<dt><a href="#CITEIntel00" name="Intel00">[14]</a></dt><dd>Intel, Willamette Processor Software Developer's Guide, February, 2000.
</dd>
<dt><a href="#CITEISO90" name="ISO90">[15]</a></dt><dd>ISO, Extended Pascal ISO 10206:1990, 1991.
</dd>
<dt><a href="#CITEISO90a" name="ISO90a">[16]</a></dt><dd>ISO, Pascal, ISO 7185:1990, 1991.
<p>
</dd>
<dt><a href="#CITEIverson62" name="Iverson62">[17]</a></dt><dd>K. E. Iverson, A Programming Language, John Wiley & Sons, Inc., New York (1962),
p. 16.
</dd>
<dt><a href="#CITEIverson80" name="Iverson80">[18]</a></dt><dd>Iverson, K. E. . Notation as a tool of thought. Communications of the ACM, 23(8),
444-465, 1980.
</dd>
<dt><a href="#CITEJmanual" name="Jmanual">[19]</a></dt><dd>Iverson K. E, A personal View of APL, IBM Systems Journal, Vol 30, No 4, 1991.
</dd>
<dt><a href="#CITEJintro" name="Jintro">[20]</a></dt><dd>Iverson, Kenneth E., J Introduction and Dictionary, Iverson Software Inc. (ISI),
Toronto, Ontario, 1995. 4, pp 347-361, 2000.
</dd>
<dt><a href="#CITEJensen" name="Jensen">[21]</a></dt><dd>Jensen, K., Wirth, N., PASCAL User Manual and Report, Springer 1978.
<p>
</dd>
<dt><a href="#CITEJohnston" name="Johnston">[22]</a></dt><dd>
Johnston, D., C++ Parallel Systems, ECH: Engineering Computing Newsletter,
No. 55, Daresbury Laboratory/Rutherford Appleton Laboratory, March 1995,pp 6-7.
</dd>
<dt><a href="#CITEKnuth" name="Knuth">[23]</a></dt><dd> Knuth, D., Computers and Typesetting, Addison Wesley, 1994.
</dd>
<dt><a href="#CITEKrall00" name="Krall00">[24]</a></dt><dd>
Krall, A., and Lelait, S., Compilation Techniques for Multimedia Processors,
International Journal of Parallel Programming, Vol. 28, No. 4, pp 347-361, 2000.
<p>
</dd>
<dt><a href="#CITELamport" name="Lamport">[25]</a></dt><dd> Lamport, L., <span class="roman">L</span><sup><span class="roman">A</span></sup><span class="roman">T</span><sub><span class="roman">E</span></sub><span class="roman">X</span>a document preparation system, Addison Wesley, 1994.
<p>
</dd>
<dt><a href="#CITELeupers99" name="Leupers99">[26]</a></dt><dd>Leupers, R., Compiler Optimization for Media Processors, EMMSEC 99/Sweden 1999.
<p>
</dd>
<dt><a href="#CITEMarx" name="Marx">[27]</a></dt><dd>Marx, K., 1976,<i>Capital </i>, Volume I, Harmondsworth: Penguin/New Left
Review.
<p>
</dd>
<dt><a href="#CITEMetcalf96" name="Metcalf96">[28]</a></dt><dd>Metcalf, M., and Reid., J., The F Programming Language, OUP, 1996.
</dd>
<dt><a href="#CITEPeleg97" name="Peleg97">[29]</a></dt><dd>Peleg, A., Wilke S., Weiser U., Intel MMX for Multimedia PCs, Comm. ACM, vol
40, no. 1 1997.
<p>
</dd>
<dt><a href="#CITEShannon" name="Shannon">[30]</a></dt><dd>
Shannon, C., A Mathematical Theory of Communication, The Bell System Technical
Journal, Vol 27, pp 379-423 and 623-656, 1948.
<p>
</dd>
<dt><a href="#CITESnyder" name="Snyder">[31]</a></dt><dd>
Snyder, L., A Programmer's Guide to ZPL, MIT Press, Cambridge, Mass, 1999.
<p>
</dd>
<dt><a href="#CITESreraman00" name="Sreraman00">[32]</a></dt><dd>Srereman, N., and Govindarajan, G., A Vectorizing Compiler for Multimedia Extensions,
International Journal of Parallel Programming, Vol. 28, No. 4, pp 363-400, 2000.
<p>
</dd>
<dt><a href="#CITEStrachey" name="Strachey">[33]</a></dt><dd>
Strachey, C., Fundamental Concepts of Programming Languages, University of
Oxford, 1967.
<p>
</dd>
<dt><a href="#CITEsable" name="sable">[34]</a></dt><dd>\' Etienne Gagnon, SABLECC, AN OBJECT-ORIENTED COMPILER FRAMEWORK, School
of Computer Science McGill University, Montreal, March 1998.
</dd>
<dt><a href="#CITETexas" name="Texas">[35]</a></dt><dd>Texas Instruments, TMS320C62xx CPU and Instruction Set Reference Guide, 1998.
</dd>
<dt><a href="#CITEWirth" name="Wirth">[36]</a></dt><dd> Wirth, N., Recollections about the development of Pascal, in <em>
History of Programming Languages-II</em>, ACM-Press, pp 97-111, 1996.</dd>
</dl>
<hr /><h3>Footnotes:</h3>
<p>
<a name="tthFtNtAAB"></a><a href="#tthFrefAAB"><sup>1</sup></a>Note this differs from ISO Pascal which allows a comment starting with { to
terminate with *) and vice versa.
<p>
<a name="tthFtNtAAC"></a><a href="#tthFrefAAC"><sup>2</sup></a>The notation used for grammar definition is a tabularised BNF . Each boxed table
defines a production, with the production name in the left column. Each line
in the right column is an alternative for the production. The metasymbol + indicates
one or more repetitions of what immediately preceeds it. The Kleene star *
is used for zero or more repetitions. Terminal symbols are in single quotes.
Sequences in brackets [ ] are optional.
<p>
<a name="tthFtNtAAD"></a><a href="#tthFrefAAD"><sup>3</sup></a>When pixels are represented as integers in the range 0..255, a 50% contrast
reduction has to be expressed as ((p<font face="symbol">-</font
>128)<font face="symbol">¸</font
>2)+128 .
<p>
<a name="tthFtNtAAE"></a><a href="#tthFrefAAE"><sup>4</sup></a> ISO Pascal requires
the base type to be a scalar type, a character type, integer
type or a subrange thereof. When the base type is one of these, Vector Pascal implements
the set using bitmaps. When the type is other than these, balanced binary trees are used.
It is strongly recomended that use be made of Boehm garbage collector (see section <a href="#garbage">5.1.2</a>) if non-bitmapped
sets are used in a program.
<p>
<a name="tthFtNtAAF"></a><a href="#tthFrefAAF"><sup>5</sup></a>The Pascal concept of static variables should not be equated with the notion
of static variables in some other languages such as C or Java. In Pascal a variable
is considered static if its offset either relative to the stack base or relative
to the start of the global segment can be determined at compile/link time. In
C a variable is static only if its location relative to the start of the global
segment is known at compile time.
<p>
<a name="tthFtNtAAG"></a><a href="#tthFrefAAG"><sup>6</sup></a>see section <a href="#block">4</a>.
<p>
<a name="tthFtNtAAH"></a><a href="#tthFrefAAH"><sup>7</sup></a>See section <a href="#manimplicitindices">3.2.1</a>.
<p>
<a name="tthFtNtAAI"></a><a href="#tthFrefAAI"><sup>8</sup></a>This compilation strategy requires that true is equivalent to -1 and false to
0. This is typically the representation of booleans returned by vector comparison
instructions on SIMD instruction sets. In Vector Pascal this representation
is used generally and in consequence, <tt>true</tt> < <tt>false</tt>.
<p>
<a name="tthFtNtAAJ"></a><a href="#tthFrefAAJ"><sup>9</sup></a>Vector Pascal allows function results to be of any non-procedural type.
<br /><br /><hr /><small>File translated from
T<sub><font size="-1">E</font></sub>X
by <a href="http://hutchinson.belmont.ma.us/tth/">
T<sub><font size="-1">T</font></sub>H</a>,
version 3.00.<br />On 13 Feb 2007, 10:52.</small>
</html>