Appendix B
Lexical Structure

B.1

Lexical Program Structure

B.2

Comments

B.3

Reserved Keywords and Symbols

 

In this appendix the lexical structure of Clean is given. It describes the kind of tokens recognised by the scan­ner/parser. In particular it summarizes the keywords, symbols and characters which have a spe­cial meaning in the language.

B.1   Lexical Program Structure

In this Section the lexical structure of Clean is given. It describes the kind of tokens recognised by the scan­ner/parser. In particular it summarizes the keywords, symbols and characters which have a special meaning in the language.

 

LexProgram

=

{ Lexeme | {Whitespace}+ }

 

Lexeme

=

ReservedKeywordOrSymbol

// see Section B.3

 

|

ReservedChar

// see Section A.9

 

|

Literal

 

 

|

Identifier

 

Identifier

=

LowerCaseId

// see A.8

 

|

UpperCaseId

// see A.8

 

|

FunnyId

// see A.8

Literal

=

IntDenotation

// see A.9

 

|

RealDenotation

// see A.9

 

|

BoolDenotation

// see A.9

 

|

CharDenotation

// see A.9

 

|

CharsDenotation

// see A.9

 

|

StringDenotation

// see A.9

 

Whitespace

=

space

// a space character

 

|

tab

// a horizontal tab

 

|

newline

// a newline char

 

|

formfeed

// a formfeed

 

|

verttab

// a vertical tab

 

|

Comment

// see Section B.2

B.2   Comments

 

Comment

=

// AnythingTillNL newline

 

 

|

/* AnythingTill/* Comment AnythingTill*/ */

// comments may be nested

 

|

/* AnythingTill*/ */

 

AnythingTillNL

=

{AnyChar/~newline}

// no newline

AnythingTill/*

=

{AnyChar/~/*}

// no "/*"

AnythingTill*/

=

{AnyChar/~*/}

// no "*/"

AnyChar

=

IdChar

// see A.8

 

|

ReservedChar

 

 

|

Special

 

B.3   Reserved Keywords and Symbols

Below the keywords and symbols are listed which have a special meaning in the language. Some sym­bols only have a special meaning in a certain context. Outside this context they can be freely used if they are not a reserved character (see A.9). In the com­ment it is indicated for which context (name space) the symbol is predefined.

ReservedKeywordOrSymbol

=

 

// in all contexts:

 

/*

// begin of comment block

 

|

*/

// end of comment block

 

|

//

// rest of line is comment

 

|

::

// begin of a type definition

 

|

:==

// in a type synonym or macro definition

 

|

=

// in a function, graph, alg type, rec field, case, lambda

 

|

=:

// labeling a graph definition

 

|

=>

// in a function definition

 

|

;

// end of a definition (if no layout rule)

 

|

foreign

// begin of foreign export

 

// in global  definitions:

|

from

// begin of symbol list for imports

 

|

definition

// begin of definition module

 

|

implementation

// begin of implementation module

 

|

import

// begin of import list

 

|

module

// in module header

 

|

system

// begin of system module

 

// in function  definitions:

|

->

// in a case expression, lambda ab­straction

 

|

[

// begin of a list

 

|

:

// cons node

 

|

]

// end of a list

 

|

\\

// begin of list or array comprehension

 

|

<-

// list gen. in list or array comprehen­sion

 

|

<-:

// array gen. in list or array compre­hension

 

|

{

// begin of a record or array, begin of a scope

 

|

}

// end of a record or array, end of a scope

 

|

.

// a record or array selector

 

|

!

// a record or array selector (for unique objects)

 

|

&

// an update of a record or array, zipping gener.

 

|

case

// begin of case expression

 

|

code

// begin code block in a syst impl. mo­dule

 

|

if

// begin of a conditional expression

 

|

in

// end of (strict) let expression

 

|

let

// begin of let expression

 

|

#

// begin of let expression (for a guard)

 

|

#!

// begin of strict let expression (for a guard)

 

|

of

// in case expression

 

|

where

// begin of local def of a function alter­native

 

|

with

// begin of local def in a rule alternative

 

// in type specifications:

|

!

// strict type

 

|

.

// uniqueness type variable

 

|

#

// unboxed type

 

|

*

// unique type

 

|

:

// in a uniqueness type variable definition

 

|

->

// function type constructor

 

|

[],[!],[!!],[#],[#!]

// lazy list, head strict, strict, unboxed, unboxed strict

 

|

[|]

// overloaded list

 

|

(,),(,,),(,,,),…

// tuple type constructors

 

|

{},{!},{#}

// lazy, strict, unboxed array type constr.

 

|

infix

// infix indication in operator definition

 

|

infixl

// infix left indication in operator defini­tion

 

|

infixr

// infix right indication in operator defini­tion

 

|

Bool

// type Boolean

 

|

Char

// type character

 

|

File

// type file

 

|

Int

// type integer

 

|

Real

// type real

 

|

World

// type world

 

// in class  definitions:

|

export

// to reveal which class instances there are

 

|

class

// begin of type class definition

 

|

derive

// derive instance of generic function

 

 

|

special

// to create a specialized instance

 

|

instance

// def of instance of a type class