Difference between revisions of "Category:LSL Operators"

From Second Life Wiki
Jump to navigation Jump to search
m (updating)
m (tweaked)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}}
{{LSL Header|ml=*}}{{LSLC|Keywords}}{{LSLC|Flow Control}}{{LSLC|}}{{RightToc}}
Page recreated to house the future revision of the LSL_Operators page into categorized Content. '''Please do not delete.'''
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]].
if you're looking for the current version, it may be found at [[LSL_Operators]].


== Operator Precedence (Order of Operations) ==
{{void-box
 
|title=Operator Precedence (Order of Operations)
current rough draft of precedence
|content=
{| bgcolor="#FFFFFF" border="1"  cellspacing="2" cellpadding="6"
{{{!}} bgcolor="#FFFFFF" border="1"  cellspacing="2" cellpadding="6"
|- bgColor="#A7C1F2"
{{!}}- bgColor="#A7C1F2"
! Operator
! Operator
! Description
! Description
! Associativity
! Direction
|-
{{!}}- bgColor="#E0E0E0"
| ()<br>[]
{{!}} ,
|| Parenthesis<br>List Constructor
{{!}}{{!}} Separator
|| Inner to Outer<br>then<br>Right to Left
{{!}}{{!}} Left to Right{{Footnote|handle=1|Separators promote ALL operators to the left until the first unmatched, from its position, open-bracket or open-parenthesis. This precedence ONLY applies within the brackets/parenthesis containing it}}
|-
{{!}}-
| ,
{{!}}
|| Comma
++<br>
|| Left to Right*
--<br>
|-
.<br>
| ++ --
&nbsp;
|| Increment/Decrement
{{!}}{{!}}
|| Right to Left
Increment<br>
|-
Decrement<br>
| (type)<br>~<br>!<br>-
Element Selector<br>
|| Typecast<br>Bitwise NOT<br>Logical NOT<br>Negation
(also Variable Evaluation)
|| Right to Left
{{!}}{{!}} Right to Left
|-
{{!}}-  bgColor="#E0E0E0"
| /<br>%<br>*<br><nowiki>|</nowiki><br>^
{{!}}
|| Division<br>Modulus<br>Multiplication<br>Bitwise OR<br>Bitwise eXclusive OR
=<br>
|| Left to Right
+=<br>
|-
-=<br>
| +<br>-
/=<br>
|| Addition/Concatenation<br>Subtraction
%=<br>
|| Left to Right
<nowiki>*=</nowiki>
|-
{{!}}{{!}}
| << >>
Direct Assignment<br>
|| Bitwise Shift Left/Right
Addition/Concatenation Assignment<br>
|| Left to Right
Subtraction Assignment<br>
|-
Division Assignment<br>
| < ><br><= >=
Modulo/Cross-Product Assignment<br>
|| Less/Greater Than<br>Less/Greater Than or Equal
Multiplication/Dot-Product Assignment
|| Left to Right
{{!}}{{!}}
|-
Right to Left{{Footnote|handle=2|Assignment operators promote ALL operators to the right, from its position, until the first un-bracketed/parenthesized separator, unmatched close bracket or close parenthesis, or semicolon. This precedence ONLY applies within the brackets/parenthesis containing it}}
| == !=
{{!}}-
|| Equivalent/NOT Equivalent
{{!}}
|| Left to Right
()<br>
|-
[]
| &
{{!}}{{!}}
|| Bitwise AND
Parenthesis<br>
|| Left to Right?
[[List|List Constructor]]
|-
{{!}}{{!}} Inner to Outer
| ^
{{!}}-
|| Bitwise eXclusive OR
{{!}}
|| Left to Right?
(type)<br>
|-
~<br>
| <nowiki>|</nowiki>
<nowiki>!</nowiki><br>
|| Bitwise OR
-
|| Left to Right?
{{!}}{{!}}
|-
[[Typecast]]<br>
| && <nowiki>||</nowiki>
Bitwise NOT<br>
|| Logical AND / OR
Logical NOT<br>
|| Left to Right
Negation
|-
{{!}}{{!}} Right to Left
| =<br>+= -= /= %= *=
{{!}}-
|| Assignment<br>Additive/Subtractive/Divisive/Modulo/Multiplicative Assignment
{{!}}
|| Right to Left*
/<br>
|}
%<br>
 
<nowiki>*</nowiki>
 
{{!}}{{!}}
* both the Comma and the Assignment Operators are special cases
Division<br>
Commas promote operators all Operators to the Left
Modulus<br>
However within parenthesis and brackets obey those respective precedences
Multiplication
<lsl>//-- example:
{{!}}{{!}} Left to Right
float a;
{{!}}-
float b;
{{!}}
float c;
-<br>
 
+
string uExample( float x, float y ){
{{!}}{{!}}
    return (string)x + " " + (string)y;
Subtraction<br>
}
[[LSL_Addition|Addition/Concatenation]]
{{!}}{{!}} Left to Right
{{!}}-
{{!}}
<<<br>
>>
{{!}}{{!}}
Bitwise Shift Left<br>
Bitwise Shift Right
{{!}}{{!}} Left to Right
{{!}}-
{{!}}
<<br>
><br>
<=<br>
>=
{{!}}{{!}}
Less Than<br>
Greater Than<br>
Less Than or Equal<br>
Greater Than or Equal
{{!}}{{!}} Left to Right
{{!}}-
{{!}}
==<br>
<nowiki>!=</nowiki>
{{!}}{{!}}
Equivalent<br>
NOT Equivalent
{{!}}{{!}} Left to Right
{{!}}-
{{!}} &
{{!}}{{!}} Bitwise AND
{{!}}{{!}} Left to Right
{{!}}-
{{!}} ^
{{!}}{{!}} Bitwise eXclusive OR
{{!}}{{!}} Left to Right
{{!}}-
{{!}} <nowiki>|</nowiki>
{{!}}{{!}} Bitwise OR
{{!}}{{!}} Left to Right
{{!}}-
{{!}}
&&<br>
<nowiki>||</nowiki>
{{!}}{{!}}
Logical AND<br>
Logical OR
{{!}}{{!}} Left to Right{{Footnote|handle=3|There is no Short Circuiting of Logical Operators in LSL, both operands will be evaluated regardless.}}
{{!}}}
=== Special Notes ===
{{Footnotes}}
}}


default{
{{void-box
    state_entry(){
|title= Logical Operators
        string vStrReport = "\n" + (string)(++a) + " " + (string)(++a); //-- first line reports "2.000000 1.000000"
|content=
        vStrReport += "\n" + (string)[++b, " ", ++b]; //-- second line reports "1.000000 2.000000"
Logical Operators are operators those result is either TRUE or FAlSE.
        vStrReport += "\n" + uExample( ++c, ++c ); //-- third line reports "1.000000 2.000000"
* insert truth tables
        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{
{{void-box
    state_entry(){
|title=Bitwise Operators
        llOwnerSay( (string)(++a + a *= ++a) ); //-- yields  "3" instead of "4"
|content=
    }
Bitwise Operators are similar to Logical Operators, but act on all bits of an integer simultaneously as if they were each a Boolean value.
}</lsl>
* flesh this out
}}

Latest revision as of 17:06, 29 September 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)

Operator Description Direction
, Separator Left to Right[1]

++
--
.
 

Increment
Decrement
Element Selector
(also Variable Evaluation)

Right to Left

=
+=
-=
/=
%=
*=

Direct Assignment
Addition/Concatenation Assignment
Subtraction Assignment
Division Assignment
Modulo/Cross-Product Assignment
Multiplication/Dot-Product Assignment

Right to Left[2]

()
[]

Parenthesis
List Constructor

Inner to Outer

(type)
~
!
-

Typecast
Bitwise NOT
Logical NOT
Negation

Right to Left

/
%
*

Division
Modulus
Multiplication

Left to Right

-
+

Subtraction
Addition/Concatenation

Left to Right

<<
>>

Bitwise Shift Left
Bitwise Shift Right

Left to Right

<
>
<=
>=

Less Than
Greater Than
Less Than or Equal
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
Logical OR

Left to Right[3]

Special Notes

  1. ^ Separators promote ALL operators to the left until the first unmatched, from its position, open-bracket or open-parenthesis. This precedence ONLY applies within the brackets/parenthesis containing it
  2. ^ Assignment operators promote ALL operators to the right, from its position, until the first un-bracketed/parenthesized separator, unmatched close bracket or close parenthesis, or semicolon. This precedence ONLY applies within the brackets/parenthesis containing it
  3. ^ There is no Short Circuiting of Logical Operators in LSL, both operands will be evaluated regardless.

Logical Operators

Logical Operators are operators those result is either TRUE or FAlSE.

  • insert truth tables

Bitwise Operators

Bitwise Operators are similar to Logical Operators, but act on all bits of an integer simultaneously as if they were each a Boolean value.

  • flesh this out

Pages in category "LSL Operators"

This category contains only the following page.