Literals are sequences of characters that are a literal representation of instances of one of a special set of classes. The value of a literal is the object it represents. Literals are tokens in the input stream that the bytecode compiler recognizes as objects. ScriptX provides string literals, name literals, numeric constants, and several kinds of collections and ranges as literal objects.
symbol ::= initialChar [ trailingChar ]*
initialChar ::= alphaChar | underscore
trailingChar ::= alphaChar | underscore | decimalDigit
alphaChar ::= a | b | c | . . . | x | y | z
decimalDigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
underscore ::= _
A symbol is a lexical name, a name that is understood by the compiler. The compiler associates a symbol at compile time with the thing in a program that it names, such as a variable, constant, or function.
RootObject
class provides each object with a default version of the methods isComparable
, localLT
, localEqual
, and eq
. These four generic functions are visible to the scripter. A class can override these generics to provide its own version of the Comparison protocol. In this way, the number and string classes have different definitions of equality. Table A-2 indicates the precedence and associativity of operators in the ScriptX language. In this table, precedence is ordered from highest to lowest.
Most ScriptX operators can be used with or without white space. Careful use of white space, which is defined on page 233, can make a program more readable. Certain operators require a separator to prevent ambiguity. Operators that are reserved words, such as contains
or as
, must be set off by a separator, normally a blank. The subtraction operator requires a separator, normally a blank, so that the compiler can distinguish it from the negation operator.
Reserved Words
Punctuation Marks and Meta-Characters
--
) or two slashes ( //
) and ends with a new line or carriage return as a comment. A comment can be inserted in the middle of an expression; interpretation of the expression will resume on the next line. ScriptX also accepts C-style inset comments, using the same delimiters. ScriptX, in contrast with ANSI C, allows inset comments to be nested.
In most cases, this grammar does not explicitly indicate where end-of-line and white space characters are allowed, except where an end-of-line character is required as a separator. An incomplete sentence can be broken with a newline character; evaluation of the expression resumes on the following line. ScriptX programmers commonly break lines after a binary operator, after a separator that cannot act as white space, or anywhere where the compiler is expecting a closing delimiter such as a parenthesis.
function doIt a b -> (
print a; print b
)
doIit -1 -2
-1
-2
doIt -(1) -(2)
no sub instance method
doIt negate(1) negate(2)
too many arguments 4 supplied 2 allowed
doIt (negate(1)) (negate(2))
-1
-2
Literals
NameClass
. Any valid name that is preceded by an at sign ( @
) is interned. Name literals are full-fledged NameClass
objects that have the same value at compile time and run time. They are used as labels in programs, often to represent a state or outcome. Two name literals that have the same value are the same object. That is, the names @insideOut
, @insideout
, and @INSIDEOUT
are not merely equal, they are actually the same object.nameLiteral ::= @ [ trailingChar ]+
trailingChar ::= alphaChar | underscore | decimalDigit
stringLiteral ::= " [ unicodeChar ]* "
unicodeChar ::= -- any printing char
| escapeChar
| \< hexConst >
escapeChar ::= \n | \r | \t
hexDigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | a | b | c | d | e | f
hexConst ::= [ hexDigit ]+
StringConstant
object. To modify or edit a string literal, it must first be converted to the String
or Text
class. Although name literals and symbols are not case sensitive in ScriptX, strings are. For more information on strings, see the "Text and Fonts" chapter of ScriptX Components Guide.Number
: ImmediateInteger
, LargeInteger
, ImmediateFloat
, or Float
, depending on range and precision requirements. An integer constant is stored as an ImmediateInteger
object, except when its value extends beyond the 29-bit storage range of the class. ScriptX has no unsigned data types. A floating point constant is converted to either an ImmediateFloat
or a Float
object depending on both range and precision requirements. For more information, see the "Numerics" chapter of ScriptX Components Guide.numericConst ::= mantissa [ exponent ]
| hexLiteral
mantissa ::= integerConst [ .decimalDigit ] [ decimalDigit ]*
exponent ::= e integerConst
integerConst ::= [ negOperator ] [ decimalDigit ]+
negOperator ::= -
decimalDigit ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
hexLiteral ::= 0x [ hexDigit ]+
new
method or by using the object
expression. ScriptX creates instances of Array
, KeyedLinkedList
, ContinuousNumberRange
, and NumberRange
from literal expressions.arrayLiteral ::= #( exprList )
| #( keyedList )
| #( )
| #( : )
exprList ::= simpleExpr [ , exprList ]*
keyedList ::= factor : simpleExpr [ , keyedList ]*
rangeLiteral ::= factor to factor [ by factor ]
| factor by factor [ by factor ]
| factor to factor [ inclOption ] continuous
| factor inclOption to factor [ inclOption ] continuous
inclOption ::= inclusive | exclusive
new
on the appropriate class or by using an object definition expression.
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.