Home | About SQeeL | Document | DownLoad | Mail Japanese
Home > Document > SQeeL Online Manual >

3. Syntax

Format
Statements and Declarations
Comment
Indent
Other
Name
Name consists of a single letter or more used for function name, variable name, and label name.
Letters, numbers, and underscore (_) are available as name.
Name must always start with a letter.
You cannot use the user-defined function name, variable name, and label name same as system function name, system variable name, and reserved word.
Name is not case-sensitive.

Example: Names
a1
a_12
const_user

Example: Invalid names
1a Name starts with a number.
_a12 Name starts with an underscore.
const Reserved word is used.

Top
Datatype
SQeeL has four built-in datatypes as follows.
  • Integer
  • Real Number
  • String
  • Array
Integer
Real Number
String
Array
Multiple data can be managed as a single data.
A group of data is called an array, and each data is called an element of the array.
Each element is numbered in an ascending order starting with 0.
The element contains any one of integer, real number, or string.
There are two methods of writing the array literal, all elements or number of elements and initial value.

All elements
Elements are separated by comma in a section enclosed between { and }.
Following example indicates that integer 1 is numbered as 0, integer 2 is numbered as 2, and string abc is numbered as 3.

Array literal with all elements
{1, 2, "abc"}

  {1, 2, "abc"} 0 1 (integer)
      1 2 (integer)
      2 gabch (string)

Number of elements and initial value
Number of elements and the initial value are separated by comma in a section enclosed between { and }.
Following example indicates that element numbers 0 to 4 represent the string abc.

Array literal with number of elements and initial value
{4 : "abc"}

  {4 : "abc"} 0 gabch (string)
      1 gabch (string)
      2 gabch (string)
      3 gabch (string)

To assign integer datatype to a variable, use an assignment statement.
When the array datatype is assigned, the array is copied, and then reference to this copy is entered as a variable.
Enclose the element of the assigned array between [ and ] to specify the element number.

Assign the array as a variable
Value = {5 : 1024} Create an array with five elements, and assign an integer 1024 to every element.

Specify the element of the array
value[2] Specify a value with an element number 2 from the array value.

  value = {5:1024} 0 1024 (integer)
        1 1024 (integer)
        2 1024 (integer)
        3 1024 (integer)
        4 1024 (integer)
          Copy
  Name Data area Array
  value Reference to the string 0 1024 (integer)
        1 1024 (integer)
        2 1024 (integer)
        3 1024 (integer)
        4 1024 (integer)

You can assign all datatypes to the element of the array.
You can also use the multidimensional array.
If the array is assigned to the element with the array and you want to clarify the element of the assigned array, enclose the element of the assigned array between [ and ].

Two-dimensional array
value = { 3 : { 2 : 1024 } } Create an array with two elements in an array with three elements, and assign an integer 1024 to every element.

Specify the element of the two-dimensional array
value[2][1] Specify a value with the element number 1 from the array with the element number 2 of multi-dimensional array value.

  value = { 3 : { 2 : 1024 } } 0 0 1024 (integer)
      1 1024 (integer)
      1 0 1024 (integer)
      1 1024 (integer)
      2 0 1024 (integer)
      1 1024 (integer)

Top
Associative array
Associative array is not a common array.
Associative array enables you to name each element of the array.
Likewise the array literal, elements in the associative array are separated by comma and enclosed between { and }. The associative array enables you to connect the string that is a key of the associative array to its value by using a mark =>.

Associative array literal
{'my age' => 32, 'my weight' => 50, 'my status' => 'okey'}

  {'my age' => 32, 'my weight' => 50, 'my status' => 'okey'}
 
  'my age' 32 (integer)
  'my weight' 50 (integer)
  'my status' "okey" (string)

Following format is not allowed.

Invalid associative array literal
{ 5 : 'my age' => 32 }

You can use the string to access the element of the associative array.
You can also access the element by using the number because the element is numbered in order of the appearance of the key string.
For example, the element of my age above is 0th.

If you assign the associative array datatype to a variable, refer to other arrays for further instruction. When you access the element, use the key string.

Access associative array literal
value['my age'] = 32

You can increase the element dynamically.
Specify new key string and then assign it to add an element.

        'my age' 32 (integer)
        'my weight' 50 (integer)
        'my status' "okey" (string)
  'my height' 180 'my height' 180 (integer)

Other types of array can automatically be changed to the associative array by simply adding the key string.
If there is an element of which the key is not specified to an array and you specify the new string, keys are allocated to the element without any key first.

Array and associative array
value = { 1 : 0 }
value['my age'] = 32

  'my age' 32 'my age' 32 (integer)
        (1) 0 (integer)
        (2) 0 (integer)

Top
Variable scope
Normally, variables are declared in a declaration before actually being used. Variable scope varies according to the type of declaration.
Variables do not have to be declared. If non-declared variables are used in a function, these variables are considered as local variable. If non-declared variables are used in any section other than the function, these variables are considered as global variable.
If there are variables not declared in a source file, alert messages are logged when a file is converted to a binary file.
If a variable is referred to before a value is not assigned to the non-declared variable, an error occurs and a program stops being executed.

Variable scope
Exglobal scope
File A
global, const variable scope
Function A-1
Local variable scope

Function A-2
Local variable scope
File B
global, const variable scope
Function B-1
Local variable scope

Function B-2
Local variable scope


Top

Fixed number
global variable
exglobal variable
Expression
Expression consists of non-operator literal, variable, function call, and operator.
The expression always returns the result.
Operators are prioritized and calculated in descending order of priority.

Calculate in descending order of priority
1 + 2 * 3

In this case, 2 is multiplied by 3 first, and then its result is added to 1.

Operator with same priority
1 + 2 + 3

In this case, 1 is added to 2 first, and then its result is added to 3.
Use ( ) to change the order of priority. If the expression contains a section enclosed in ( ), numbers enclosed in ( ) are calculated first.

Expression with ()
( 1 + 2 ) * 3

In this case, 1 is added to 2 first, and then its result is multiplied by 3.
Arithmetic operation
There are two types of arithmetic operations, binominal operation and unary operation.
Binominal operation contains two non-operation values. Unary operation, on the other hand, contains a single non-operation value.

1 + 2 Binominal operation
i++ Unary operation

Arithmetic operation may return different results when calculating as integer or calculating as real number.
Thus, it is necessary to determine integer or real number by non-operation datatype.
If non-operation value does not contain real number, it is calculated as integer.
If non-operation value contains real number, it is calculated as real number.
If it is calculated as integer, all non-operation values are converted to integer.
If it is calculated as real number, all non-operation values are converted to real number.
Arithmetic operation returns a value.
When calculated as real number, real number is returned. When calculated as integer, integer is returned.

Integer and real number and datatype
1 + 2 Return an integer i=3j
1.0 + 2.0 Return a real number i=3.0j
1.0 + 2 Return a real number i=3.0j

Following are the list of operations.
Operator with a larger priority value is calculated first.
Expr1 and expr2 represent non-operator values, and var indicates it is available only when an non-operator value is variable.

Arithmetic operator
operator priority method description
+ 5 expr1 + expr2 Return a sum of expr1 and expr2
- 5 expr1 - expr2 Return a value of expr2 subtracted from expr1
* 6 expr1 * expr2 Return a product of expr2 and expr1
/ 6 expr1 / expr2 Return a quotient of exprt1 divided by expr2
% 6 expr1 % expr2 Return a reminder of exprt1 divided by expr2
= 1 var = expr1 Assign expr1 to var, and return a value assigned to var.
+= 1 var += expr1 Assign the sum of var and expr1 to var, and return a value assigned to var.
-= 1 var -= expr1 Assign a difference of expr1 subtracted from var, and return a value assigned to var.
*= 1 var *= expr1 Assign a power of var and expr1 to var, and return a value assigned to var.
/= 1 var /= expr1 Assign a quotient of var divided by expr2 to var, and return a value assigned to var.
++ 8 ++var Assign a value of 1 added to var to var, and return var.
++ 8 var++ Assign a value of 1 added to var to var, and return the source value of var.
-- 8 --var Assign a value of 1 subtracted from var, and return var.
-- 8 var-- Assign a value of 1 subtracted from var, and return the source value of var.
- 7 - expr1 Returns a power of expr1 and -1.

String Operator
Arithmetic non-operator
String comparison operation
String comparison operation returns logical value (true and false.)
Non-operators of the string comparison operator are converted to string.

String comparison operator
Operator Priority Method Description
EQ 2 expr1 EQ expr2 Returns true if expr1 is equal to expr2. Otherwise, returns false.
NE 2 expr1 NE expr2 Returns true if expr1 is not equal to expr2. Otherwise, returns false.
GT 2 expr1 GT expr2 Compares expr1 with expr2 in character code. Returns true if expr1 is greater than expr2. Otherwise, returns false.
GE 2 expr1 GE expr2 Compares expr1 with expr2 in character code. Returns true if expr1 is equal to or greater than expr2. Otherwise, returns false.
LT 2 expr1 LT expr2 Compares expr1 with expr2 in character code. Returns true if expr1 is smaller than expr2. Otherwise, returns false.
LE 2 expr1 LE expr2 Compares expr1 with expr2 in character code. Returns true if expr1 is equal to or smaller than expr2. Otherwise, returns false.
LIKE 2 expr1 LIKE expr2 Compares a pattern of expr1 with expr2. Returns true if the patterns match. Otherwise, returns false.
Percentage mark (%) and underscore (_) are available as a wildcard.
% indicates 0 or more of any letters match. _ indicates 1 or more of any letters match.
If you want to use % and _ as a letter, add a pound sign (#) before % and _.
MATCH 2 expr1 MATCH expr2 Compares string of expr1 with regular expression of expr2. Returns matched string as true.
Otherwise, returns false.

Regular expressions available for MATCH
+ Match 1 or more times
* Match 0 or more times
? Match 1 or 0 times
. Match any character
\ Escape letter
^ Match the beginning of the line
$ Match the end of the line
rx1 | rx2 Connect two regular expressions rx1 and rx2 with OR condition.
{m[,n]} Specify the number of times the regular expression is repeated.
If m is specified, matches m times. If m and n are specified, matches m times but not more than n times.
(rx1) Subpattern the regular expression rx1.
[class_list] Match the string class.
List the element composing string class in class_list.
When ^ is placed before class_list, match any other elements than the ones listed in class_list.
Elements consist of letters or following descriptions.
s-e Specify the range of strings.
Specify [0-9] to match any string between 0 and 9.
[.str.] Consider str specifying an element of multiple strings as a single element of string class.
Specify [[.ce.]]* to match 0 times or more of ce.
[:cname:] Match string class shown in cname.
Following can be specified in cname.
Specify [[:alpha:]] to match 0 times or more of alpha.
alpha Alphabet
graph Any alphanumeric or punctuation character
space Space
blank Space and tab
lower Lower-case character
upper Upper-case character
cntrl Any control character
print Any alphanumeric or punctuation character or space
digit Any decimal digit
xdigit Any hexadecimal digit

Example of regular expression program
if matched = "The quick brown fox jumped over the lazy dog" match \
		"([[:alpha:]]*o[[:alpha:]]*)([[:alpha:]]*)([[:alpha:]]*o[[:alpha:]]*)"
	loop i = 0; i < count(matched); i++
		print(matched[i])
	endloop
endif

Result:
fox jumped over

The example above uses match operator to match a pattern of string, refers to a variable matched in loop statement, and prints out a value.

Logic Operation

© Insight Technology, Inc. 1996-2004 All Rights Reserved.