commonutil.formula

算式處理函式庫 / Formula processing functions

class ArgumentSeparator(v=None, *args, **kwds)[source]

表現參數分隔字元的物件 / Class of argument separator token

class BaseFunction[source]

表現函數的基底物件 / Base class of function

evaluate(*args)[source]

進行運算,參數數量為 get_argument_count() 方法所傳回的數值

Perform the computation. The number of parameter will be the value returned by get_argument_count() method.

Returns:運算結果 / Result of evaluation
get_argument_count()[source]

取得參數的數量

Get the number of arguments

Returns:參數的數量 / Number of arguments
class BaseOperator[source]

表現運算子的基底物件 / Base class of operator

evaluate(*args)[source]

進行運算,參數數量為 get_operand_count() 方法所傳回的數值

Perform the computation. The number of parameter will be the value returned by get_operand_count() method.

Returns:運算結果 / Result of evaluation
get_operand_count()[source]

取得運算元的數量

Get the number of operand

Returns:運算元的數量 / Number of operand(s)
get_priority()[source]

取得運算子的優先順序,愈高的優先順序應傳回愈大的值

Get the priority of operator. Bigger value means higher priority.

Returns:運算子的優先權 / Priority of operator
is_left_associative()[source]

運算子是否為左結合

Return a boolean value to indicate associative of operator.

Returns:傳回 True 時表示運算子為左結合,否則為右結合 / Return True for left-associative operator; False for right-associative operator
class Divide(v=None, *args, **kwds)[source]
evaluate(a, b, *args)[source]

進行運算,參數數量為 get_operand_count() 方法所傳回的數值

Perform the computation. The number of parameter will be the value returned by get_operand_count() method.

Returns:運算結果 / Result of evaluation
get_operand_count()[source]

取得運算元的數量

Get the number of operand

Returns:運算元的數量 / Number of operand(s)
get_priority()[source]

取得運算子的優先順序,愈高的優先順序應傳回愈大的值

Get the priority of operator. Bigger value means higher priority.

Returns:運算子的優先權 / Priority of operator
class Minus(v=None, *args, **kwds)[source]
evaluate(a, b, *args)[source]

進行運算,參數數量為 get_operand_count() 方法所傳回的數值

Perform the computation. The number of parameter will be the value returned by get_operand_count() method.

Returns:運算結果 / Result of evaluation
get_operand_count()[source]

取得運算元的數量

Get the number of operand

Returns:運算元的數量 / Number of operand(s)
get_priority()[source]

取得運算子的優先順序,愈高的優先順序應傳回愈大的值

Get the priority of operator. Bigger value means higher priority.

Returns:運算子的優先權 / Priority of operator
class Multiply(v=None, *args, **kwds)[source]
evaluate(a, b, *args)[source]

進行運算,參數數量為 get_operand_count() 方法所傳回的數值

Perform the computation. The number of parameter will be the value returned by get_operand_count() method.

Returns:運算結果 / Result of evaluation
get_operand_count()[source]

取得運算元的數量

Get the number of operand

Returns:運算元的數量 / Number of operand(s)
get_priority()[source]

取得運算子的優先順序,愈高的優先順序應傳回愈大的值

Get the priority of operator. Bigger value means higher priority.

Returns:運算子的優先權 / Priority of operator
class ParenthesisL(v=None, *args, **kwds)[source]

表現左括弧的物件 / Class of left parenthesis

class ParenthesisR(v=None, *args, **kwds)[source]

表現右括弧的物件 / Class of right parenthesis

class Plus(v=None, *args, **kwds)[source]
evaluate(a, b, *args)[source]

進行運算,參數數量為 get_operand_count() 方法所傳回的數值

Perform the computation. The number of parameter will be the value returned by get_operand_count() method.

Returns:運算結果 / Result of evaluation
get_operand_count()[source]

取得運算元的數量

Get the number of operand

Returns:運算元的數量 / Number of operand(s)
get_priority()[source]

取得運算子的優先順序,愈高的優先順序應傳回愈大的值

Get the priority of operator. Bigger value means higher priority.

Returns:運算子的優先權 / Priority of operator
class RegexParsePlan(regex_object, element_mapper)
element_mapper

Alias for field number 1

regex_object

Alias for field number 0

evaluate(fm)[source]

計算由 parse_*() 函數所解析出的算式結果

Evaluate the result of parse_*() function.

Parameters:fm – 透過 parse_*() 函數所解析出的算式 / Formula object generated by parse_*() function
Returns:計算結果 / Result of evaluation
parse_literal_math(v)[source]

將給定的數學算式陳述式進行句元分割並轉換為後波蘭表示式

Convert given math formula to reverse polish notation

Parameters:v – 要解析的算式字串 / String to be parse
Returns:轉換為後波蘭表示式的句元所構成的串列 / Resulted token list in reverse polish notation
parse_token_w_regex(v, parse_plan)[source]

將給定的陳述式進行句元分割並轉換為後波蘭表示式

Split given statement into tokens and transform into reverse polish (postfix) notation form

Parameters:
  • v – 要解析的陳述式字串
  • parse_plan – 解析規則 (RegexParsePlan 物件)
Returns:

轉換為後波蘭表示式的句元所構成的串列 / Resulted token list in reverse polish notation