lang_ref_expressions.html 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type"
  4. content="text/html; charset=iso-8859-1">
  5. <title>Language Reference - Expressions and Conversions</title>
  6. <link rel="stylesheet" href="lang_ref.css" type="text/css">
  7. </head>
  8. <body><br>
  9. &nbsp;<span class="Command">&nbsp;Expressions and Conversions&nbsp;</span>
  10. <blockquote>
  11. <p> The following operators are supported, listed in order of precedence: </p>
  12. </blockquote>
  13. <table width="85%" border="0" cellspacing="2" cellpadding="2" align="center">
  14. <tr>
  15. <td width="13%" nowrap>
  16. <p>
  17. <p>New,First,Last</p>
  18. </td>
  19. <td width="87%">custom type operators (unary) </td>
  20. </tr>
  21. <tr>
  22. <td width="13%" nowrap>
  23. <p>
  24. <p>Before,After</p>
  25. </td>
  26. <td width="87%">object operators (unary) </td>
  27. </tr>
  28. <tr>
  29. <td width="13%" nowrap>
  30. <p>
  31. <p>Int,Float,Str</p>
  32. </td>
  33. <td width="87%">type conversion operators (unary) </td>
  34. </tr>
  35. <tr>
  36. <td width="13%" nowrap>
  37. <p>
  38. <p>+,-,~</p>
  39. </td>
  40. <td width="87%">arithmetic posate(?), negate, bitwise complement (unary) </td>
  41. </tr>
  42. <tr>
  43. <td width="13%" nowrap>^</td>
  44. <td width="87%">arithmetic 'to-the-power-of' (binary) </td>
  45. </tr>
  46. <tr>
  47. <td width="13%" nowrap>*,/,Mod</td>
  48. <td width="87%">arithmetic multiply, divide, remainder (binary) </td>
  49. </tr>
  50. <tr>
  51. <td width="13%" nowrap>
  52. <p>
  53. <p>Shl,Shr,Sar</p>
  54. </td>
  55. <td width="87%">bitwise shift operators (binary) </td>
  56. </tr>
  57. <tr>
  58. <td width="13%" nowrap>
  59. <p>
  60. <p>+,-</p>
  61. </td>
  62. <td width="87%">arithmetic add, subtract (binary) </td>
  63. </tr>
  64. <tr>
  65. <td width="13%" nowrap>
  66. <p>
  67. <p><,>,<=,>=,=,<></p>
  68. </td>
  69. <td width="87%">comparison operators (binary) </td>
  70. </tr>
  71. <tr>
  72. <td width="13%" nowrap>
  73. <p>
  74. <p>And,Or,Xor</p>
  75. </td>
  76. <td width="87%">bitwise And, Or and Exclusive Or (binary) </td>
  77. </tr>
  78. <tr>
  79. <td width="13%" nowrap>Not</td>
  80. <td width="87%">
  81. <p>
  82. <p> logical Not (unary)</p>
  83. </td>
  84. </tr>
  85. </table>
  86. <p>
  87. <p>
  88. <blockquote>
  89. <p> Unary operators take one operand, while binary operators take two. </p>
  90. <p> Arithmetic operators produce a result of the same type as the operands.
  91. For example, adding two integers produces an integer result. </p>
  92. <p> If the operands of a binary arithmetic or comparison operator are not of
  93. the same type, one of the operands is converted using the following rules:
  94. </p>
  95. <blockquote>
  96. <p>- If one operand is a custom type object, the other must be an object of
  97. the same type, or 'Null'.<br>
  98. </p>
  99. <blockquote>
  100. <p>Else if one operand is a string, the other is converted to a string.
  101. <br>
  102. </p>
  103. <p>Else if one operand is floating point, the other is converted to floating
  104. point. <br>
  105. </p>
  106. <p>Else both operands must be integers. </p>
  107. </blockquote>
  108. </blockquote>
  109. </blockquote>
  110. <blockquote>
  111. <p>When floating point values are converted to integer, the value is rounded
  112. to the nearest integer. When integers and floating point values are converted
  113. to strings, an ascii representation of the value is produced. </p>
  114. <p>When strings are converted to integer or floating point values, the string
  115. is assumed to contain an ascii representation of a numeric value and converted
  116. accordingly. Conversion stops at the first non-numeric character in the string,
  117. or at the end of the string. </p>
  118. <p>The only arithmetic operation allowed on string is '+', which simply concatenates
  119. the two operands.</p>
  120. <p> Int, Float and Str can be used to convert values. They may be optionally
  121. followed by the appropriate type tag - ie: 'Int%', 'Str$' and 'Float#'. </p>
  122. <p>Comparison operators always produce an integer result: 1 for true, 0 for
  123. false. </p>
  124. <p>If one of the operators is a custom type object, the other must be an object
  125. of the same type, or 'Null', and the only comparisons allowed are '=' and
  126. '<>'. </p>
  127. <p>Bitwise and logical operators always convert their operands to integers and
  128. produce an integer result. </p>
  129. <p>The Not operator returns 0 for a non-zero operand, otherwise 1. When an expression
  130. is used to conditionally execute code - for example, in an 'If' statement
  131. - the result is converted to an integer value. A non-zero result means true,
  132. a zero result means false. </p>
  133. <p>&nbsp;</p>
  134. </blockquote>
  135. </body>
  136. </html>