Operator Description Associativity
function call, [] left
-, ! integer and logical negation —
*, *>>, /, % multiplication, high multiplication, division, remainder left
+, - addition, subtraction left
<, <=, >=, > comparison operators left
==, != equality operators left
& logical and left
| logical or left
6 Statements
The legal statements, also called commands, are the following:
•
An assignment to a variable or to an array element. However, the left-hand side of an assignment (and
thus the assignment itself) cannot begin with an open parenthesis (() or an open brace ({).
• if
and
while
statements with syntax similar to that in C and Java except that parentheses are not required
in the guard expression of each.
•
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 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
statement may be used instead, except in a function definition. However, a
return
statement may not be
used in place of a block.
•
A variable declaration, with an optional initialization expression. It may declare multiple variables, in
which case there must be an initialization expression that is a function call with the appropriate return
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 “
\xHHHH
”, where
HHHH
stands for 1–4 hexadecimal
digits (upper or lower case), representing the Unicode character with the corresponding index. For example
“\x0a” is the same as “\n”.
8 Source files and interfaces
The Xi compiler compiles a source file with extension
.xi
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
.ixi
. To use the procedures and
functions declared in interface file
F.ixi
, a source file includes the top-level declaration “
use F
”, optionally
CS4120/4121/5120/5121 Spring 2020 5/6 Xi Language Specification