' Rapid-Q by William Yu (c)1999-2000 . ' ================================================================================ ' Upload_il_tuo_script_su_Rapidq.it ' Valid_Operators ****** Introduction to Operators ****** Operators perform mathematical or logical operations on values. They are usually encompassed by an expression. For example, 2 * 8 is a valid expression, and * is an operator operating on values 2 and 8. Rapid-Q can evaluate both INFIX and POSTFIX (RPN) expressions, but if you want to evaluate POSTFIX expressions, you'll need to note the special cases. Arithmetic_operators Rapid-Q maintains a table of precedence for each operator. The highest precedence operator will always execute before any lower precedence operator. For operators that share the same precedence, the left to right associativity law holds. Expressions enclosed in braces (...) automatically have higher precedence than expressions outside the braces. _____________________________________________________________________________ |Operation______________|Operator|Precedence|Description______________________| | | | |Returns a character from a string| |String index |[] |1 |ie. s$[2] | | | | |returns the second character in | |_______________________|________|__________|string_s$________________________| | | | |Calculates power of a number | |Exponentiation |^ |1 |ie. 2^6 | |_______________________|________|__________|is_2_to_the_power_of_6___________| | | | |Negates a number | |Negation |- |1 |ie. -99 | |_______________________|________|__________|is_negative_99___________________| | | | |Multiplies 2 numbers | |Multiplication |* |2 |ie. 2*6 | |_______________________|________|__________|is_2_multiplied_by_6_____________| | | | |Divides 2 floating point numbers | |Floating-point Division|/ |2 |ie. 6.5/2.6 | |_______________________|________|__________|is_6.5_divided_by_2.6____________| | | | |Divides 2 integer numbers | | | | |Before integer division is | | | | |performed, operands are rounded | |Integer Division |\ |2 |to integers. The result is | | | | |truncated to an integer value. | | | | |ie. 6\2 | |_______________________|________|__________|is_6_divided_by_2________________| | | | |Shifts bits left by amount | | | | |specified | |Left Bit Shift |SHL |2 |ie. 10 SHL 2 | | | | |is number 10 whose bits are | |_______________________|________|__________|shifted_2_bits_to_the_left_______| | | | |Shifts bits right by amount | | | | |specified | |Right Bit Shift |SHR |2 |ie. 10 SHR 2 | | | | |is number 10 whose bits are | |_______________________|________|__________|shifted_2_bits_to_the_right______| | | | |Returns the remainder of the | |Modulus/Remainder |MOD |3 |division | | | | |ie. 15 MOD 10 | |_______________________|________|__________|is_15/10_whose_remainder_is_5____| | | | |Returns the inverse of a number | | | | |in modulus | |Inverse Modulus |INV |3 |ie. 3 INV 26 | | | | |The inverse of 3 is 9 in 1 (MOD | |_______________________|________|__________|26)______________________________| | | | |Add 2 operands (strings included)| | | | |ie. 3+6 | |Addition |+ |4 |is 3 plus 6 = 9 | | | | |ie. "hi"+"world" | | | | |is "world" appended to "hi" = | |_______________________|________|__________|"hiworld"________________________| | | | |Same as using '+' but maintained | |Addition |& |4 |for compatibility with other | |_______________________|________|__________|BASIC_languages,_such_as_VB._____| | | | |Subtracts 2 operands (strings | | | | |included) | | | | |ie. 6-3 | |Subtraction |- |4 |is 6 minus 3 = 3 | | | | |ie. "jello"-"l" | | | | |is "jello" minus all occurrences | |_______________________|________|__________|of_"l"_=_"jeo"___________________| Relational_operators Relational operators are used to compare 2 values. The result of this comparison is either "true" (nonzero) or "false" (zero). You may assume that "true" equals -1. _____________________________________________________________________________ |Relation_____________|Operator|Precedence|Description________________________| | | | |Tests for equality between 2 | | | | |operands (strings included) | |Equality |= |5 |ie. 2=2 | | | | |if 2 equals 2 then "true" else | |_____________________|________|__________|"false"____________________________| | | | |Tests for inequality between 2 | | | | |operands (strings included) | |Inequality |<> |5 |ie. "hello"<>"world" | | | | |if "hello" is not equal to "world" | |_____________________|________|__________|then_"true"_else_"false"___________| | | | |Tests if operand is less than | | | | |another (strings included) | |Less than |< |5 |ie. 2<10 | | | | |if 2 is less than 10 then "true" | |_____________________|________|__________|else_"false"_______________________| | | | |Tests if operand is greater than | | | | |another (strings included) | |Greater than |> |5 |ie. "z">"a" | | | | |if "z" is greater than "a" then | |_____________________|________|__________|"true"_else_"false"________________| | | | |Tests if operand is less than or | | | | |equal to another (strings included)| |Less than or equal |<= |5 |ie. 2<=10 | | | | |if 2 is less than or equal to 10 | |_____________________|________|__________|then_"true"_else_"false"___________| | | | |Tests if operand is greater than or| | | | |equal to another (strings included)| |Greater than or equal|>= |5 |ie. 20>=10 | | | | |if 20 is greater than or equal to | |_____________________|________|__________|10_then_"true"_else_"false"________| Logical_operators Logical operators perform tests on multiple relations, bit manipulation, or Boolean operations and return a true (nonzero) or false (zero) value to be used in making a decision. _____________________________________________________________________________ |Operation___________________|Operator|Precedence|Description_________________| | | | |Returns the complement | | | | |(inverted bits) | |Logical complement |NOT |6 |ie. NOT -1 | | | | |-1 has all bits set, NOT - | |____________________________|________|__________|1_inverts_all_bits__________| | | | |Compare corresponding bits | | | | |in 2 operands and sets the | | | | |corresponding bit in the | |Conjunction |AND |7 |result to 1 if both bits are| | | | |1. | | | | |ie. 5 AND 3 | | | | |5 AND 3 = 1 since their | |____________________________|________|__________|first_bits_are_set__________| | | | |Compares corresponding bits | | | | |in 2 operands and sets bit | | | | |to 1 if either one has a | |Disjunction (inclusive "or")|OR |8 |corresponding bit set. | | | | |ie. 5 OR 3 | | | | |5 OR 3 = 7 since bits | |____________________________|________|__________|overlap_____________________| | | | |Compares corresponding bits | | | | |in 2 operands and sets bit | | | | |to 1 if only one of the | |Exclusive "or" |XOR |9 |operands has a corresponding| | | | |bit set. | | | | |ie. 5 XOR 3 | | | | |5 XOR 3 = 6 since one bit | |____________________________|________|__________|overlaps____________________| INFIX/POSTFIX_notation Expressions, in most languages, are expressed in INFIX notation. Rapid- Q prefers INFIX notation, but can also handle POSTFIX notation with a few special cases. Example INFIX expression: A = 4 * 7 + (4 - 1)^6 INFIX notation is easier to use and understand than POSTFIX notation. In fact, Rapid-Q's POSTFIX notation is a simple side effect, and was not intentional. Please avoid using POSTFIX if possible. Example POSTFIX expression: A = (4) (7) (*) (4) (1) (-) (6) (^) (+) The 2 expressions should evaluate to 757. As you'll note, when dealing with POSTFIX notation, make sure all operands and operators are enclosed in braces. When dealing with negation, you'll have to do this instead: Example POSTFIX expression w/negation: A = (5) (0-5) (-) Notice that (0-5) and (-5) return different results. ' =============================================================================== ' 2003 Holyguard.net - 2007_Abruzzoweb