Laynetworks  
Web laynetworks.com Google
Home | Site Map | Tell a friends
Management Tutorials
Download
Tutorials
History
Computer Science
Networking
OS - Linux and Unix
Source Code
Script & Languages
Protocols
Glossary
IGNOU
Quiz
About Us
Contact Us
Feedback
 
Sign up for our Email Newsletter
 
Get Paid for Your Tech Turorials / Tips

 

 

Home > Script & Languages > WML Script Reference
 
WML Script Reference
<< Back to Tutorial
Page : 1 2 3
 
This Section outlines the syntax of the WMLScript language
  1. Arithmatic
  2. Logical 
  3. Bitwise Logical
  4. Bitwise Logical
  5. Assignment
  6. Comparison 
  7. Miscellaneous 

WMLScript Operator Precedence

WMLScript Statement/Functions

  1. Declarations
  2. Loops
  3. Execution Control statements

Pragrams 

Comment 

Escape Codes 

WMLScript Operators 

 
A. Arithmetic Operators
Name Example Result
Additional v1 + v2 Sum of v1 and v2
Concatenation of v1 and v2, if they are strings.
Subtraction v1 - v2 Different of v1 and v2
Multiplication v1 * v2 Product of v1 and v2
Division v1 / v2 Quotient of v2 into v1
Integer Division v1 div v2 Integer quotient of v2 into v1 (ignoring the remainder)
Modulus v1 % v2 Integer remainder of dividing v1 by v2
Prifix Increment ++ *v2 (v1+1) *v2
Profix Increment v1 ++ v2 (v1v2). Is then incremented by 1
Profix Decrement --v1 v2 (v1 - 1) *v2
Profix Decrement v1-- *v2 (v1 * v2). V1 is then decremented by 1
 
B. Logical Operators
 
These operators should return one of the Boolean literals, true or false. However, this may not happen if either v1 or v2 is neither a Boolean value nor a value that easily converts to a Boolean value, such as 0,1, null, the empty string, or undefined.
 
Name Example Meaning
Logical AND v1 && v2 Returns true if both v1 and v2 are true, false otherwise.
    Will not evalute v2 if v1 is false.
Logical OR v1 v2 Returns false if both v1 and v2 are false, true otherwise.
    Will not evalute v2 if v1 is true.
Logical NOT !v1 Returns false if v1 is true otherwise.
C Bitwise Shift Operators
 
These operators work by converting the value in v1 to a 32 bit binary number and then moving the bits in the number to the left or the right by the number of places specified by v2.
 
Name Example Meaning
Left Shift v1 && v2 Shifts v1 to the left by v2 places, filling the
Right Shift v1 v2 new gaps in with zeros
    Shifts v1 to the right by v2 places, ignoring the bitts shifted off the number
Zero-Fill Right Shift v1 && v2 Shifts v1 to the right by v2 place, ignoring the bits shifted off the number and adding v2 zeros to the left of the number
 
D. Bitwise Logical Operators
 
These operators work by converting the values in both v1 and v2 to 32 bit binary numbers and then comparing the individual bits of these two binary numbers. The result is returned as a normal decimal number.
 
Name Example Meaning
Bitwise AND v1 & v2 ANDs each pair of corresponding bits
Bitwise OR v1 | v2 Ors each pair of corresponding bits
Bitwise XOR v1^ v2 XORs (that is, exclusive Ors) each pair of  corresponding bits
Bitwise NOT -v1 Inverts all the bits in the number
 
E. Assignment operators
 
Name Example Meaning
Assignment v1 = v2 Setting v1 to the value of v2
Shorthand Addition or  v1 += v2 v1 = v1 + v2
Shorthand Concatenation    
Shorthand Subtraction v1 -=  v2 v1 = v1 - v2
Shorthand Multiplication v1 *= v2  v1 = v1 * v2
Shorthand Division v1 /= v2 v1 = v1 / v2
Shorthand Integer Division v1 div= v2 v1 = v1 div v2
Shorthand Modulus v1 %= v2 v1 = v1 % v2
Shorthand Left Shift v1 <<= v2 v1 = v1<< v2
Shorthand Right Shift v1 = v2 v1 = v1 v2
Shorthand Zero-Fill Right Shift v1 = v2 v1 = v1 v2, adding 2 padding zeros after assignment.
Shorthand AND v1 &= v2 v1 = v1 & v2
Shorthand XOR v1 ^= v2 v1 = v1 ^ v2
Shorthand OR  v1 |= v2 v1 = v1 | v2
 
F. Comparison operators
 
These operators return the Boolean literal values, true and false. If v1=1 and v2=2, the following statements are all true.
 
Name Example Meaning
Equal v1= =1 True if two operands are strictly equal.
Not Equal v1 != v2 True if two operands are strictly not equal.
Greater Than v2 > v1 True if LHS operand is greater than RHS operand.
Greater Than Or Equal v2 > = v2 True if LHS operand is greater than or equal to RHS operand.
Less Than v1 < v2 True if LHS operand is less than RHS operand.
Less Than Or Equal v1 < = v1 True if LHS operand is less than or equal to RHS operand.

TOP

G. Miscellaneous operators
There are several other miscellaneous operators in WMLScript.
 
Name Example Meaning
Conditional Operator evalquery ? v1 : v2 If evalquery is true, the operatorreturns v1, else it returns v2.
Comma Operator eval1, eval2 Evaluates both eval1 and eval2 while treating the two as one expression.
    Can also be used to declare or set multiple variables at the same time.
typeof type of v1 Returns a number representing the type of v1, which is not evaluated.
    The numbers 0, 1, 2, 3, 4 represent the type integer, floating point, string, Boolean and invalid.
Isvalid isvalid x Returns a Boolean: true if x is not of type invalid, and false if x is of type invalid.
 
H. Operator Precedence
 
Does 1 + 2 + 3 = 1 + ( 2 * 3) = 7 or does it equal (1 + 2) * 3 = 9? The table shows precedence with highest at the top, and like operators grouped together. The third column explains whether to read 1+2+3+4 as ((1+2)+3)+4 or 1+((2+(3+(4))).
 
Operator type Operators Evaluations order for like elements

Postfix [] () expr++  expr--  left to right
Unary ++expr -expr +expr -expr - ! right to left
Type typeof isvalid right to left
Multiplicative *  /  div  % left to right
Additive +    - left to right
Shift <<  left to right
Relational <      <=    = left to right 
Equality =  =  ! = left to right 
Bitwise AND & left to right
Bitwise Exclusive OR  ^ left to right
Bitwise Inclusive OR  | left to right 
Logical AND &&  left to right
Logical OR ||left to right right to left
Conditional  ?     :   right to left
Assignment =  +=   -=  *=  /=  div=  %=  &=  ^= |= right to left
Comma  , left to right
 
WMLScript Statements/Functions
 
The following tables describe WMLScript statements
 

A. Declarations 

Statement Example Description 

Var Number = 6 ; Initializing it to a value is Optional at the time of

Var N1, N2, N3 = 6; declaration.
Function extern function doIt Now ( ) Used to declare a function with

{ the specified parameters. 
Statements To return a value the function must use the return statement. }; extern function do this (p1,p2,p3) 
extern is used so that the function is available outside of where it is defined. { statements } ;

use use url script2

*http://www.somewhere.com/WMLS use is used to enable the script scripts/script2.wmls" ; to use pragmas (see table below). 

B. Loops

Statement Example Description

For for (var 1=0; i<15; I++) Creates a loop controlled according to the three optional expressions enclosed { in the parentheses after the for and separated by semicolons. The first of x + = i; these three expressions is the initial-expressions, the second is the test

do something (x); condition, and the third is the increment -expression. }

if . . . else if (x < = y) Executes a block of statements if the condition evaluates to true. If the {condition evaluates to false, another

TOP


Statement Example Description 

block of statements can be executed thing + = x; using else (this is optional).

x + + ; 

}

Executes a block of statements if a test condition evalutes to true. The loop then { repeats, testing the condition with each repeat, ceasing if the condition evaluates

dosomething(); to false. }

{ control to the statement following the loop.

if (10 = = x)

break;

x++;

}

return x*b;

statements in the current iteration of a while or for loop; execution of the loop

{continues with the next iteration.

if (0 = = (++ count % 2))

continue;

return count*c;

}

returnSthg (x,y)

{

}

Pragmas

Pragma Example Description

url use url ID "URL" Used to specify the URL of the WMLScript file containing the functions we want to use, in URL, and can then access these functions using the name specified in ID.

access use access domain Used to specify the domain and "domin" path "path" path from which access is allowed to function in the current WMLScript. 

meta use meta type property Used to supply additional information. content scheme type represents the type of pragma,property the name of the header you wish to set, content the value you want to set the header, and scheme the formatting of the header

Comment

Comments are notes which the scrip engine ignores, and which can be used to explain the code.

//this is the syntax for a one line comment_

/* and this is the syntax for a multiple line comment. The comment can be of any length, as long as it is contained within the "star slash" brackets */ 

TOP

Escape Codes 

The following table lists all the literal string escape codes.

Escape Code Represents

\' Single quote

\" Double quote

\\ Backslash

\ / Frontslash 

\b Backspace

\f Newline

\r Carriage return

\t Horizontal tab

\xhh Character hh from the Latin -1 character set (ISO 8859-1) hexadecimal format as two digits

\ooo Character ooo form the Latin-1 character set (ISO 8859-1) format as three digits

\uhhhh Character hhhh from the Unicode character set, (ISO 8859-1) format as four digits 

Standard WMLScript Library Functions

Dialogs

This library contains functions used to produce simple use interface cards. 

Alert

Usage: alert(message)

Parameters: message-of type string, the warning to be displayed to the user

Comments: This function displays the message passed to it as a warning and when the user confirms they have read the message returns them to the previous card 

Example: Dialogs.alert ("There has been an error"); 

Confirm 

Usage: confirm(message, ok, cancel)

Parameters: message-of type string, the positive option to offer the user

Cancel-of type string, the negative option to offer the user

Comments: a Boolean, true if the user chooses ok, false if they choose cancel Confirmation, is required.

Example: bleResult = Dealogs.confirm("Are you sure you wish to do this "Yes", "Not really"); 

Prompt

Usage: prompt(message, default)

Parameters: message-of type string, the text to display prompting the user for input default-of type string, the default text to fill to input box with

Comments: This function just presents the user with an input box to fill.

Example: strResult = Dialogs.prompt ("Enter your name", "Bob");

Float

This library contains functions for the manipulation and conversion of floating point

numbers.

Ceil

Usage: ceil(value)

Parameters: value - a floating point number

Returns: An integer, which is nearest in size to the value, but not smaller than it.

Comments: Be careful when using negative numbers, ceil(2.7)=and NOT-3

Example: x = Float.ceil (4.1);

// x is assigned the value 5

floor

Usage: floor(value)

Parameters: value- a floating point number

Returns: An integer, which is nearest in size to the value, but not greater than it

Comments: Be careful when using negative numbers, floor(-4.1)= -5 and NOT -4

Example: x = Float.floor (1.9) ;

Int

Usage: int(value)

Parameters: value-a floating point number

Returns: The integer part of the floating point value Comments: This simply returns the integer part of the
value; it doesn't round the number 

Example: x = float.int(2.9) ;

// x is assigned the value 2

TOP
 
Page : 1 2 3
 
Donation | Useful links | Link to Laynetworks.com | Legal | SharePoint Development
Copyright © 2000-2010 Lay Networks All rights reserved.