51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 3975|回复: 14
打印 上一主题 下一主题

求tsl参考文档中文版

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2004-10-12 21:42:08 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
如有这种文档的中文版请发给我!yedi007@163.com
谢谢,一共好象有5个!


This Help module describes the basic elements of the TSL programming language. Click one of the following buttons for more information on a topic in this Help module:

Variables and constants
Operators and expressions
Statements
Control-flow
Arrays
Input/output
Comments
Built-in functions
User-defined functions
External function declarations

Variables and Constants

Variables and constants may be either strings or numbers. Declaration is optional; if variables are not declared, their type is determined at run time according to their context.
Variable names can include English-language letters (a-z and A-Z), digits, and underscores (_). The first character must be a letter or an underscore. TSL is case sensitive; y
and Y are therefore two different characters. Note that names of built-in functions and keywords (such as if, while, switch) cannot be used as variable names.

Click one of the following buttons for more information on a topic in this Help module:

Type (of variable or constant)
Undeclared variables
Variable declarations
Constant declarations

Type ( of variable or constant)

TSL supports two types of constants and variables: numbers and strings. Numbers may be either integer or floating point, and exponential notation is also acceptable. For example, -17, .05, -3e2, and 3E-2 are all legal values.
Strings consist of a sequence of zero or more characters enclosed within double quotes. When a backslash (\) or double-quote (") character appears within a string, it must be preceded by a backslash. Special characters can be incorporated in a string using the appropriate representation:

Backspace        \b        Vertical tab        \v
Carriage return        \r        Newline        \n
Formfeed        \f        Octal number        \ooo
Horizontal tab        \t               
In the case of octal numbers, the zeroes represent the ASCII code of a character. For example, "\126" is equivalent to the letter "v."
For example, to represent the string "The values are:   12   14   16", type

"\"The values are:\t12\t14\t16\""

At a given moment, the value of a constant or variable can be either a string or a number. The TSL interpreter determines the type according to the operation performed. For example:
x = 123;
s = x & "Hello";
y = x + 1;
Variable x is assigned the value 123. In the second statement, because the operation is concatenation (&), x is treated as a string. The interpreted value of s is therefore 123Hello. In the third line, because the operation is addition, x is treated as a number. Variable y
is therefore assigned the value?24.

In the case of an expression where a mathematical operation is performed on a string, such as
"6RED87" + 0
the numeric value of the string is the first part of the string that can be evaluated to a number. Here, the numeric value of the expression is 6.
Since relational operators are valid for both strings and numbers, a numeric comparison is always performed if both operands can be evaluated to a number. For instance, in the relational expression below
"0.01" == "1e-2"

although both constants are written like strings (enclosed within quotation marks), both expressions are also valid numbers so a numeric comparison is performed. But in the next expression
"0.01" == "1f-2"
the second expression is not a number, so a string comparison is performed.

Undeclared Variables

If a variable is not declared, it is created implicitly when it is assigned or used in an expression. If a variable is not initialized, it is given the string value "" (null) at run time.
All undeclared variables are global, unless they are on the formal Parameter List of a called test. (For more information on parameters, refer to the chapter "Calling Tests" in your User's Guide.)

Variable Declarations

Note that while constant and variable declarations are optional in tests, they are required in user-defined functions. Variable declarations have the following syntax:
class variable [ = init_expression ];
The init_expression assigned to a declared variable can be any valid expression. If an init_expression is not set, the variable is assigned an empty string. The variable class can be any one of the following:
auto: An auto variable can only be declared within a function and is local to that function. It exists only as long as the function is running. A new copy of the variable is created each time the function is called.

static: A static variable is local to the function, test, or compiled module in which it is declared. The variable retains its value until the test is terminated by a Stop command.
public: A public variable can only be declared within a test or module, and is available for all functions, tests, and compiled modules.
extern: An extern declaration indicates a reference to a public variable declared outside of the current test or module.

With the exception of the auto variable, all variables continue to exist until the Stop command is executed. For example, the statement
static a=175, b=get_time( ), c = 2.235;
defines three variables (a, b, and c), and assigns each an initial value. This value is retained between invocations of the test. The following script segment demonstrates how a static variable can be used so that a message is printed only the first time that the test, T_2, is called.
static first = 1;

pause ("first = " & first);
if (first == 1) {
        first = 0;
        report_msg ("Test T_2 was called.");
}

The following table summarizes the scope, lifetime, and location of the variable declarations for each class:

Declaration        Scope        Lifetime        Declare the variable in...
Auto        Local        End of function        function
Static        Local        Until stop        function, test, or module
Public        Global        Until stop        test or module
Extern        Global        Until stop        function, test, or module variables: declarations

Constant Declarations

The const specifier indicates that the declared value cannot be modified. The syntax of this declaration is:
[ class ] const name [ = expression ];
The class of a constant may be either public or static. (If no class is explicitly declared, the constant is assigned the default class public.) Once a constant is defined, it remains in existence until WinRunner is closed.
For example, defining the constant TMP_DIR using the declaration:
const TMP_DIR = "/tmp";

means that the assigned value /tmp cannot be modified. (This value can be changed only by explicitly making a new constant declaration for TMP_DIR.)

Operators and Expressions

TSL supports six types of operators: arithmetical, concatenation, relational, logical, conditional, and assignment. Operators are used to create expressions by combining basic elements. In TSL, expressions can consist of constants, variables, function calls, and other expressions.
Click one of the following buttons for more information on a topic in this Help module:

Arithmetical operators
Concatenation operator
Relational operators
Logical operators
Conditional operator
Assignment operators
Precedence and associativity of operators

Arithmetical Operators

TSL supports the following arithmetical operators:

+        Addition
-        Subtraction (unary)
-        Subtraction (binary)
*        Multiplication
/        Division
%        Modulus
^ or **        Exponent
++        Increment (adds 1 to its operand - unary operator)
--        Decrement (subtracts 1 from its operand - unary operator)
The result of the modulus operation is assigned the sign of the dividend. For example,
7 % -4 = 3
-4.5 % 4 = -0.5
The increment and decrement operators may be placed before the variable (++n), or after (n
++). As a result, the variable is incremented either before or after the value is used. For example:
i = 5;
j = i++;
k = ++i;
print(i & j & k);
prints the values 7, 5, 7. Note that the increment and decrement operators may be applied only to variables, and not to expressions, such as (a + b).

Note: You can increment or decrement an operand by a number other than 1. For example, to increment an operand by 5, use the following statement:

i = i + 5;

Concatenation Operator

The ampersand (&) character is used to concatenate strings. For example, the statement

[ Last edited by yedi007 on 2004-10-12 at 21:45 ]
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏

该用户从未签到

2#
 楼主| 发表于 2004-10-12 21:42:36 | 只看该作者
x = "ab" & "cd";
assigns the string value abcd to variable x.

Relational Operators

The relational operators used in TSL are:

>        greater than
>=        greater than or equal to
<        less than
<=        less than or equal to
==        equal to
!=        not equal to

Relational expressions are evaluated to the value 1 if true, and 0 if false. When the value of an expression is null or zero, it is considered false. All other values are considered true.
Strings are compared character by character according to their ASCII value. Letter strings are evaluated in terms of alphabetical order; the string which comes first alphabetically is considered smaller. For instance, "galactic" < "galaxy".

Logical Operators

Logical operators are used to create logical expressions by combining two or more basic expressions. TSL supports the following logical operators:

&&        and
||        or
!        not (unary)

Logical expressions are assigned the value 1 if true, and 0 if false. When the value of an expression is null or zero, it is considered false. All other values are considered true. Logical expressions are evaluated from left to right, and as soon as the value of an expression is determined, interpretation stops. For example, in the expression
(g= 0) && (d/g > 17)
if the first expression is false, then the second expression is not evaluated.

Conditional Operator

The conditional operator is the ? (question mark) character. Conditional expressions have the format:
expression1 ? expression2 : expression3
expression1 is evaluated first; if it is true, expression2 is evaluated and becomes the value of the expression. If expression1 is false (zero or null), then expression3 is executed and becomes the value of the expression. In the following statement
(g= 0) ? 17 : 18;
if the first expression is true (g is not equal to zero), then the value of the conditional expression is 17. If the first expression is false, then the value of the conditional expression is 18.

For more information, see the "Control-Flow" section in this Help module.

Assignment Operators

Assignment operators are used to assign values to variables and arrays. All of the binary arithmetical operators have corresponding assignment operators:

Operator        Example        Meaning
=        a = b        assign the value of b to a
+ =        a += b        assign the value of a plus b to a
- =        a -= b        assign the value of a minus b to a
* =        a *= b        assign the value of a times b to a
/ =        a /= b        assign the value of a divided by b to a
% =         a %= b        assign the value of a modulo b to a
^= or **=        a ^ = b        assign the value of a to the power of b to a
For example, in the following segment of a test script,
for (i=0; i<200; i+=20)

move_locator_abs(i,i);

the value of i is incremented by 20 after each repetition of the loop. The mouse pointer is then moved to the new position defined by i. For more information about for loops see the "Control-Flow" section in this chapter.

Precedence and Associativity of Operators

The rules of precedence and associativity determine the order in which operations are performed when more than one operator appears in an expression. Operators with higher precedence are interpreted before operators with lower precedence. For example, multiplication is performed before addition.
When more than one operator of the same level of precedence appears in an expression, the associativity indicates the order in which they are interpreted. For example, in
x / 2 + i - q

division is performed first. Addition is performed before subtraction because the associativity of these operators, which have the same level of precedence, is left to right.
The following table lists the precedence, in descending order, and the associativity of operators:

Operator (in order of precedence)        Associativity
( ) (parentheses)        None
++   --        None
^   **        right to left
!   -   +   (unary)        None
*   /   %        left to right
+   -   (binary)        left to right
&        left to right
<    <=    >    >=    ==   =        None
in (array operator)        None
&&        left to right
?        left to right
||        right to left
=    +=    -=    *=    /=    %=    ^=    **=        right to left

Statements

Any expression followed by a semicolon is a statement. A statement can continue beyond one line.
In a control-flow structure, a single statement can be replaced by a group of statements, or block. Statements are grouped by enclosing them within curly brackets { }. Each individual statement within brackets is followed by a semicolon, but the brackets themselves are not. This is illustrated below:
for (i = 0; i < 10; i++) {

st = "Iteration number " & i;
        type (st);
}
回复 支持 反对

使用道具 举报

该用户从未签到

3#
发表于 2004-10-13 11:13:53 | 只看该作者
关注中
回复 支持 反对

使用道具 举报

该用户从未签到

4#
发表于 2004-10-13 12:58:04 | 只看该作者
我也要,
回复 支持 反对

使用道具 举报

该用户从未签到

5#
发表于 2004-10-13 12:58:34 | 只看该作者
baytibaby@msn.com,请给我一份
回复 支持 反对

使用道具 举报

该用户从未签到

6#
发表于 2004-10-13 13:07:47 | 只看该作者
烦劳给我一份,谢谢!
tiansl@novel-tongfang.com
回复 支持 反对

使用道具 举报

该用户从未签到

7#
发表于 2004-10-13 15:29:05 | 只看该作者
哪有中文的啊,要不去翻译板块就高手翻译一下
回复 支持 反对

使用道具 举报

该用户从未签到

8#
发表于 2004-10-14 11:34:43 | 只看该作者
这个两篇文章写的都是关于TSL是一个类C语言,描述其语法规则与C的相同和不同之处,可惜我没有中文版```````
提醒大家用的时候要把TSL和C类比!!```````
回复 支持 反对

使用道具 举报

该用户从未签到

9#
发表于 2004-10-18 13:31:58 | 只看该作者
烦劳给我一份
bluexhb@163.com
i'm newcomer
回复 支持 反对

使用道具 举报

该用户从未签到

10#
发表于 2004-10-19 11:30:19 | 只看该作者
回复 支持 反对

使用道具 举报

该用户从未签到

11#
发表于 2004-12-11 15:08:12 | 只看该作者

lilylilymail@163.net

谢谢!
回复 支持 反对

使用道具 举报

该用户从未签到

12#
发表于 2004-12-22 11:55:20 | 只看该作者
回复 支持 反对

使用道具 举报

该用户从未签到

13#
发表于 2004-12-22 12:04:02 | 只看该作者
到外文翻译版去求助一下看看。
回复 支持 反对

使用道具 举报

该用户从未签到

14#
发表于 2004-12-28 09:52:25 | 只看该作者
也给我一份jsj_lzz@126.com
回复 支持 反对

使用道具 举报

该用户从未签到

15#
发表于 2007-10-14 02:03:53 | 只看该作者
我也要!我的邮箱是:ljq@sina.com  谢谢·!
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-15 03:30 , Processed in 0.084453 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表