The WMLScript basis of the Wireless Markup Language (WML) Foundation

Source: Internet
Author: User
Tags end expression functions connect number strings numeric value variables string

WML script is part of the Unlimited Application protocol WAP application layer, which can be used to add client-side processing logic to WML cards and cards, and the latest version is the 1.1 version. The WML Script1.1 is specified as modified and optimized on the basis of the ECMAScript scripting language developed by the European Computer manufacturer agreement. It is better able to support high-bandwidth communications devices such as mobile phones, and using WML script in WML programming can effectively enhance the flexibility of client applications, and we can also use WML script as a tool to develop powerful WAP Web applications and unlimited Web pages. In this chapter, we will explain in detail the basis of WML Script1.1 programming, such as basic rules, variable data types, operation-given expressions, and so on.   In order to describe the simplicity, later we will "WML Script1.1" referred to as "WMLScript." Call WML script function in 4.1 WML program

After the first two chapters of the study, familiar with C language readers may realize that WML function, logic operation functions are very limited. While WMLScript provides a wealth of function functions, we can use WMLScript to enhance WML programming in WAP application development. As a result, WMLScript has become a major development tool for expanding WML programming capabilities.

The main advantages of 4.2 wmlscript and its bytecode interpreter

WMLScript has a well-defined set of bytecode and an interpreter reference structure. The WMLScript data in the wireless network transmission is transmitted in binary format, so the user can use the bandwidth communication channel, which can keep the client phone only need the minimum memory. ECMAScript modified WMLScript can be faster, smaller, and easier to compile programs in bytecode form. All of these features are wmlscript with many of the advantages and features that WML cannot have.

4.2.1 The main advantages of using WMLScript

WMLScript is designed to provide the WMLScript system with a general script processing capabilities, using wmlscript we can further complement the XML-based WML language programming capabilities, the development of bandwidth-oriented network applications and content, such as text, images, select lists, etc. We can use a simple format to write a more flexible and readable user interface. WMLScript has the advantages and functions of WML, including the following:

(1) Check the legality of user input:

(2) Expand the function of the user's browser, such as allowing programmers to develop phone calls, send short messages, store phone numbers, manage phone books or SIM cards;

(3) Generate a user-side confirmation, prompt, warning message or Action dialog box, and make it quickly displayed in the browser;

(4) The browser-side software and parameters can be extended and configured after the user's browser changes;

(5) The maximum extent to overcome the client's bandwidth communication connection restrictions, and provide a wealth of program functions;

(6) Complement WML and enable it to implement a variety of services for micro-mobile terminal devices, such as supporting the advanced user interface, increasing client intelligence, providing access to the user's browser peripherals, and browsing the data on the server and client to reduce bandwidth consumption.

4.2.2 WMLScript byte-code interpreter

Before the WMLScript bytecode interpreter is interpreted, the text-formatted program written in the WMLScript language will be first compiled into binary-formatted code. At compile time, the compiler usually first divides the WMLScript program into several editing units, each unit of the program contains a number of statement lines and WMLScript functions, then, the WMLScript compiler will follow these compilation units, one by one, the WMLScript program as input, and the corresponding byte code as output content. When the user calls the WMLScript program through the WAP phone, the compiler's encoding function is activated and executed.

4.3 wmlscript Basic Rules

WMLScript has followed the WML approach in many of the basic rules. However, because WMLScript is specified in the C language, its grammatical features are very similar to the C language. If you are familiar with C language, then learning and mastering this part of the content should be relatively easy.

4.3.1 wmlscript and URL

Like WML, WMLScript also uses the WWW and HTML access resources URL, HTTP and other specifications, and expanded the scope of the use of URLs. In WMLScript, not only the hyperlink, file path, or file name can be used as URL processing, external functions, access control information can also be treated as a URL.

For this reason, WMLScript uses a WML workaround, that is, to improve the value of the HTML named resource, and to use the form of the program segment anchor (Fragment anchor) to handle the resource location. The program segment anchor is defined according to the document URL rule and is written in the form of a well font size (#) before the program segment identifier. With the program segment anchor, the WMLSCRIPT program can specify any function within the WMLScript compilation unit, and can pass the required arguments while calling the function.

4.3.2 Lexical structure

WMLScript programming in the lexical structure is not complex, we are the following from the case sensitive, space, line, note that is reserved words to explain the relevant specific rules.

(1) Content type. WMLScript content types are mainly for file form and binary form, type structure can be specified on the server side, in the form of:

Text form: Text/vnd.wap.wmlscript;

Binary form: APPLICATION/VND.WAP.WMLSCRIPTC.

Specific methods we have introduced in the 4th chapter, no longer repeat here.

(2) Case sensitive. WMLScript1.1 is a case sensitive scripting language. The various keywords, variables, and function names designed by it must be used in a reasonable case.

(3) Spaces and line wrapping. In general, the WMLScript program value form ignores all spaces, tables conform to line breaks, and so on. However, if these special characters are expressed in code or processed as strings, WMLScript will no longer ignore them. , for example, the string "Oct 28,2001" contains spaces that are not ignored when executed, and are different from "oct28,2001", which contains no spaces.

(4) Notes. As with WML programming, annotation content can also be added to the WMLScript script program. The annotation content is not executed by the program, and annotations cannot be nested. There are two kinds of annotation methods for WMLScript:

First, line comments. Even if you are booting with a double oblique line number (//) with one line of content, this line of content is all commented. Such as:

This is a line comment, with the double slash number beginning to the end of the comment.

Secondly, block selection. This starts with the symbol "/*" and all content is commented during the end of the symbol "/*". Such as:

/* This is a block annotation, added in the middle of the content is the annotation content * *

(5) Data type and direct encoding. WMLScript allows 4 types of data to be encoded directly and nested and nested within a program. The data types that are directly encoded in 4 are: integers, floating-point numbers, strings, and Boolean values. In addition, the "invalid" value can also be directly encoded "1." Integer. This type of integer can be encoded directly when an integer is used in decimal, hexadecimal, or octal mode.

When coding, the decimal digits do not start with 0, and contain only 0~9 numeric strings; The hexadecimal data begins with the ox or ox and contains only strings of 0~9, a~f, or a~f; the octal number starts with 0 and contains only the number strings of the 0~7.

2. Floating point numbers. Floats are usually defined as numbers that contain decimal points, and can contain decimal and exponential portions. Floating point numbers have more forms, you can make decimal integers or floating-point numbers, can be fractions, can also be exponential; but a floating-point number must have at least one count.

The exponent starts with E or E, followed by an integer. The exponent is a power of 10. For example: E0 10 of the 0 power, such as: E0 when the other power 10, e-2 10 of the negative 2 power set equals 0.01. Indices can be signed, just (+) or minus signs (-), which represent positive and negative indices, respectively.

3. String. A string is the content that is defined between pairs of double quotes ("") or single quotes (' ").

Because WMLScript only allows strings to be defined using pairs of double quotes or quotes, a compilation error occurs when a single or double quotation mark is used in a program.

Given that some special characters cannot appear directly in the string, WMLScript provides a translation sequence to represent these special characters.

4. Boolean type. It is only ture and false two values that represent "truth" or "false value" in WMLScript. Boolean data can participate in different, or equal operations, the specific rules we later introduce.

5. Invalid type. Also known as an "empty type", it is a wmlscript-supported amount representing an invalid value, expressed in invalid. The two are similar to NULL in the C language.

4. Reserved words. WMLScript defines a set of reserved words that contain words that represent special meanings that cannot be defined separately or most other identifiers. The reserved words in WMLScript are as follows:

Acces HTTP agent If break IsValid continue meta header

div name div= path domain return else typeof while

Equiv URL extern use for user function var

In addition, WMLScript also reserved some reserved words for future versions, mainly:

Case finally catch import class private Const public debugger

sizeof default struct do Super enum switch export throw

Extends try

WMLScript also has some reserved words that are not used:

Delete Null in-lib void new with

7. Identifier. The wmlscript identifier can specify or name 3 elements: variables, functions, and callouts. An identifier cannot begin with a number but can begin with an underscore (-), and the identifier cannot be a wmlscript reserved word. For example, TimeOfDay, speed, quality, home_address, _myname, __, Varo, and so on are legitimate identifiers, while strings that start with a special symbol of a number or a short underline, and reserved words are all illegal flags, such as while, For, if, My~name, $sys, 123, 3piecs, take.this, etc.

Because WMLScript are strictly case-sensitive, identifiers that are identical but different in capitalization are not the same identity, for example, work and work are different identifiers.

8. Name space. WMLScript provides a more liberal namespace, and the same identifier can be used for different purposes at the same time. For example, as an identifier for a function name, it can also be used as variable names, function arguments, program annotations, and so on, and their properties or values do not interact with each other. In the following simple routine, the mytest identifier is used as the function name and as the variable name, function parameter name, function parameter name, and constant name. Obviously, this particular wmlscript provides a great convenience for us to write programs.

Basic writing rules of 4.3.3 WMLScript program

Basic book writing rules for WMLScript programs:

1. The program consists of a number of statements or functions, and functions are composed of several statements;

2. Each complete statement must be preceded by a semicolon (;), there must be space between the operands of the statement key words, and a semicolon (;) is an integral part of the WMLSCRIPT program;

3. The function body must be enclosed with pairs of curly braces ({}). Also, at the end of the function, add a semicolon (;) after the right curly brace (}), and the function Description section, such as function name, function type, function argument, and so on, should precede the curly braces ({});

4. Some statements may also require a practical curly brace ({})-containing content, which can usually be placed in a function, so curly braces ({}) can be nested.

Of course, different statements, parameters, variables and other elements in the declaration and writing may have some finer requirements, specifically, we later introduce these elements are specifically given,

4.4 Variables and data types

A variable, or data type, is the concept and component of all programming languages, and WMLScript is no exception. It gives detailed rules for its variable usage and data type definition methods. A variable usually corresponds to a data, we can assign a value to a variable, and we can change the value of the variable in the execution of the program. Here's a detailed explanation of wmlscript about variables and data types.

4.4.1 variables and their declarations

A variable is a symbolic name, or identifier, that has a value in the WMLScript script program. You can use variables to store and change the data you need in your program. Unlike the C language, WMLScript only supports variables defined within functions or parameter variables used to transfer numbers.

Variables must be declared before they are used, that is, to define a variable, that is, to specify the name of the variable. The keyword that declares the variable is VAR, which is the legal identifier of the variable name on the back root, and the last semicolon (;), which completes the declaration of a quantity. Declaring variables is that you can use VAR to declare multiple variable names at once, and to use the sign (,) interval between adjacent variables.

In general, when naming variables, we want to be able to use meaningful variable names. For example, when you need to use a variable to represent the price of a book, there is nothing wrong with naming the variable J or books, but if you can name it as Bookprice, it will be. WMLScript script is more readable and can be convenient for programmers to write and debug scripts. Moreover, since WMLScript is not allowed to use reserved words in naming variables, it is a good solution to avoid the conflict between variable names and reserved words because of a momentary lapse of time, and we recommend using multiple word combinations as a variable name. For example, if you want to define a variable to store the price of a book, then we may as well use Bookprice or Book_price as the name of the variable, so that on the one hand, the variable appears clearer, on the other hand, you can avoid the conflict between the variable and the reserved word.

These are just our suggestions for variable naming, not mandatory requirements, users can not do according to our requirements to do, as long as the compliance WMLScript to the name of the requirements of identifiers, but the formation of a good programming style for both programmers and scripting people, are very meaningful.

The scope and life period of 4.4.2 variables

The scope of a variable refers to a piece of code that can refer to the variable in the program. Because WMLScript only supports variables defined within functions, the function of WMLScript variables is usually the one that defines them. Outside the function, the variable no longer plays a direct role.

The life-starting value of a variable begins with a variable declaration until it is invalidated. The lifetime of a variable is also referred to as the duration and duration of the variable. A variable is valid within the entire function that defines it, and any block of statements within the function does not reduce the lifetime of the variable or the scope of the restricted variable.

If a variable is used directly without life, or declared later, it destroys the lifetime of the variable. The first situation causes the variable to not start the declaration period, that is, there is no "life", and the latter causes the variable declaration period to be redefined before the end of the declaration period, that is, it is "born" multiple times. This can result in invalid variables being used. This problem is illustrated by the use of variables in the following functions:

function foo () {

x=1;//Error: The variable was not declared before it was used, and the amount of change has not been declared.

var x,y,z;

y=x+3;

var zd =invalid

if (x) {

var (y);//ERROR: This variable has been declared, here is the duplicate declaration.

};

};

Use of 4.4.3 variables

A WMLScript variable can only be used within a function that defines it. You need to declare a variable when you use it, declaring that it is possible to assign a value to a variable at the same time, or even to compute a variable. For example, the following simple function illustrates this flexible use of a variable:

function Ourage () {

var myage=38;

var yourage=26;

var ourage=myage+yourage;

return ourage;

};

Variables can be used in the form of calling variable names. In the example above, "Var ourage=myage+yourage;" By calling the variable name, the variable ourage the sum of the variable myage and the variable yourage.

4.4.4 variable type and data type

WMLScript is a "weakly typed" language and its variables have no determined type. The type of the WMLScript variable is determined by the type of the data being assigned, and changes depending on the type of data being changed. WMLScript only supports internally defined data, so we write a program that does not need to specify the type of wmlscript variable, WMLScript automatically matches the type that assigns the data based on the variable. Because the WMLScript data type has five types of integers, floating-point numbers, strings, booleans, and "Invalid types," the type of wmlscript variable can match that of the five types.

4.4.5 variable Domain

Because the type of the variable is particularly determined by the type of data being assigned, the variable value is equivalent to the desired range of the data that the field is assigned to. Below we give the range of integers, floating-point numbers, strings, and Boolean values to determine the domain value of the variable to be typed. 1. The range of integers. The integers supported by WMLScript are 32-bit, meaning that the range of integers is from 2147483648 to +2147483647. We can use the Lang function to get these values during the runtime of the program, such as:

Lang.maxint (); Get the largest integer

Lang.maxint (); Get the smallest integer

2. The range of floating-point numbers. It refers to the minimum and maximum numeric value that the precision of a wmlscript floating-point number can represent WMLScript supports 32 single-precision floating-point numbers, with a maximum of 3.40282347E+38, and a minimum non-zero of 1.17549435E-38 or less (according to normal precision).

We can use the floating-point float function library to run it in the program to get these values:

Float.maxfloa (); Get the maximum floating-point value supported by WMLScript

Float.maxfloa (); Get the minimum floating-point value supported by WMLScript

For some special floating-point numbers that appear during the runtime, WMLScript will be treated according to the following rules:

First, if the operation result is a numeric value that cannot be represented by a precision floating-point number, the result is considered to be a invalid, or an invalid value;

Second, if the result of the operation is overflowed, the result will be treated as 0.0:

The third, minus 0 and positive 0 are exactly equal.

3. The range of strings. Any symbol string that consists of letters, numbers, or special characters is either an operation defined in WMLScript or a function control string in a string library.

4. The range of Boolean data. Boolean data only Ture and flase two values, which is also a Boolean variable of two values. We can use Boolean data to initialize or specify the numeric value of a variable, or to write a Boolean variable to a statement that requires a Boolean value as a parameter. A Boolean value can be the result of a numeric operation, or it can be the result of a logical operation.

Here is a sample example that defines a Boolean variable and assigns an initial value:

var Truth=truth;

var Lie=!truth;


4.5 operator and expression

In WMLScript, an expression can combine variables, constants, and operators to produce certain computational results. The result of an expression operation can be an integer, floating-point, String, or Boolean type of data. In fact, we are not unfamiliar with expressions, for example, 1+2 is a simple expression.

There are two main types of wmlscript expressions. An assignment expression, an expression that assigns data to a variable, for example, mybook=3, in this expression, assigns 3 to the variable myBook, and the expression itself has an arithmetic result, which is 3. The other is an operational expression, which is an expression that produces a result of an operation without an assignment, for example, 1+2 is an expression of an expression, in which the result is 3, but the expression does not assign the result of the operation to the variable.

In the process of expression operation, the expression in the operation of one or both of the data generated operation of the symbol to do the operator, the operator is the operation of the data called operands, in the wmlscript we will use a variety of operators, the following on the operator and related expressions for detailed explanation.

4.5.1 Assignment operator

The assignment operator is used for assignment operations, that is, to assign the desired value to the variable, it can manipulate the operation of an operand, and the simplest assignment operator is "=", for example, x=2, which assigns 2 to the variable x. The following lines of statements are assignment operations:

var= "ABC";

var b=a;

B= "Def";

The assignment operator does not need to specify the object to use, nor does it change the value of the variable to the right of the assignment operator. The assignment operators of WMLScript mainly include the following:

1.=. For assignment operations, an operand is assigned to the left operation.

2 + +. The operand is met with the left-hand operand, and the result of the operation is assigned to the left operand. For example, suppose x=3, then the result of the x+=2 operation is x=5.

+ + is a special operator because it can connect two strings, so the + = operator can also manipulate the string, and then assign the concatenated string to the left operand. For example, suppose x= "Happy", then x+= "New Year" result is x= "Happy New Year".

3.-=. The left-hand operand is simply fetched with an operand, and the result of the operation is assigned to the left operand. For example, suppose x=3 then x-= the result of the operation is x=1.

4*=. The left operation is multiplied by the operator, and the result of the operation is assigned to the left operand. For example, suppose x=6, then the result of the x*=2 operation is x=6.

5/=. The right operation is multiplied by the right operator, and the result of the operation is assigned to the left operand. For example, suppose x=6, then the result of the x*=2 operation is x=6.

6div=. Having the operand process the left operand, and then assigning the integer part of the result of the operation to the left-hand operand, such as x=7, then the result of the xdiv=2 operation is x=3.

7%=. The function is to find the remainder and assign a value, divide the right-hand operand by doing the operand, and finally the residual value of the operation is given to the operand. For example, suppose x=7, then the result of the x%=3 operation is x=1.

8<<=. The function is a signed left displacement and assignment, the left operation and the right operand to the left offset operation, the result is assigned to the left operand.

9>>=. The left and right operations can be performed right to complement the 0 right displacement operation, and the result is assigned to the left operand.

4.5.2 Mathematical operation operator

The mathematical operator can operate on operands of numeric types, and then return the result of an operation of a numeric type.

1+. This is the operation of addition operations, which corresponds to the mathematical operation of the addition operation, such as the expression 1+2 the result of the operation of 3.

The addition operator can also operate on the operands of a string type and then connect two strings as an operation

2-. The check operator, corresponding to the subtraction operation in the speed calculation, such as expression 2-1, the result of the operation is 1.

At the same time, "-" or a negative operator, when it takes the negative operator is an operand, take the function of the negative operator to return the opposite number of operands.

3*. This is the multiply operator, which corresponds to the multiplication in the mathematical operation, for example, the expression 2*3 the result of the operation is 6.

4/. In addition to the operator, corresponding to the mathematical operation of the division operation, but the division in the WMLScript some special, in the WMLScript, the result of division is a floating-point number, but do not want the C language or the Java language in the integer division operation of the result of the results of forced conversion of integers. In WMLScript, 1/2=0.5, and in Jave, 1/2=0.

5div. This is the division operator, which corresponds to the integer operation in the mathematical operation, the result of the operation of an integer, which is the same as in C or the Java language, you can force an integer to convert the result of the operation of the integer.

6%. The modulo operator, which corresponds to the MO operation in mathematical operations, divides two operations and returns the remainder after division.

The modulo operator is used primarily to determine whether a number is divisible by another number.

(The Year%3==0) && (the year%100!=0)) | | (The year%400==0)

Where && represents the operation of the logical operation, | | Represents a logical operation or operation, which we will describe in detail later.

7++. This is the increment operator, which has only one operand, the operation can be on the left side of the operator, or at the right of the operator, it completes the operation by adding the operand by 1. Assuming the operand name is J, and the value is 2, then ++j plus 1 and then returns a value of J of 3, while J + + implements the value 2 of J and then J plus 1.

In a loop, we often use the increment operator to do the exact opposite. The operational operation of the decrement operation is minus 1 by the operand. For example, if the operand name is called J, and the value is 2, then--j the J minus 1 and then returns the value 1, while j--returns the value of J 2 and then J minus 1.

4.5.3-bit operator

For the operator in the operation of the operation will be converted to 32-bit binary number, and then the number of each operand bitwise operation, after the operation of the binary results in accordance with the standard WMLScript numeric type returned to the operation end.

1&. This is the same as the operator, which can operate on a bitwise of two operands, and its rules of operation are:

0&0=0,0&1=0,1&0=0,1&1=1

2|. This is a bit or an operator that can be bitwise OR manipulated on two operands, and the rule of operation is:

0|0=0, 0|1=1,1|0=1,1|1=1

3^. This is the only or operator that can vary or manipulate two operations by bitwise, and its Operation rule is: 0^0=0,0^1=1,1^0=1,1^1=0

4~. This is a bitwise non operator, it has only one operand, can do not operate by bitwise, the Operation rule is: ~0=1,~=0

5<<. This is a left-shift operation, which can perform a left-bit operation on the left-hand operand, given the number of digits to be moved by the operand, and the minimum of the left operand during the move is 0.

6>>. This is the right shift operator, which shifts the left operand to the right, with the operand given the number of bits to move, and in the shift, the bit to the right.

7>>>. This is the 0 right shift operator, which is similar to the right shift operator. When the positive numbers are being manipulated, they have exactly the same effect; when the negative integer to the right operation, because the responsibility to convert to binary, the maximum is 1, so after the right move operation, the highest bit still add 1, and in the 0 right move operation, the highest supplement is 0, therefore, This is a negative number that will be converted to a positive number.

4.5.4 logical operator

Logical operators can combine Boolean-type expressions, complete logical operations, and then return the result of a logical operation-true or false-to accomplish more complex logical judgments. There are 3 kinds of logic operation;

1&&. That is, the logic and the operator it is only when the two operands are ture, the return result is ture, in other cases the result is false or invalid.

2| |. This is the OR operator, which returns the result as ture when at least one of the two operands is ture, and in other cases the result is false or invalid.

3!. That is, a non operator, it has only one operand. When the operand is ture, the return result is flase and the result is ture.

4.5.5 comparison operator

The comparison operator can compare the operands and return a logical value indicating whether the result of the comparison operation is true. The operand of a comparison operation can be a numeric type or a string type of data. Comparison operators are also often referred to as relational operators.

The WMLScript supports a total of 6 comparison operators, which are described below.

1. = =. equals the operator, which can compare two operands for equality. Returns ture if two operands are equal, otherwise returns false

2.! = That is, unequal operators. It can compare whether two operands are equal. Returns False if two operands are equal, otherwise returns ture.

3. >. That is, greater than the operation. Its operation rules, if the left operand is greater than the right-hand operand, return ture.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.