19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13<br />

Expressions<br />

<strong>Fortress</strong> is an expression-oriented language. Syntactically, the positions in which an expression may legally appear<br />

(value context) is determined by the nonterminal Expr in the <strong>Fortress</strong> grammar, defined in Appendix G.<br />

13.1 Literals<br />

Syntax:<br />

Value ::= Literal<br />

<strong>Fortress</strong> provides boolean literals, () literal, character literals, string literals, and numeric literals. Literals are values;<br />

they do not require evaluation.<br />

<strong>The</strong> literal false has type BooleanLiteralfalse . <strong>The</strong> literal true has type BooleanLiteraltrue .<br />

<strong>The</strong> literal () is the only value with type (). Whether any given occurrence of () refers to the value () or to the type<br />

() is determined by context.<br />

A character literal has type Character. Each character literal consists of an abstract character in Unicode 5.0 [25],<br />

enclosed in single quotation marks (for example, ‘a’, ‘A’, ‘$’, ‘α’, ‘⊕’). For convenience, the single quotes may be<br />

either true typographical “curly” single quotation marks or a pair of ordinary apostrophe characters (for example, ’a’,<br />

’A’, ’$’, ’α’, ’⊕’). See Section 5.9 for a description of how names of characters may be used rather than actual<br />

characters within character literals, for example ‘APOSTROPHE’ and ‘GREEK CAPITAL LETTER GAMMA’.<br />

A string literal has type String. Each string literal is a sequence of Unicode 5.0 characters enclosed in double quotation<br />

marks (for example, “Hello, world!” or “π r 2 ”). For convenience, the double quotes may be either true typographical<br />

“curly” double quotation marks or a pair of “neutral” double-quote characters (for example, "Hello, world!"<br />

or "π r 2 "). Section 5.10 also describes how names of characters may be used rather than actual characters within<br />

string literals. One may also use the escape sequences \b and \t and \n and \f and \r as described in [5].<br />

Numeric literals in <strong>Fortress</strong> are referred to as numerals, corresponding to various expressible numbers. Numerals may<br />

be either simple or compound (as described in Section 5.13).<br />

A numeral containing only digits (let n be the number of digits) has type NaturalNumeraln, 10, v where v is the<br />

value of the numeral interpreted in radix ten. If the numeral has no leading zeros, or is the literal 0 , then it also has<br />

type Literalv .<br />

A numeral containing only digits (let n be the number of digits) then an underscore, then a radix indicator (let r be the<br />

radix) has type NaturalNumeralWithExplicitRadixn, r, v where v is the value of the n-digit numeral interpreted<br />

in radix r.<br />

91

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

Saved successfully!

Ooh no, something went wrong!