Студопедия
Случайная страница | ТОМ-1 | ТОМ-2 | ТОМ-3
АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатика
ИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханика
ОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторика
СоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансы
ХимияЧерчениеЭкологияЭкономикаЭлектроника

The Scripting Language

Читайте также:
  1. Appendix 5. Body language
  2. B) The International Summer language programme
  3. English language and it role in education
  4. Focus on Language
  5. Focus on Language
  6. Full Title NORMA - an Extremely High-Level Language: Programming without Programs Tech Area / Field
  7. Language

Introduction

OpenHoldem's scripting language is very similar to the C programming expression syntax. If you already know and understand C programming then you have an advantage in that the OH scripting language should be very familiar. This section is largely based off of Ray Bornert's original WinHoldem "C-tutorial" here: http://www.winholdem.net/help/help-c.html

 

Syntax

The general syntax for OpenHoldem formulas is same as that of the C programming language. However, the formulas are strict R-VALUES (right side of an assignment expression), meaning that there is no assignment operator. All values are stored as (double) floating point values on the expression stack. For bitwise operations the values are first converted to integer values and then the operator is applied.

 

Boolean Logic

A boolean expression is composed of logical operators (not, and, or, xor) and operands. All boolean operands have only two values - true and false. Each logical operand has a very well defined operation upon the operand(s) in the expression, with a very well defined result. When any numeric value is used in conjunction with a logical operator, any zero values are considered to be false (0) and any non-zero values are considered to be true (1). If the numeric value in question is not zero then it is considered to be true for boolean purposes.

Reams of material have been written on boolean logic. Example: http://en.wikipedia.org/wiki/Boolean_logic

 

Operators

These operators are listed in order of precedence

Category Operator(s) Associativity
Exponentiation ** ln (not standard ANSI C) Right to Left
Unary ! ~ - ` Right to Left
Multiplicative * / % Left to Right
Additive + - Left to Right
Bitwise Shift << >> Left to Right
Relational < > <= >= Left to Right
Equality ==!= Left to Right
Bitwise AND & Left to Right
Bitwise XOR ^ Left to Right
Bitwise OR pipe (above forward slash on U.S. keyboard) Left to Right
Logical AND && Left to Right
Logical XOR ^^ (not standard ANSI C) Left to Right
Logical OR double pipe (above forward slash on U.S. keyboard) Left to Right
Conditional ?: Right to Left
Group () [] {} (not standard ANSI C) Left to Right

 

Exponentiation

Power ** (not ANSI-C)

a ** b

Standard algebraic exponentiation on a and b.

a is raised to the power of b.

 

Natural Log ln (not ANSI-C)

ln a

Standard algebraic natural log of a

a == e ** (ln a)

 

Natural Log Base e (not ANSI-C)

e == ln(1)

e == 2.71828182845905

 

Unary

A unary operator takes a single operand.

 

Logical NOT!

False when the operand is true. True when the operand is false.

a !a
false true
true false
   

 

Bitwise NOT ~

Logical NOT operation on a bit by bit basis.

expression binary result
a  
~a  

 

Negation -

A good example is the minus sign when it is used to alter the sign of a value. Example: "a + b / -4" The minus sign in front of the 4 is a unary minus.

 

Bit Count ` (not ANSI-C)

Provides a count of the number of bits set in any integer value. Here are 3 examples of the number of bits that are set in some 32-bit integer numbers.

a `a
   
   
   
   

 

Multiplicative

Multiply *

a * b

Standard algebraic multiplication on a and b.

 

Divide /

a / b

Standard algebraic division on a and b.

 

Modulo %

a % b

Standard algebraic modulo on a and b.

 

Additive

Add +

a + b

Standard algebraic addition on a and b.

 

Subtract -

a - b

Standard algebraic subtraction on a and b.

 

Bitwise Shift

Bitwise Shift Left <<

Slides the entire bit pattern to the left by N bits. Note that the leftmost bits are simply dropped and that the rightmost bits are filled with 0's. The shift magnitude is used as modulo 32, meaning that any shift N that is specified in excess of 32 bits has a N%32 operation performed prior to the shift.

expression binary result
a  
a<<1  
a<<7  
a<<31  
a<<32  

 

Bitwise Shift Right >>

Slide the entire bit pattern to the right by N bits. Note that the rightmost bits are dropped and that the leftmost bits are filled with the leftmost bit of the operand. The shift magnitude is used as modulo 32, meaning that any shift N that is specified in excess of 32 bits has a N%32 operation performed prior to the shift.

expression binary result
a  
a>>1  
a>>7  
a>>31  
a>>32  
a  
a>>1  
a>>7  
a>>31  
a>>32  

 

Relational

Less Than <

a b a < b
-1   true
    false
+1   false

 

Greater Than >

a b a > b
-1   false
    false
+1   true

 

Less Than Or Equal <=

a b a <= b
-1   true
    true
+1   false

 

Greater Than or Equal >=

a b a >= b
-1   false
    true
+1   true

 

Equality

Equal ==

a b a == b
-1   false
    true
+1   false

 

Not Equal!=

a b a!= b
-1   true
    false
+1   true

 

Bitwise AND &

Logical AND operation on a bit by bit basis.

 

expression binary
a  
b  
a&b  

 

Bitwise OR |

Logical OR operation on a bit by bit basis.

 

expression binary
a  
b  
b  

 

Bitwise XOR ^

Logical XOR operation on a bit by bit basis.

 

expression binary
a  
b  
a^b  

 

Logical AND &&

False when any operand is false. True when both operands are true.

 

a b a && b
false false false
false true false
true false false
true true true

 

Logical XOR ^^ (not ANSI-C)

False when operands are boolean equal. True when operands are not boolean equal. Note that "a^^b" is equivalent to "(a!=0)^(b!=0)".

 

a b a ^^ b
false false false
false true true
true false true
true true false

 

Logical OR ||

False when both operands are false. True when any operand is true.

 

a b a || b
false false false
false true true
true false true
true true true

 

Conditional?:

Standard algorithmic if then else. "a? b: c" means "If a then b else c"

 

a b c a? b: c
true any any b
false any any c

 

Grouping Operators ()[]{}

Note that [] and {} are not ANSI-C.

 

These grouping operators are used to either visibly separate sections of your code for readability and maintainability purposes, or to affect the precedence of logical operation. Note that unlike WinHoldem's grouping syntax, there is no limitation on how the various grouping operators can be nested.

 

Numeric Constants

Floating point constants

All numeric constants are treated internally as double floating point values in base 10.

Floating Point Numeric Constants
123.456
0.987
 
.5
17.
5.4321e-76

 

Integer constants

There are 4 integer options available as well that allow you to select the base of the constant. The 4 available bases are: 16, 8, 4, 2. Prefixing a numeric constant with a zero followed by a letter (see table below) will specify the numeric base of the constant.

 

Letter Base Name
x   Hex
o   Octal (non-standard ANSI C)
q   Quadal (non-standard ANSI C)
b   Binary (non-standard ANSI C)

 

Examples:

Decimal Hex Octal Quadal Binary
  0x0 0o0 0q0 0b0
  0x1 0o1 0q1 0b1
  0x2 0o2 0q2 0b10
  0x3 0o3 0q3 0b11
  0x4 0o4 0q10 0b100
  0x5 0o5 0q11 0b101
  0x6 0o6 0q12 0b110
  0x7 0o7 0q13 0b111
  0x8 0o10 0q20 0b1000
  0x9 0o11 0q21 0b1001
  0xa 0o12 0q22 0b1010
  0xb 0o13 0q23 0b1011
  0xc 0o14 0q30 0b1100
  0xd 0o15 0q31 0b1101
  0xe 0o16 0q32 0b1110
  0xf 0o17 0q33 0b1111
  0x10 0o20 0q100 0b10000
  0x1f 0o37 0q133 0b11111
  0x3f 0o77 0q333 0b111111
  0x7f 0o177 0q1333 0b1111111
  0xff 0o377 0q3333 0b11111111

 

 


Дата добавления: 2015-07-20; просмотров: 155 | Нарушение авторских прав


Читайте в этой же книге: Technical Reference | Manipulating region records using OpenScrape | Technical Reference | Manipulating font records using OpenScrape | Manipulating hash point records using OpenScrape | Manipulating hash records using OpenScrape | Menu Options | Toolbars | The Formula Editor | Secondary Functions |
<== предыдущая страница | следующая страница ==>
Menu Options| Calculated Symbols

mybiblioteka.su - 2015-2024 год. (0.016 сек.)