|
| Home > Document > SQeeL Online Manual > |
| Comment signs | |
| // | All lines after double slash (//) are considered as comment. |
| # | Lines starting with a pound sign (#) are considered as comment. |
| /* */ | Lines enclosed in slash and asterisk (/* */) are considered as comment. Multiple lines can be enclosed at a time. |
| Example: indented program |
/* Call a function to calculate the power and print out */ print(beki(2, 3)) // Calculate the third power of 2 exit function beki(a, b) local ans = 1, i loop i = 1; i <= b; i++ ans = ans * a endloop return ans endfunction |
| Example: script extends over multiple lines |
traceout = stderr // Output an error of trace.
global f1, f2
f1 = open \
('test1.dat', new) // A script extents over two lines.
f2 = open('test2.dat', new)
print('4567')
output(f1)
print('0123')
close(f1)
close(f2)
|
| 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. |
| Example: Integer literal | |
| 543 0 -101 |
Decimal |
| 0xFF00 | Hexadecimal |
| 0733 | Octal |
| Example: Assignment statement |
| value = 100 |
| value = 100 | ![]() |
Name | Data area |
| value | 100 (Integer) |
| Example: Real number literal | |
| -1.666E5 -1.666E-5 |
Fifth power of 10 of -1.666 Minus fifth power of 10 of -1.666 |
| 0.5 .725 -3.14 |
Fixed-point part can be excluded. |
| Example: Assignment statement |
| value = -123.5 |
| value = -123.5 | ![]() |
Name | Data area |
| value | -123.5 (real number) |
| Example: String literal | |||
| "ABCDEFG" | ![]() |
ABCDEFG | |
| 'ABCDEFG' | ![]() |
ABCDEFG | |
| "ABC'DEFG" | ![]() |
ABC'DEFG | Single quotation marks shown as string |
| 'ABC"DE"FG' | ![]() |
ABC"DE"FG | Double quotation marks shown as string |
| Example: Escape sequence | |
| ¥n | Newline |
| ¥t | Tab |
| ¥r | Return |
| ¥f | Form feed |
| ¥" | Double quotation is shown as letter. |
| Example: String literals using the escape sequence | ||
| "¥x41¥x42" | ![]() |
AB |
| "¥101¥102" | ![]() |
AB |
| "ABC¥"DEFG" | ![]() |
ABC"DEFG |
| "ABC¥¥DEFG" | ![]() |
ABC¥DEFG |
| "ABC¥nDEF" | ![]() |
ABC DEF |
| Example: String literal with the expression | ||
| "1 + 1 = ${ 1 + 1 }" | ![]() |
1 + 1 = 2 |
| Example: Assignment statement | ||
| string = 'ABC' | ||
| string = 'ABC' | ![]() |
Name | Data area | |
| string | Reference to the character code | |||
![]() |
||||
| ABC |
| Array literal with all elements | |
| {1, 2, "abc"} | |
| {1, 2, "abc"} | ![]() |
0 | 1 (integer) | |
| 1 | 2 (integer) | |||
| 2 | gabch (string) |
| Array literal with number of elements and initial value | |
| {4 : "abc"} | |
| {4 : "abc"} | ![]() |
0 | gabch (string) | |
| 1 | gabch (string) | |||
| 2 | gabch (string) | |||
| 3 | gabch (string) |
| 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) | ||||
| 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) |
| 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) | |
| Invalid associative array literal |
| { 5 : 'my age' => 32 } |
| Access associative array literal |
| value['my age'] = 32 |
| 'my age' | 32 (integer) | ||||
| 'my weight' | 50 (integer) | ||||
| 'my status' | "okey" (string) | ||||
| 'my height' | 180 | ![]() |
'my height' | 180 (integer) |
| Array and associative array |
| value = { 1 : 0 } value['my age'] = 32 |
| 'my age' | 32 | ![]() |
'my age' | 32 (integer) | |
| (1) | 0 (integer) | ||||
| (2) | 0 (integer) |
| Variable scope | ||||||||||||||||
|
||||||||||||||||
| Calculate in descending order of priority |
| 1 + 2 * 3 |
| Operator with same priority |
| 1 + 2 + 3 |
| Expression with () |
| ( 1 + 2 ) * 3 |
| 1 + 2 | Binominal operation |
| i++ | Unary operation |
| Integer and real number and datatype | ||
| 1 + 2 | Return an integer | i=3j |
| 1.0 + 2.0 | Return a real number | i=3.0j |
| 1.0 + 2 | Return a real number | i=3.0j |
| 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 | |||
| Operator | Priority | Method | Description |
| & | 4 | expr1 & expr2 | eturns a string with expr2 connected after expr1. |
| = | 1 | var = expr1 | Assigns expr1 to var, and returns a value assigned to var. |
| Arithmetic non-operator | |||
| Operator | Priority | Method | Description |
| > | 2 | expr1 > expr2 | Returns true if expr1 is greater than expr2. Otherwise, returns false. |
| < | 2 | expr1 < expr2 | Returns true if expr1 is numerically less than expr2. Otherwise, returns false. |
| >= | 2 | expr1 >= expr2 | Returns true if expr1 is numerically greater than or equal to expr2. Otherwise, returns false. |
| <= | 2 | expr1 <= expr2 | Returns true if expr1 is numerically less than or equal to expr2. Otherwise, returns false. |
| == | 2 | expr1 == expr2 | Returns true if expr1 is numerically equal to expr2. Otherwise, returns false. |
| != | 2 | expr1 != expr2 | Returns true if expr1 is numerically not equal to expr2. Otherwise, returns false. |
| 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 | ||
| 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
|
| Logic operation | |||
| Operator | Priority | Method | Description |
| and | 3 | expr1 and expr2 | Return true if both expr1 and expr2 are true. Otherwise, returns false. If expr1 is false, returns false immediately without determining expr2. |
| or | 3 | expr1 or expr2 | Return true if either expr1 or expr2 is true. Returns false if both expr1 and expr2 are false. If expr1 is true, returns true without determining expr2. |
| not | 7 | not expr | Return false if expr is true. Returns true if expr is false. |