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.

Chapter 6<br />

Declarations<br />

Declarations introduce named entities; we say that a declaration declares an entity and a name by which that entity<br />

can be referred to, and that the declared name refers to the declared entity. As discussed later, there is not a one-one<br />

correspondence between declarations and named entities: some declarations declare multiple named entities, some<br />

declare multiple names, and some named entities are declared by multiple declarations.<br />

Some declarations contain other declarations. For example, a trait declaration may contain method declarations, and a<br />

function declaration may contain parameter declarations.<br />

Syntactically, the positions in which a declaration may legally appear is determined by the nonterminal Decl in the<br />

<strong>Fortress</strong> grammar, defined in Appendix G.<br />

6.1 Kinds of Declarations<br />

Syntax:<br />

Decl ::= TraitDecl<br />

| ObjectDecl<br />

| FnDecl<br />

| VarDecl<br />

| DimUnitDecl<br />

| TypeAlias<br />

| TestDecl<br />

| PropertyDecl<br />

<strong>The</strong>re are two kinds of declarations: top-level declarations and local declarations.<br />

Top-level declarations occur at the top level of a program (or component), not within any other declaration or expression.<br />

A top-level declaration is one of the following: 1<br />

• trait declarations (see Chapter 9)<br />

• object declarations (see Chapter 10), which may be parameterized or nonparameterized<br />

• top-level function declarations (see Chapter 12), including top-level operator declarations (see Chapter 16)<br />

1 <strong>The</strong> <strong>Fortress</strong> component system, defined in Chapter 22, includes declarations of components and APIs. Because component names are not used<br />

in a <strong>Fortress</strong> program and API names are used only in qualified names and declarations of import and export , we do not discuss them in this<br />

chapter.<br />

54

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

Saved successfully!

Ooh no, something went wrong!