Visviva Player | Visviva Tools | SDK for Developers | ScriptV

Overview Tutorial

ScriptV Language Reference

1. Lexical Conventions

This chapter describes the lexicon of ScriptV.  Contained in this chapter are all of the alphanumeric characters used in the ScriptV language, as well as the ways these characters are combined to form the "Lexical Elements" that ScriptV recognizes as legal programming instructions.

1.1.    Character Set

Below are the characters that are used to write ScriptV programs.  The sum total of all the characters that can be used to write a source code is called a Character Set.  A ScriptV source is a sequence of characters selected from this character set.  A ScriptV interpreter may use any character set, as long as it includes the following standard characters that constitute the lexical elements of ScriptV.

An AlphabeticCharacter is one of the following:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

a b c d e f g h i j k l m n o p q r s t u v w x y z

A DecimalDigit is one of the following:

0 1 2 3 4 5 6 7 8 9

This is an Underscore:

_

Separators: refers to one of

{ } ( ) [ ] , ; ' " #

An Operator Character is one of the following:

! # $ % ^ & * - + = ~ \ [ ] | : . < > / ? @

A WhiteSpace can be one or more of the following:

blank

horizontal or vertical tab

newline

formfeed

comment

1.2.    Comments

A comment is a piece of text that serves to explain certain lines of code.  This code explanation is solely for the edification of the reader and does not contribute any meaning to a ScriptV program.

A comment in a ScriptV program begins with the characters /* and ends with a matched */.

A comment can also begin with the characters // and end with the first subsequent occurrence of a new line.

Comments enclosed by /* and */ can be nested.

Here are some examples of ScriptV comments:

object xyz /* comment: xyz is an object name */

       is XYZ  // comment: XYZ is a class name

{

       /* comment: here is the body of the object

             /* with a nested comment here */

       */

}

1.3.    Lexical Elements

The ScriptV character set may be grouped into four different types of lexical elements:

Identifiers:                A continuous sequence of characters used as names for objects, classes, attributes, functions, etc.

Keywords:                 A continuous sequence of characters reserved for lexical elements that have specific meanings in ScriptV.

Operator strings:     A continuous sequence of operator characters used for specific function names, such as +, -, *, /, and ++.

Literals:                     The fundamental representation of the value of an object, such as an object's integer value, floating-point number value, character string, etc.

 

How to Separate Lexical Elements:

Lexical elements are most commonly separated by white spaces.  For instance, the following text

object xyz is XYZ

contains four lexical elements, each separated from the next by a blank space.

Separator characters can also separate lexical elements.  For example:

x,y

The character sequence "x,y" is separated by a comma separator, and has three lexical elements: "x", ",", and "y".

Unlike white spaces, separators are lexical elements themselves.  As such, they have associated semantics.  Separators may be used to introduce a new scope in context.  Separators may also be used to change the priority in an expression’s associativity, separate parallel grammatical elements, constitute an operator string, and so forth.  Some separators must appear in pairs (like { }, [ ], etc.).

Each separator character is a lexical element that cannot be used in combination with other characters.  For example, the following string:

,,,

contains three separate lexical elements.  These elements do not combine into a single lexical element that has three commas.

 

 The four lexical elements are discussed in detail in the following sections.

1.3.1   Identifiers

An identifier is an arbitrarily long continuous sequence of alphabetic characters (a, b, c…), underscore symbols ( _ ), and decimal digits (1, 2, 3…). Identifiers are names that distinguish individual entities in ScriptV programs.  Identifiers name such program entities as objects, classes, and functions. 

The first character in an identifier must not be a decimal digit.  Though an underscore symbol can be used as the first character in an identifier, this is not a recommended procedure.  Identifiers with their first character as an underscore already have a specific usage as names for system entities

All alphabetic characters are significant in ScriptV.  Upper- and lower- case letters are different and will be read by ScriptV as such.  Therefore:

name

Name

NAME

are three different identifiers.

Here are some more examples of identifiers:

Sphere

sphere1

sphere_color

The following are not identifiers:

3D_Point

Percent

Laüfer

Identifiers are used internally by the computer to distinguish the names of objects, classes and functions.  The ScriptV identifiers exclude extended characters such as and ü.  The Visviva Animation Engine supports a translation mechanism through which object and class names can be viewed externally in different national languages.  Using extended characters internally can bring about problems in creating language-independent animation titles and cause confusion in releasing, reusing, and exchanging works internationally.  For this reason, identifier names are restricted to standard alphabetical characters.

1.3.2   Keywords

A keyword is a continuous sequence of characters reserved for lexical elements with specific ScriptV meanings.  They may not be used otherwise.  Following is a list of ScriptV keywords, some of which have already appeared in this book:


assume

at

begin

break

case

class

const

continue

default

do

else

end

enter

exit

for

foreach

func

if

in

inspect

is

null

object

of

operator

owner

prefix

persistent

return

root

self

sub

super

switch

type

while

with

and

or

not

has


The following words, although not currently used as keywords in ScriptV, may become keywords in the compiled version of this language and so are reserved for future use.


abstract

assert

by

def

deferred

exact

fixed

final

imp

interface

meta

noperator

private

protected

public

retry

sealed

throw

try

when

use


1.3.3   Operator strings

An operator string is an arbitrarily long continuous sequence of operator characters.  An operator string is used as a name, or as a part of a function’s name that distinguishes one function from another.  A function can be named with an identifier or with operators. ScriptV supports user-defined operators. 

Under no circumstances may a user-defined operator string contain any of the following character combinations:


/*

//

*/

:<

=. 

:. 

<. 

>. 

+. 

-. 

*. 

/. 

%. 

|. 

&. 

~. 

!. 

^. 

?.

.= 

.: 

.< 

.> 

.+ 

.-

.* 

./ 

.% 

.|

.& 

.~ 

.! 

.^ 

.?

 


Also, the following three operator characters cannot be used to make operator strings:

":"             Reserved for declarations

"::"            Reserved for scope selectors

".."            A range token.

When an operator character is also a separator, it should not be used in combination with other separator characters.  For example:

;=

cannot be an operator string because ";" is a separator.

These are some function names that use operator strings:

++

<==>

Some operator names may contain more than one operator string, such as:

<*  *>

Why is this?  Because "<*" and "*>" are two operator strings which constitute two parts of a name of a function.  When this function’s name is referenced, the two parts should be written separately unless they happen to be separators.  

Therefore,

<**>

is a different name from

<*  *>

because "<**>" is a single operator string and “<*” and “*>” are two operator strings.  Consider:

[  ]

These characters are two parts of a name for an array index operator.  Since they are also separators, the string:

[]

is still the same operator and has two individual lexical elements.

Unless an operator character is a separator, an operator string will terminate only when the next character is not an operator character.  This requires programmers to use a white space or another kind of separator to separate two operator strings.  For example, the expression

        x--+--y

in C++ or Java contains three operator names: "--", "+", and "--". 

ScriptV considers "--+--" a single operator name.  This encourages programmers to write clear expressions when using ScriptV.  The above example in ScriptV would be written as

        x-- + --y

or

        (x--)+(--y)

 

1.3.4.  Literals

Literals are the fundamental representations of the value of an object.  There are four kinds of literals:

Integer

Character

Floating-point Number

String

In some of the following pages, the word "constant" is used in reference to literals.  A literal constant (Integer, Character, Floating-Point, or String) is a value that cannot be changed by any program expression.  "Constant" is opposite in meaning to "Variable."  A variable is an identifier that represents a value in a program expression.  The value a variable represents may be changed.

1.3.4.1.  Integer

Decimal integers and hexadigital integers comprise the two kinds of integer literals used in ScriptV.  These integer literals are all of the type Int.

A decimal integer is a sequence of the following digit numbers:

0  1  2  3  4  5  6  7  8  9

Examples of decimal integers are:

256

00234

4560000

A hexadigital integer starts with the characters "0x" or "0X" and contains a sequence of the following hexadigits:

0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F  a  b  c  d  e  f

Examples of hexadigit integers are:

0x45feb

0X0045ee00

0xFF00E0A0

1.3.4.2.  Character

A character constant, or literal, is one character enclosed in single quotes, as in 'c'.  A character constant may or may not be preceded by the character u, which is a Unicode prefix.  A character has the type Char.

The actual character that is represented by a character literal depends on the character set used in the application.  Character sets define a mapping method between the characters and the integer numbers that are used to represent the character.  Most western languages can use an 8-bit integer for the mapping because the number of characters in a western language is usually less than 255.  Some Asian languages may contain thousands of characters and must use a 16-bit integer for coding.

In some display contexts, a character may appear as two separated alphabetic symbols, as in 'ÎÄ'.  This is caused by displaying a character with an inappropriate font.  The literal 'ÎÄ' may represent a single Chinese character if the ChineseBig5 character set is used, or may be an invalid character if the ANSI character set is used.

Certain non-graphic characters, as well as the single quote ', the double quote ", the question mark ?, and the backslash \, may be represented in ScriptV code according to the following list:

Character

ASCII Representation

Escape Sequence

Null character

NUL

\0

New line

NL (LF)

\n

Horizontal tab

HT

\t

Vertical tab

VT

\v

Backspace

BS

\b

Carriage return

CR

\r

Form feed

FF

\f

Alert

BEL

\a

Backslash

\

\\

Question mark

?

\?

Single quote

'

\'

Double quote

"

\"

Hex number

Hh

\xhh

If the character following the backslash does not specify a legal escape sequence, the result is undefined.

The escape \xhh consists of a backslash followed by x followed by a sequence of hexadecimal digits, and is terminated by either another x or by a non-hexadecimal digit.

These are some character constant examples:

      'x'

      '"'

      'ÎÄ'

      '\''

      '\\'

      '\x6E'