Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of WML Script

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article is about sample analysis of WML Script. Xiaobian thinks it is quite practical, so share it with everyone for reference. Let's follow Xiaobian and have a look.

WML Script is part of the WAP application layer, which allows you to add client-side processing logic to WML decks and cards. The latest version is version 1.1. WML Script 1.1 is a modified and optimized version of ECMAScript, a scripting language developed by the European Computer Manufacturers Association. It can better support broadband communication devices such as mobile phones. Using WML Script in WML programming can effectively enhance the flexibility of client applications. Moreover, we can 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 basics of WML Script 1.1 programming, such as basic rules, variable pre-data types, operation assignment expressions, etc. For simplicity of description, we will refer to "WMLScript 1.1" as "WMLScript " in the future.

4.1 Calling WML Script Functions in WML Programs

After studying the first two chapters, readers familiar with C language may realize that WML's function, logic operation function, etc. are very limited. WMLScript provides a wealth of functional features, we can use WMLScript in WAP application development to enhance WML programming. As a result, WMLScript became the primary development tool for extending WML programming capabilities.

4.2 Main Benefits of WMLScript and Its Bytecode Interpreter

WMLScript has a well-defined set of bytecodes and an interpreter reference structure. WMLScript data is transmitted in binary format over wireless networks, so users can use broadband communication channels to keep client phones to a minimum of memory. ECMAScript modifications result in WMLScript being able to compile programs into bytecode form faster, smaller, and easier. All of these features, WMLScript has many advantages and features that WML does not have.

4.2.1 Main Benefits of Using WMLScript

WMLScript is designed to provide general scripting capabilities for WMLScript systems. Using WMLScript we can further supplement the XML-based WML programming language to develop bandwidth-specific web applications and content, such as text, images, selection lists, etc. We can use simple formats to write more flexible and readable user interfaces. WMLScript has advantages and functions that WML cannot have, mainly including the following aspects:

(1) Check the legality of user input:

(2) Expand user browser functions, such as allowing programmers to make phone calls, send short messages, store phone numbers, manage phone books or SIM cards, etc.;

(3) Generate confirmation, prompt, warning message or operation dialog box at the user end, and make it quickly displayed on the browser;

(4) After the change of the user browser, the software and parameters of the browser can be expanded and configured;

(5) Overcome the bandwidth communication connection limitation of the client to the greatest extent and provide rich program functions;

(6) Complementing WML and enabling it to implement multiple services for micro Mobile device devices, such as supporting advanced user interfaces, increasing client intelligence, providing access to peripheral functions of user browsers, and reducing bandwidth consumption by browsing and transmitting data between servers and clients.

4.2.2 Bytecode Interpreter for WMLScript

Text-format programs written in WMLScript are compiled into binary format code before WMLScript's bytecode interpreter interprets them. 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, and then the WMLScript compiler will take the WMLScript program as input and the corresponding byte code as output according to these compilation units. When the user calls WMLScript program through WAP mobile phone, the coding function of compiler is activated and executed.

4.3 WMLScript Basic Rules

WMLScript follows WML in many of its basic rules. However, since WMLScript is specified based on C, its syntactic features are very similar to C. If you are familiar with the C language, then learning and mastering this part of the content should be relatively easy.

4.3.1 WMLScript and URLs

Like WML, WMLScript follows WWW and HTML specifications for accessing resources such as URLs and HTTP, and expands the scope of URL usage. In WMLScript, not only hyperlinks and file paths, i.e., file names, but also external functions and access control information can be processed as URLs.

To this end, WMLScript takes a workaround from WML, which improves the way HTML names resources as values and handles resource positioning in the form of fragment anchors. The segment anchor is defined according to the document URL rules and written with a tick (#) before the segment identifier. Using segment anchors, WMLScript programs can call arbitrary functions within the WMLScript compilation unit and pass desired arguments at the same time.

4.3.2 Lexical structure

The lexical structure in WMLScript programming is not complex. We will explain the specific rules from case sensitivity, spaces, newlines, comments, reserved words, etc.

1) Type of content. The content type of WMLScript is mainly for file form and binary form. The type structure can be specified on the server side. The specific form is:

Text format: text/vnd.wap.wmlscript;

Binary form: application/vnd.wap.wmlscriptc.

We have already described the specific method of designation in Chapter 4, and we will not repeat it here.

(2) Case sensitive. WMLScript 1.1 is a case-sensitive scripting language. The keywords, variables, and function names it designs must be appropriately capitalized.

(3) Spaces and newlines. In general, WMLScript program value forms ignore all spaces, tabs, newlines, and so on. However, WMLScript no longer ignores these special characters if they are expressed in code or processed as strings. For example, the string "Oct 28, 2001" contains spaces, which are not ignored when executed, unlike the string "Oct28,2001" without spaces.

(4) Notes. As with WML programming, comments can be added to WMLScript scripts. Comment content is not executed by the program, and comments cannot be nested. There are two ways to annotate WMLScript:

First, line comments. That is, the double diagonal line number (//) leads to a line of content, and this line of content is all used as comment content. For example:

//This is a line comment, starting with a double slash and ending with a comment.

Second, block selection. That is, everything during the period beginning with the symbol "/*" and ending with the symbol "/*" is comment content. For example:

/* This is the block comment, and the content added in the middle is the comment content */

(5) Data types and direct coding. WMLScript allows four types of data to be encoded directly and nested and embedded in programs. The 4 directly encoded data types are: integer, floating point, string, and boolean. Alternatively, the "invalidity" value can be coded directly as " 1. Round numbers. When integers are used in decimal, hexadecimal, or octal, they can be directly encoded.

When programming, decimal numbers do not start with 0 and only contain numerical strings from 0 to 9; hexadecimal data start with OX or Ox and only contain strings from 0 to 9, a to f, or A to F; octal numbers start with 0 and only contain strings from 0 to 7.

2. Floating point numbers. Floating-point numbers are usually defined as numbers with decimal points and can contain both decimal and exponential parts. Floating-point numbers have many forms, which can be decimal integers or floating-point numbers, which can be fractions or exponents; however, a floating-point number must have at least one number.

An exponent starts with e or E followed by an integer. The index is raised to a power of 10. For example, e0 is the zeroth power of 10, e.g., e0 is the other power of 10, and e-2 is the negative power of 10 equal to 0.01. Exponents can be signed, either positive (+) or negative (-), representing positive and negative exponents, respectively.

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

Because WMLScript only allows double quotes or open quotes to define strings, compilation errors occur when a single quote or a double quote is used in a program.

Given that some special characters cannot be directly represented in strings, WMLScript provides translation sequences to represent them.

4. Boolean. It's just true and false, which is used to represent "true" or "false" in WMLScript. Boolean data can participate in exclusive OR operations, the specific rules we will introduce later.

5. Invalid type. Also known as "null type," it is a quantity supported by WMLScript to represent invalid values, denoted as invalid. This is similar to NULL in C.

4. reserved word. WMLScript defines a set of reserved words that contain words with special meanings that cannot be defined otherwise or used as other identifiers. The reserved words in WMLScript are as follows:

acces http agent if break isvalid continue meta header

p name p= path domain return else typeof while

equiv url extern use for user function var

In addition, WMLScript reserves 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 unused keywords:

delete null in this lib void new with

7. Identifiers. WMLScript identifiers can specify or name three types of elements: variables, functions, and annotations. Identifiers cannot start with a number, but can start with an underscore (-), and identifiers cannot be reserved words in WMLScript. For example, timeOfDay, speed, quality, HOME_ADDRESS,_myName, varO, etc. are all legal identifiers; strings starting with numbers or special symbols other than short underscores, and reserved words, etc. are illegal flags, such as while, for, if, my~name,$sys, 123, 3 pieces, take.this, etc.

Because WMLScript is case sensitive, identifiers with the same letter but different case 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 simultaneously. For example, as an identifier of a function name, it can also be used as a variable name, function parameter, program label, etc., and their attributes or values do not affect each other when used. In the following simple routine, the myTest identifier is used as both the function name, variable name, function parameter name, function parameter name, and constant name. Obviously, this particular feature of WMLScript makes writing programs much easier.

Thank you for reading! About "WML Script sample analysis" This article is shared here, I hope the above content can be of some help to everyone, so that everyone can learn more knowledge, if you think the article is good, you can share it to let more people see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report