This chapter describes many of the basic building blocks of
the ScriptX language, including expression syntax, comments,
lexical constructs such as end-of-line, literals such as
numbers and strings, variable scope, declaration, assignment,
and simple operators.
Expressions
2
+
2
yields an
ImmediateInteger
object whose value is
4
. End-of-Line
a <
b
as follows:a <
b
a
< b
a
is a complete expression in ScriptX,
the end-of-line after a
is considered the end of
the expression. The second line would then result in an error,
since the ScriptX bytecode compiler expects to find a new
expression beginning on that line.
->
).
\
) to indicate
all line breaks, even in cases where it is not required by
ScriptX syntax. Most programmers break lines only in obvious
places, such as after separators and binary operators.A script cannot be broken in the middle of a literal (such as a number or string) without causing a syntax error, or changing the meaning of the expression.
-- this example generates a syntax error
global myArray := #(33, 44, 55, 6
6, 77, 88, 99)
-- ** Syntax error: ("syntax error") at "6" (SyntaxError)
In the next example, the line break is interpreted as a newline character:
global myString := "This is my
string"
"This is my
string"
To force evaluation of an incomplete sentence in the scripter, type
!!
and press enter. Two
exclamation marks act as a terminator, allowing you to begin
entering a new expression. If the expression that the scripter
was currently evaluating is incomplete, termination reports a
syntax error.
(a + b) < !!
-- ** Syntax error: ("syntax error") at "(a + b) < !" (SyntaxError)
For more information on ScriptX syntax and expressions, see Appendix A, "ScriptX Reference."
Continuation Over Multiple Lines
\
) at the end of the line. 1 + 2 + 3 \
+ 4 + 5
print "This is an example of a very long expression, one that \
is too long to fit on one line."
print
function. Function calls are the most common case of an
expression that is too long to fit on one line but cannot be
split over multiple lines unless you use a backslash. Function
calls are described in further detail in Chapter 3, "Working with Objects."
Finally, multiple expressions can be placed on one line,
separated by semicolons:
t := b * b; if t < j then t else j; print b; print t
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.