Evlan
Syntax
Last updated at 2005/04/23 10:19:42 PDT by Temporal

Text

Evlan programs are written in UTF-8 text. However, characters beyond the 7-bit ASCII range may only be used in string and character literals.

Comments and Whitespace

Comments in Evlan begin with a # (number sign) and extend to the end of the line:

#this is a comment

Comments will be ignored by the interpreter except when used by the documentation system (described elsewhere).

Whitespace in Evlan is only necessary for two purposes:

  • To separate two tokens which would otherwise be interpreted as a single token.

  • Indentation for blocks, as described later in this section.

Other than these two cases, whitespace is simply ignored.

Tokens

At the lowest level, Evlan programs are composed of tokens. The following types of tokens are used to build expressions:

  • Identifiers: Any string starting with a letter and followed by letters or numbers. Identifiers are used as names for values. You can even use keywords as identifiers by prefixing the token with a $ (dollar sign). For example:

    $if = 5

    Normally, "if" would be interpreted as a keyword, but here it is forced to be used as an identifier. You can prefix any identifier with a $, whether it clashes with a keyword or not. For example, "$i" and "i" are considered equivalent.

  • Keywords: The following words are keywords in Evlan, and may not be used as identifiers unless prefixed with a $: and, array, catch, do, else, false, finally, if, import, not, object, of, or, return, then, throw, true, try, where.

  • Symbols: The following symbols have special meaning in Evlan: . , => ( ) { } [ ] = := \ :: + - * / % ^ == < > <= >= !=

And these tokens are literals; that is, each token is itself a complete expression with a constant value:

  • Booleans: The keywords "true" and "false" are literal boolean values.

  • Numbers: Numbers -- both integers and reals -- are expressed in base 10. A real number with a non-integral value can be expressed using normal decimal point notation. Scientific notation can be expressed using an "e" (such as "1.0e10"), though using "*10^" (such as "1.0*10^10") is encouraged. Note that the Evlan 0.3 virtual machine does all numerical computation using double-precision floating points, so there is no internal distinction between integers and real numbers.

  • Data: Raw data is expressed in hexadecimal notation, prefixed with "0x". Data values must come in sizes which are a power of two. For example, you can express a 32-bit data value as "0x1234abcd". Unlike some other languages, Evlan makes a distinction between data and integers. Integers can be represented using data, but integers are considered a higher structure.

  • Characters: Single characters surrounded by single-quotes are interpreted as literal characters. A string of characters surrounded by double-quotes are interpreted as an array of characters. Multiple adjacent string tokens will automatically be concatenated. C-style escape sequences using backslashes are used to represent characters which cannot simply be typed as-is (such as quotes and newlines). Evlan uses the same set of escape sequences as C.

  • Atoms: If a token which would otherwise be an identifier is prefixed with an @ (at sign), it becomes an atom literal. Two atoms are equal if they have the same name, and not equal otherwise. They are convenient to use when a variable has a discrete set of possible values which are more conveniently identified by name than by number. Manipulating atoms is as efficient as manipulating integers and much more efficient than strings.

Examples of tokens:

a $x myIdent MyIdent2 $if  #identifiers
if then where of           #keywords
+ - % == =>                #symbols
true false                 #booleans
1 5 2.3 0.05 4.7e4         #numbers
0x15 0x1234 0xbaadf00d     #data
'a' 'x' '\'' '\n'          #characters
"Hello world!"             #character array
@a @red @black @myAtom     #atoms

Blocks and Indentation

Evlan uses indentation to delimit blocks of code. This is done both to enforce good indentation style as well as to make Evlan code easier to read and write.

The keywords "where", "of", and "do" are block keywords. This means that their presence at the end of a line of code means that the next line begins a new block. A block is composed of several statements, each of which is one or more lines of code. The first line of a statement must be preceded by the exact same amount of white space as all other statements in the block. A long statement can be broken up into multiple lines as long as each additional line is indented beyond the first line. A block's indentation must be greater than that of the block containing it. The end of a block is marked by the first line which is indented less than the block's statements.

The following code fragment shows some examples of blocks. Here, each block is highlighted by a gray bar along its left edge. This bar is only syntax highlighting, not something you need to type.

#from /evlan.org/protocol/http/Server, line 69
addConnection = clientAddress => do
   potentialSemaphore := Thread.makeSemaphore(perIpServiceLimit)
   semaphore := connections.update of
      oldState => result where
         oldClient = oldState.find(clientAddress)
         newClient =
            if oldClient.isEmpty
               then object of
                  semaphore = potentialSemaphore
                  count = 1
               else object of
                  semaphore = oldClient.value.semaphore
                  count = oldClient.value.count + 1
         result = object of
            newState = oldState.insert(clientAddress, newClient)
            result = newClient.semaphore
   return semaphore
evlan.org © Copyright 2003-2005 Kenton Varda
Powered by Io Community Manager, Evlan, and FreeBSD