• if
and
while
statements with syntax similar to that in C and Java except that parentheses are not required
in guard expressions.
•
A
return
statement. In a procedure, this is written just as
return
; in a function with a return type, the
value(s) to be returned follow the
return
keyword, separated by commas. Unlike in Java, a
return
statement may only be used inside a block and must be the last statement in its immediately enclosing
block.
• A call to a procedure (but not a function).
•
A block of statements, surrounded by braces. A block may be empty or may contain a sequence of
statements. Each statement in a block may be terminated by a semicolon, but semicolons are entirely
optional, even if statements are on the same line. Anywhere a block of statements is expected, a single
(non-
return
) statement may be used instead, except in a function definition, where a full block is required.
•
A variable declaration, with an optional initialization expression. It may declare multiple variables,
in which case it may be initialized with either a function call with the appropriate return types or a
comma-separated list of expressions of the right types.
7 Lexical considerations
The language is case-sensitive. An input file is a sequence of Unicode characters, encoded using UTF-8.
Therefore ASCII input is always valid.
Comments are indicated by a double slash
//
followed by any sequence of characters until a newline
character.
Keywords (
use
,
if
,
while
,
else
,
return
,
length
) may not be used as identifiers. Nor may the names or
values of the primitive types (int, bool, true, false).
String and character literals should support some reasonable set of character escapes, including at
least “
\\
”, “
\n
”, and “
\’
”. In addition, an escape of the form “
\x{HHHHHH}
”, where
HHHHHH
stands for 1–6
hexadecimal digits (upper or lower case), represents the Unicode character with the corresponding code. For
example “\x{0a}” is the same as “\n”.
You may be more successful parsing negative integer literals as the negation of a positive literal.
8 Source files and interfaces
The Eta compiler compiles a source file with extension
.eta
to runnable code. It may also read in interface
files that describe external code to be used by the program.
Interface files contain a nonempty set of procedure and function declarations without implementations
and may contain end-of-line comments. Interface files have the extension
.eti
. To use the procedures and
functions declared in interface file
F.eti
, a source file includes the top-level declaration “
use F
”, optionally
terminated by a semicolon. This causes the compiler to look for
F.eti
. All such “
use
” declarations must
precede all procedure and function definitions.
Multiple “
use
” declarations are permitted within one source file. The same function or procedure may
be declared in multiple
.eti
files that are read in and may also be defined in the source file, but its signature
must match everywhere it appears. Therefore, it is legal to reference an interface more than once in a source
file.
9 Current library interfaces
Interfaces for I/O and corresponding libraries are available, including the following functions from interface
file io:
CS4120/4121/5120/5121 Spring 2023 6/7 Eta Language Specification