19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

13.10 Assignments<br />

Syntax:<br />

Expr ::= Expr AssignOp Expr<br />

AssignOp ::= := | Op=<br />

An assignment expression consists of a left-hand side indicating one or more variables or a subscripted expression (as<br />

described in Section 34.7) to be updated, an assignment token, and a right-hand-side expression.<br />

<strong>The</strong> assignment token may be ‘ := ’, to indicate ordinary assignment; or may be any operator (other than ‘ : ’ or ‘ = ’<br />

or ‘ < ’ or ‘ > ’) followed by ‘ = ’ with no intervening whitespace, to indicate compound (updating) assignment. A<br />

compound assignment is a syntactic sugar; for example, x += e is a shorthand for x := x + e . An assignment<br />

expression evaluates its right-hand-side expression and binds its left-hand side to the value of the right-hand-side. An<br />

assignment expression performs a memory write operation.<br />

A left-hand side of an assignment expression may be a single variable, a subscripted expression, or n variables using<br />

tuple notation. If tuple notation is used, then the right-hand side must be an expression which ultimately evaluates to a<br />

tuple of length n or a function application that returns a tuple of n values. Variables updated in assignment expressions<br />

must be already declared. <strong>The</strong> value of an assignment expression is () .<br />

Here are some examples:<br />

x := f(0)<br />

c ij := c ij + a ik b kj<br />

(a, b, c) := (b, c, a) (∗ Permute a, b, and c ∗)<br />

x += 1<br />

(x, y) += (δ x , δ y )<br />

myBag = myBag ∪ newItems<br />

myBag∪ = newItems<br />

13.10.1 Definite Assignment<br />

References to uninitialized variables are statically forbidden. As with the Java Programming <strong>Language</strong>, this static<br />

constraint is ensured with a specific conservative flow analysis. In essence, an initialization of a variable must occur<br />

on every possible execution path to each reference to a variable. Variable initialization is performed in a local scope<br />

analogously to the rules for top-level initialization of simple components, defined in Section 22.6.<br />

13.11 Do Expressions<br />

Syntax:<br />

Flow ::= Do<br />

Do ::= do BlockElem ∗ end<br />

BlockElem ::= Expr[ , GeneratorList]<br />

| LocalVarFnDecl<br />

A do expression consists of the special reserved word do , a series of expressions, a generated expressions (described<br />

in Section 13.11.1) local variable declarations, or local function declarations (block expression), and the special reserved<br />

word end . <strong>The</strong> last of the block expression must not be a local declaration. A do expression evaluates its<br />

subexpressions and local declarations in order. <strong>The</strong> value and type of a do expression is the value and type of the last<br />

expression in the block expression. Each do expression introduces a new scope. Some compound expressions have<br />

clauses that are implicitly block expressions.<br />

97

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!