Coronavirus (Covid-19): Latest updates and information
Skip to main content Skip to navigation

Language basics

The Eden language has a number of C-like statements and operators. C programmers may find it familiar but they are still advised to go through this chapter since there are new data types and operators. Not all C operators have been implemented.

An Eden program is a list of statements. Each statement can be one of the followings: formula definitions, action specifications, function (procedure) definitions and C-like procedural statements.

program:
        statement program

When a procedural statement is encountered, this statement will be executed. The effect of execution is to evaluate an expression, assign values to variables or call other functions/procedures (these must be defined earlier). The order of statements reflects the order of execution, and thus affects the results of computation. The user is responsible for arranging the statements in proper order to get the correct results.

In addition, the EDEN interpreter will do the (re-)calculation of the formula definitions and/or invoke the procedures defined by the action specifications automatically. The order of calculation of formula definitions and execution of actions should not be of concern to the user, and is fully controlled by the interpreter.

The dependency-link command is an alternative way of specifying actions. The query command inspects the current definitions of the objects.

Lexical Conventions

There are five classes of tokens: identifiers, keywords, constants, operators, and other separators. Blanks, tabs, newlines, and comments (collectively, ``white space'') as described below are ignored except as they serve to separate tokens. Some white space is required to separate otherwise adjacent identifiers, keywords, and constants. If the input stream has been parsed into tokens up to a given character, the next token is taken to include the longest string of characters which could possibly constitute a token.

Syntax Notation

In the syntax notation used in this chapter, syntactic categories are indicated by italic type, literal words and characters in fixed-width font, and keywords in bold fixed-width font. Alternative categories are listed on separate lines. An optional terminal or non-terminal symbol is indicated by the subscript ``opt'', so that

[ expression-listopt ]

indicates an optional expression list enclosed in square brackets.

Comments

Comments are arbitrary strings of symbols placed between the delimiters /* and */. The whole sequence is equivalent to a white space. Note that /* */ can be nested. It is useful to comment a block of program with comments in it. Lines beginning with % (no even spaces or tabs before it) are also comment lines.

/* This is a comment */
/* --- Begin of comment ---
        /* This is a nested comment */
--- End of comment --- */
% This is a single-line comment

Comments are not parts of the executable program, but are used by the programmer as a documentation aid.

Identifiers (Names)

An identifier (name) consists of a sequence of letters and digits. The first character must be a letter. The underscore character _ is considered a letter. Eden imposes no limit on the number of characters in a name, but the implementation of the EDEN interpreter does (about 255 characters). An Eden keyword cannot be used as an identifier.

Examples of identifiers

hello
this_is_a_most_unusually_long_name
IF
foO
bAr
HorseSense
var1
var2
_auto_
_

Upper- and lowercase letters are distinct, so Count and count are different identifiers. An identifier is a symbolic name of a variable, function or other objects.

Examples of character sequences that cannot be used as identifiers:

012
a fool
$sys
auto
3var
pay.due
foo~bar
.name
if

Keywords

The following identifiers are reserved for use as keywords, and may not be used otherwise:

append
auto
break
case
continue
default
delete
do
else
for
func
if
insert
is
para
proc
return
shift
switch
while

Objects and Lvalues

An object is a manipulatable region of storage (NB the vocabulary we use here is based on the C reference manual - the term 'object' is not used in the OOP sense); an lvalue is an expression referring to an object. An obvious example of an lvalue expression is an identifier. There are operators which yield lvalues: for examples, if E is an expression of pointer type, then *E is an lvalue expression referring to the object to which E points. The name ``lvalue'' comes from the assignment expression E1 = E2 in which the left operand E1 must be an lvalue expression. The discussion of each operator below indicates whether it expects lvalue operands and whether it yields an lvalue.

An object can be any one of the following:

Read/Write Variables

A read/write variable (RWV) is a named storage that holds a data. The data can be any Eden data structure. There is no need to declare a variable before it is used. Memory storage is allocated when the variable name first appears in a program. Data can be assigned to RWV's using assignment statements. For example,

V = 1;

The identifier (name) V denotes an RWV whose value is assigned to integer 1 by the operator =. The semi-colon terminates the statement.

The value of an RWV is referenced if its name appears in an expression. If the RWV has not been assigned a value before its value is referenced, the value @ (meaning ``undefined'') is assigned to it automatically.

Different typed data can be assigned to the same variable at different time. The EDEN interpreter checks for data type clash at run-time.

The interpreter assumes all objects are RWV's until they are defined to be functions, formula definitions or action specifications.

Function Definition

A function definition is an object that stores an entry point (address) of a sequence of instructions (the function) which computes a result from the parameters. There are some functions pre-defined by the intepreter. The user can define his/her own functions using some procedural statements.

The value of a function definition is equivalent to the function (address of the instruction sequence).

Note that the interpreter allows an identifier designating a RWV to be re-used as a function name but not vice versa, because the intepreter assumes all objects are RWV's initially.

Formula Variable

A formula variable is an object that stores a formula expression (unlike a RWV which stores a value) and is bound to that expression using a formula definition. The value of a formula variable is equivalent to the current value of the formula expression that the variable stores. To optimize the computation speed, the formula variable also stores the up-to-date value of the formula expression. So, whenever, the value of the formula variable is referenced, this value is used. The interpreter is responsible for updating this value.

An identifier designating a RWV can be re-used to designate a formula variable and vice versa.

Action Specification

An action specification is an object that stores an entry point (address) of an instruction sequence - the action procedure. It also stores a list of objects on which the action depends. Whenever the values of these objects (usually are RWV's or formula variables) are changed the action procedure will be invoked by the system.

Note that the value of an action specification is equivalent to the address of the action procedure.

An identifier designating a RWV can be re-used as an action name but not vice versa.