SoFunction
Updated on 2025-04-14

Wireless Markup Language (WML) Basics WMLScript Basics Page 1/2

WML Script is part of the WAP application layer of the Unlimited Application Protocol. It can use it to add client processing logic to WML card sets and cards. The latest version is version 1.1. WML Script1.1 is specified based on the ECMAScript scripting language formulated by the European Computer Manufacturer Agreement and has been modified and optimized. It can better support bandwidth communication devices such as mobile phones. Using WML Script in WML programming can effectively enhance the flexibility of client applications. Moreover, we can also use WML Script as a tool to develop powerful WAP network applications and unlimited web pages. In this chapter, we will explain in detail the basic pre-legal system of WML Script1.1 programming, such as basic rules, variable pre-data types, operation assignment expressions, etc. For the sake of simplicity of narrative, we will shortly refer to "WMLScript1.1" as "WMLScript ".
4.1 Calling WML Script functions in WML program
After studying the first two chapters, readers who are familiar with C language may realize that the function functions, logical operation functions, etc. of WML are very limited. WMLScript provides rich functional functions, and we can use WMLScript to enhance WML programming in WAP application development. Therefore, WMLScript has become the main development tool for extending WML programming capabilities.
4.2 The main advantages of WMLScript and its bytecode interpreter
WMLScript has a well-defined set of bytecodes and an interpreter reference structure. The WMLScript data in wireless network transmission is transmitted in binary format, so users can use the Bandwidth communication channel, so that the client phone only needs the minimum memory. The WMLScript modified by ECMAScript can compile programs into bytecode faster, smaller and easier. All these characteristics are that WMLScript has many advantages and functions that WML cannot have.
4.2.1 The main advantages of using WMLScript
The design purpose of WMLScript is to provide general script processing capabilities for WMLScript systems. Using WMLScript, we can further supplement the programming functions of the WML language based on XML, develop network applications and contents targeting bandwidth, such as text, images, selection lists, etc. We can use simple formats to write a more flexible and readable user interface. The advantages and functions that WMLScript cannot have mainly include the following aspects:
(1) Check the legality of user input:
(2) Expand the functions of the user's browser, such as allowing programmers to develop phone calls on their mobile phones, send short messages, store phone numbers, manage phone books or SIM cards, etc.;
(3) Generate the user's confirmation, prompt, warning message or operation dialog box and make it quickly displayed on the browser;
(4) After the user's browser changes, the software and parameters on the browser side can be expanded and configured;
(5) Overcome the client's bandwidth communication connection limitations to the greatest extent and provide rich program functions;
(6) Supplement WML and enable it to implement a variety of services for micro mobile terminal devices, such as supporting advanced user interfaces, increasing client intelligence, providing access to user browser peripheral functions, and browsing and transmitting data on servers and clients is to reduce bandwidth usage.
4.2.2 WMLScript's Bytecode Interpreter
Before WMLScript's bytecode interpreter interprets, a program written in the WMLScript language in text format will be first compiled into binary format code. When compiling, the compiler usually divides the WMLScript program into several editing units. Each unit of the program contains a certain number of statement lines and WMLScript functions. Then, the WMLScript compiler will use the WMLScript program as input content one by one according to these compilation units, and use the corresponding bytecode as output content. When a user calls the WMLScript program through a WAP mobile phone, the compiler's encoding function is activated and executed.
4.3 Basic rules of WMLScript
WMLScript follows the practice of WML in many basic rules. However, since WMLScript is specified in C language, its syntax features are very similar to those in C language. If you are familiar with C language, it should be easier to learn and master this part of the content.
4.3.1 WMLScript and URL
Like WML, WMLScript also follows the URL, HTTP and other specifications of WWW and HTML access resources, and expands the scope of URL usage. In WMLScript, not only the hyperlinks, file paths, or file names, can be processed as URLs, but external functions, access control information, etc. can also be processed as URLs.
To this end, WMLScript adopts a workaround of WML, that is, to improve the way HTML naming resources as values, and to use the form of a program segment anchor (Fragment Anchor) to handle resource positioning. The block anchor point is defined according to the document URL rules and written in the way of adding a tic toe (#) to the block identifier. Using the program block anchor, the WMLScript program can arbitrarily specify a function within the WMLScript compilation unit and can pass the required parameters while calling the function.
4.3.2 Lexical structure
The lexical structure in WMLScript programming is not complicated. Let’s explain the relevant specific rules from the aspects of case sensitivity, spaces, line breaks, comments, i.e. retained words, etc.
(1) Content type. The content types of WMLScript are mainly for two situations: file form and binary form. The type structure can be specified on the server side, and the specific form is:
Text form: text/;
Binary form: application/.
We have already introduced the specific specification method in Chapter 4 and will not be repeated here.
(2) Case sensitivity. WMLScript 1.1 is a case-sensitive scripting language. The various keywords, variables and function names it designs must be reasonably case-based.
(3) Spaces and line breaks. Generally speaking, the WMLScript program value form will ignore all spaces, tabs comply with line breaks, etc. But if these special characters are expressed through code or processed as strings, WMLScript will no longer ignore them. For example, the string "Oct 28,2001" contains spaces, which will not be ignored during execution. It is different from the string "Oct28,2001" that does not contain spaces.
(4) Comments. Like WML programming, comment content can also be added to WMLScript script programs. The comment content is not executed by the program, and the comment cannot be nested. There are two ways to comment WMLScript:
First, line comments. That is, use double oblique line numbers (//) to guide the content of one line, and all the content of this line is used as the comment content. like:
//This is a comment with line, starting from the double slash number to end is commented.
Second, block selection. That is, start with the symbol "/*", and all contents during the period when the symbol "/*" ends with the symbol "/*" are commented contents. like:
/*This is the block comment, the content added in the middle is the comment content*/
(5) Data type and direct encoding. WMLScript allows 4 types of data to be encoded directly and nested and embedded as in a program. The data types in direct encoding of 4 are: integers, floating-point numbers, strings, and boolean values. In addition, the "invalidity" value can also be directly encoded" 1. Integer. When integers are used in decimal, hexadecimal or octal, such integers can be directly encoded.
When programming, decimal numbers do not start with 0, only contain numeric strings of 0~9; hexadecimal data starts with OX or Ox, only contain 0~9, a~f or A~F; octal numbers all start with 0, only contain numeric strings of 0~7.
2. Floating point number. Floating points are usually defined as numbers with decimal points, which can contain decimal and exponential parts. There are many forms of floating-point numbers, which can make decimal integers or floating-point numbers, either fractions or exponents; but a floating-point number must have at least one number.
The index starts with e or E, followed by an integer. The index is powered by 10. For example: the zero power of e0 at 10, for example: another power of e0 at 10, and the negative power set of 2 at 10 at 2-2 is equal to 0.01. The index can be signed, just (+) or minus (-), which represent positive and negative indexes, respectively.
3. String. A string is what is defined between pairs of double quotes ("") or single quotes (' ').
Since WMLScript only allows paired double quotes or but quotes to define strings, a compilation error occurs when using a single quote or a double quote in a program.
Considering that some special characters cannot be directly displayed in a string, WMLScript provides a translation sequence to represent these special characters.
4. Boolean type. It is just two numerical values, ture and false, used to represent "true value" or "false value" in WMLScript. Boolean data can participate in different or equal operations, and we will introduce the specific rules later.
5. Invalid type. Also known as "empty type", it is a quantity supported by WMLScript to represent invalid values, represented by invalid. These two are similar to NULL in C.
4. Reserved words. There is a set of reserved words in WMLScript that contains some words that represent special meanings. These times cannot be defined separately, nor can it be the most other identifier. 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 has 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
There are also some reserved words in WMLScript that are not used:
delete null in this lib void new with
7. Identifier. The identifier of WMLScript can specify or name three elements: variables, functions, and labels. Identifiers cannot start with numbers, but can start with an underscore (-), and the identifier cannot be a reserved word for WMLScript. For example, timeOfDay, speed , quality, HOME_ADDRESS, _myName, __, varO, etc. are all legal identifiers; while strings starting with numbers or special symbols that are not short underscores, as well as reserved characters, etc. are illegal logos, such as while, for, if, my~name, $sys, 123, 3piecs, etc.
Since WMLScript is strictly case-sensitive, identifiers with the same letters but different cases are not the same identifier. For example, Work and work are different identifiers.
8. Namespace. WMLScript provides a relatively free namespace, and the same identifier can be used for different purposes at the same time. For example, as an identifier of a certain function name, it can also be used as variable names, function parameters, program annotations, etc., and their attributes or values ​​do not affect each other when used. In the simple routine below, the identifier myTest is used as the function name, as the variable name, function parameter name, function parameter name, and constant name. Obviously, this particularity of WMLScript provides us with great convenience in writing programs.
12Next pageRead the full text