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.

Appendix G<br />

Concrete Syntax<br />

In this chapter, we describe the concrete syntax of <strong>Fortress</strong> programs in BNF notation. This syntax is “human-readable”<br />

in the sense that it does not describe uses of whitespaces and semicolons exactly. Instead, they are described as follows.<br />

<strong>Fortress</strong> has three different contexts influencing the whitespace-sensitivity of expressions:<br />

statement Expressions immediately enclosed by a block expression are in a statement-like context. Multiple expressions<br />

can appear on a line if they are separated (or terminated) by semicolons. If an expression can legally end<br />

at the end of a line, it does; if it cannot, it does not. A prefix or infix operator that lacks its last operand prevents<br />

an expression from ending. For example,<br />

an = expression+<br />

spanning+<br />

four+<br />

lines<br />

a = oneLiner<br />

four();on();one();line();<br />

nested An expression or list of expressions immediately enclosed by parentheses or braces is nested. Multiple expressions<br />

are separated by commas, and the end of a line does not end an expression. Because of this effect,<br />

the meaning of a several lines of code can change if they are wrapped in parentheses. Parentheses can also be<br />

used to ensure that a multiline expression is not terminated prematurely without paying special attention to line<br />

endings.<br />

lhs = rhs<br />

−aSeparateExpression<br />

postProfit(revenue<br />

−expenses)<br />

pasted <strong>Fortress</strong> has special syntax for matrix pasting. Within square brackets, whitespace-separated expressions are<br />

treated (depending on their type) as either matrix elements or submatrices within a row. Because whitespace<br />

is the separator, it also ends expressions where possible. In addition, newline-or-semicolon-separated rows are<br />

pasted vertically along their columns. Higher-dimensional pasting is expressed with repeated semicolons, but<br />

repeated newlines do not have the same effect.<br />

id2a = [1 0; 0 1 ]<br />

id2b = [1 0;<br />

0 1 ]<br />

id2c = [1 0<br />

0 1 ]<br />

375

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

Saved successfully!

Ooh no, something went wrong!