Difference between revisions of "Category:LSL Operators"

From Second Life Wiki
Jump to navigation Jump to search
m (rough draft start)
m (updating)
Line 4: Line 4:
if you're looking for the current version, it may be found at [[LSL_Operators]].
if you're looking for the current version, it may be found at [[LSL_Operators]].


== Operator Precedence ==
== Operator Precedence (Order of Operations) ==
 
current rough draft of precedence
current rough draft of precedence
{| bgcolor="#FFFFFF" border="1"  cellspacing="2" cellpadding="6"
{| bgcolor="#FFFFFF" border="1"  cellspacing="2" cellpadding="6"
|- bgColor="#A7C1F2"
|- bgColor="#A7C1F2"
! Operator
! Operator
! Notes
! Description
! Associativity
|-
| ()<br>[]
|| Parenthesis<br>List Constructor
|| Inner to Outer<br>then<br>Right to Left
|-
| ,
|| Comma
|| Left to Right*
|-
|-
| ()
| ++ --
|| Parenthesis:
|| Increment/Decrement
all operation within have higher precedence than those outside
|| Right to Left
|-
|-
| (list)<br>(integer)<br>(float)<br>(vector)<br>(rotation)<br>(string)<br>(key)<br>++(prefix)<br>--(prefix)<br>~<br>-<br>!
| (type)<br>~<br>!<br>-
|| Prefix Operators:
|| Typecast<br>Bitwise NOT<br>Logical NOT<br>Negation
When combined together, order of execution takes precedence (- is negation in this context not subtraction)
|| Right to Left
|-
|-
| /<br>%<br>*<br>&<br><nowiki>|</nowiki><br>^
| /<br>%<br>*<br><nowiki>|</nowiki><br>^
|| Division, Multiplication, and Bitwise operators:
|| Division<br>Modulus<br>Multiplication<br>Bitwise OR<br>Bitwise eXclusive OR
|| Left to Right
|-
|-
| +<br>-
| +<br>-
|| Addition and Subtraction Operators:
|| Addition/Concatenation<br>Subtraction
(- is subtraction in this context not negation)
|| Left to Right
|-
| << >>
|| Bitwise Shift Left/Right
|| Left to Right
|-
| < ><br><= >=
|| Less/Greater Than<br>Less/Greater Than or Equal
|| Left to Right
|-
| == !=
|| Equivalent/NOT Equivalent
|| Left to Right
|-
| &
|| Bitwise AND
|| Left to Right?
|-
|-
| &&<br><nowiki>||</nowiki><br>==<br>!=<br><=<br>>=<br>><br><
| ^
|| Logical Operators
|| Bitwise eXclusive OR
order of execution takes precedence when multiple operators of this type are in the same operation
|| Left to Right?
|-
|-
| =<br>+=<br>-=<br>/=<br>%=<br>*=
| <nowiki>|</nowiki>
|| Assignment Operators:
|| Bitwise OR
|| Left to Right?
|-
|-
| (postfix)++<br>(postfix)--
| && <nowiki>||</nowiki>
|| Postfix Operators:
|| Logical AND / OR
|-}
|| Left to Right
|-
| =<br>+= -= /= %= *=
|| Assignment<br>Additive/Subtractive/Divisive/Modulo/Multiplicative Assignment
|| Right to Left*
|}
 
 
* both the Comma and the Assignment Operators are special cases
Commas promote operators all Operators to the Left
However within parenthesis and brackets obey those respective precedences
<lsl>//-- example:
float a;
float b;
float c;
 
string uExample( float x, float y ){
    return (string)x + " " + (string)y;
}
 
default{
    state_entry(){
        string vStrReport = "\n" + (string)(++a) + " " + (string)(++a); //-- first line reports "2.000000 1.000000"
        vStrReport += "\n" + (string)[++b, " ", ++b]; //-- second line reports "1.000000 2.000000"
        vStrReport += "\n" + uExample( ++c, ++c ); //-- third line reports "1.000000 2.000000"
        llOwnerSay( vStrReport );
    }
}</lsl>
Assigment operators Demote all precedences to the Left of them (but obey all precedences below above increment/decrement.
<lsl>//-- example:
integer a;


== Order of Execution ==
default{
    state_entry(){
        llOwnerSay( (string)(++a + a *= ++a) ); //-- yields  "3" instead of "4"
    }
}</lsl>

Revision as of 03:19, 9 January 2010

Page recreated to house the future revision of the LSL_Operators page into categorized Content. Please do not delete.

if you're looking for the current version, it may be found at LSL_Operators.

Operator Precedence (Order of Operations)

current rough draft of precedence

Operator Description Associativity
()
[]
Parenthesis
List Constructor
Inner to Outer
then
Right to Left
, Comma Left to Right*
++ -- Increment/Decrement Right to Left
(type)
~
!
-
Typecast
Bitwise NOT
Logical NOT
Negation
Right to Left
/
%
*
|
^
Division
Modulus
Multiplication
Bitwise OR
Bitwise eXclusive OR
Left to Right
+
-
Addition/Concatenation
Subtraction
Left to Right
<< >> Bitwise Shift Left/Right Left to Right
< >
<= >=
Less/Greater Than
Less/Greater Than or Equal
Left to Right
== != Equivalent/NOT Equivalent Left to Right
& Bitwise AND Left to Right?
^ Bitwise eXclusive OR Left to Right?
| Bitwise OR Left to Right?
&& || Logical AND / OR Left to Right
=
+= -= /= %= *=
Assignment
Additive/Subtractive/Divisive/Modulo/Multiplicative Assignment
Right to Left*


  • both the Comma and the Assignment Operators are special cases

Commas promote operators all Operators to the Left However within parenthesis and brackets obey those respective precedences <lsl>//-- example: float a; float b; float c;

string uExample( float x, float y ){

   return (string)x + " " + (string)y;

}

default{

   state_entry(){
       string vStrReport = "\n" + (string)(++a) + " " + (string)(++a); //-- first line reports "2.000000 1.000000"
       vStrReport += "\n" + (string)[++b, " ", ++b]; //-- second line reports "1.000000 2.000000"
       vStrReport += "\n" + uExample( ++c, ++c ); //-- third line reports "1.000000 2.000000"
       llOwnerSay( vStrReport );
   }

}</lsl> Assigment operators Demote all precedences to the Left of them (but obey all precedences below above increment/decrement. <lsl>//-- example: integer a;

default{

   state_entry(){
       llOwnerSay( (string)(++a + a *= ++a) ); //-- yields  "3" instead of "4"
   }

}</lsl>

Pages in category "LSL Operators"

This category contains only the following page.