NCBI C++ ToolKit
Public Types | Public Member Functions | Private Types | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
CExprParser Class Reference

Search Toolkit Book for CExprParser

#include <corelib/expr.hpp>

+ Collaboration diagram for CExprParser:

Public Types

enum  EAutoVar {
  fAllowAutoVar = 0 , fDenyAutoVar = (1 << 0) , fLogicalOnly = (1 << 1) , eAllowAutoVar = fAllowAutoVar ,
  eDenyAutoVar = fDenyAutoVar
}
 Parser flags. More...
 
typedef int TParserFlags
 

Public Member Functions

 CExprParser (TParserFlags auto_var=0)
 
 ~CExprParser (void)
 
void Parse (const char *str)
 
const CExprValueGetResult (void) const
 
template<typename VT >
CExprSymbolAddSymbol (const char *name, VT value)
 

Private Types

enum  EOperator {
  eBEGIN , eOPERAND , eERROR , eEND ,
  eLPAR , eRPAR , eFUNC , ePOSTINC ,
  ePOSTDEC , ePREINC , ePREDEC , ePLUS ,
  eMINUS , eNOT , eCOM , ePOW ,
  eMUL , eDIV , eMOD , eADD ,
  eSUB , eASL , eASR , eLSR ,
  eGT , eGE , eLT , eLE ,
  eEQ , eNE , eAND , eXOR ,
  eOR , eSET , eSETADD , eSETSUB ,
  eSETMUL , eSETDIV , eSETMOD , eSETASL ,
  eSETASR , eSETLSR , eSETAND , eSETXOR ,
  eSETOR , eSETPOW , eCOMMA , eTERMINALS
}
 
enum  { hash_table_size = 1013 }
 
enum  { max_stack_size = 256 }
 
enum  { max_expression_length = 1024 }
 

Private Member Functions

EOperator Scan (bool operand)
 
bool Assign (void)
 
CExprSymbolGetSymbol (const char *name) const
 
void ReportError (const string &msg) const
 
EOperator IfChar (char c, EOperator val, EOperator val_def)
 
EOperator IfElseChar (char c1, EOperator val1, char c2, EOperator val2, EOperator val_def)
 
EOperator IfLongest2ElseChar (char c1, char c2, EOperator val_true_longest, EOperator val_true, EOperator val_false, EOperator val_def)
 
TParserFlags AutoCreateVariable (void) const
 
bool LogicalOnly (void) const
 

Static Private Member Functions

static void ReportError (int pos, const string &msg)
 

Private Attributes

CExprSymbolhash_table [hash_table_size]
 
CExprValue m_VStack [max_stack_size]
 
int m_v_sp
 
EOperator m_OStack [max_stack_size]
 
int m_o_sp
 
const char * m_Buf
 
int m_Pos
 
TParserFlags m_ParserFlags
 

Static Private Attributes

static int sm_lpr [eTERMINALS]
 
static int sm_rpr [eTERMINALS]
 

Detailed Description

Definition at line 267 of file expr.hpp.

Member Typedef Documentation

◆ TParserFlags

Definition at line 281 of file expr.hpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
private
Enumerator
hash_table_size 

Definition at line 354 of file expr.hpp.

◆ anonymous enum

anonymous enum
private
Enumerator
max_stack_size 

Definition at line 357 of file expr.hpp.

◆ anonymous enum

anonymous enum
private
Enumerator
max_expression_length 

Definition at line 358 of file expr.hpp.

◆ EAutoVar

Parser flags.

Enumerator
fAllowAutoVar 
fDenyAutoVar 
fLogicalOnly 
eAllowAutoVar 
eDenyAutoVar 

Definition at line 271 of file expr.hpp.

◆ EOperator

enum CExprParser::EOperator
private
Enumerator
eBEGIN 
eOPERAND 
eERROR 
eEND 
eLPAR 
eRPAR 
eFUNC 
ePOSTINC 
ePOSTDEC 
ePREINC 
ePREDEC 
ePLUS 
eMINUS 
eNOT 
eCOM 
ePOW 
eMUL 
eDIV 
eMOD 
eADD 
eSUB 
eASL 
eASR 
eLSR 
eGT 
eGE 
eLT 
eLE 
eEQ 
eNE 
eAND 
eXOR 
eOR 
eSET 
eSETADD 
eSETSUB 
eSETMUL 
eSETDIV 
eSETMOD 
eSETASL 
eSETASR 
eSETLSR 
eSETAND 
eSETXOR 
eSETOR 
eSETPOW 
eCOMMA 
eTERMINALS 

Definition at line 302 of file expr.hpp.

Constructor & Destructor Documentation

◆ CExprParser()

CExprParser::CExprParser ( CExprParser::TParserFlags  ParserFlags = 0)

Definition at line 416 of file expr.cpp.

References AddSymbol(), fabs, gcd(), hash_table, invmod(), log, log10(), prime(), to_float(), and to_int().

◆ ~CExprParser()

CExprParser::~CExprParser ( void  )

Definition at line 451 of file expr.cpp.

References hash_table, hash_table_size, and i.

Member Function Documentation

◆ AddSymbol()

template<typename VT >
CExprSymbol * CExprParser::AddSymbol ( const char *  name,
VT  value 
)
inline

◆ Assign()

bool CExprParser::Assign ( void  )
private

Definition at line 726 of file expr.cpp.

References CExprValue::m_Pos, m_v_sp, CExprSymbol::m_Val, CExprValue::m_Var, m_VStack, NULL, and ReportError().

Referenced by Parse().

◆ AutoCreateVariable()

TParserFlags CExprParser::AutoCreateVariable ( void  ) const
inlineprivate

Definition at line 346 of file expr.hpp.

References fDenyAutoVar, and m_ParserFlags.

Referenced by Scan().

◆ GetResult()

const CExprValue& CExprParser::GetResult ( void  ) const
inline

◆ GetSymbol()

CExprSymbol * CExprParser::GetSymbol ( const char *  name) const
private

Definition at line 496 of file expr.cpp.

References hash_table, hash_table_size, CExprSymbol::m_Name, CExprSymbol::m_Next, NULL, and string_hash_function().

Referenced by AddSymbol(), and Scan().

◆ IfChar()

CExprParser::EOperator CExprParser::IfChar ( char  c,
EOperator  val,
EOperator  val_def 
)
inlineprivate

Definition at line 400 of file expr.hpp.

References m_Buf, m_Pos, and val.

Referenced by IfLongest2ElseChar(), and Scan().

◆ IfElseChar()

CExprParser::EOperator CExprParser::IfElseChar ( char  c1,
EOperator  val1,
char  c2,
EOperator  val2,
EOperator  val_def 
)
inlineprivate

Definition at line 414 of file expr.hpp.

References m_Buf, and m_Pos.

Referenced by Scan().

◆ IfLongest2ElseChar()

CExprParser::EOperator CExprParser::IfLongest2ElseChar ( char  c1,
char  c2,
EOperator  val_true_longest,
EOperator  val_true,
EOperator  val_false,
EOperator  val_def 
)
inlineprivate

Definition at line 432 of file expr.hpp.

References IfChar(), m_Buf, and m_Pos.

Referenced by Scan().

◆ LogicalOnly()

bool CExprParser::LogicalOnly ( void  ) const
inlineprivate

Definition at line 351 of file expr.hpp.

References fLogicalOnly, and m_ParserFlags.

Referenced by Scan().

◆ Parse()

void CExprParser::Parse ( const char *  str)

◆ ReportError() [1/2]

void CExprParser::ReportError ( const string msg) const
inlineprivate

Definition at line 330 of file expr.hpp.

References m_Pos, and ReportError().

Referenced by ReportError().

◆ ReportError() [2/2]

static void CExprParser::ReportError ( int  pos,
const string msg 
)
inlinestaticprivate

Definition at line 326 of file expr.hpp.

References NCBI_THROW2.

Referenced by Assign(), GetResult(), Parse(), and Scan().

◆ Scan()

CExprParser::EOperator CExprParser::Scan ( bool  operand)
private

Member Data Documentation

◆ hash_table

CExprSymbol* CExprParser::hash_table[hash_table_size]
private

Definition at line 355 of file expr.hpp.

Referenced by AddSymbol(), CExprParser(), GetSymbol(), and ~CExprParser().

◆ m_Buf

const char* CExprParser::m_Buf
private

Definition at line 367 of file expr.hpp.

Referenced by IfChar(), IfElseChar(), IfLongest2ElseChar(), Parse(), and Scan().

◆ m_o_sp

int CExprParser::m_o_sp
private

Definition at line 366 of file expr.hpp.

Referenced by Parse().

◆ m_OStack

EOperator CExprParser::m_OStack[max_stack_size]
private

Definition at line 365 of file expr.hpp.

Referenced by Parse().

◆ m_ParserFlags

TParserFlags CExprParser::m_ParserFlags
private

Definition at line 369 of file expr.hpp.

Referenced by AutoCreateVariable(), and LogicalOnly().

◆ m_Pos

int CExprParser::m_Pos
private

Definition at line 368 of file expr.hpp.

Referenced by IfChar(), IfElseChar(), IfLongest2ElseChar(), Parse(), ReportError(), and Scan().

◆ m_v_sp

int CExprParser::m_v_sp
private

Definition at line 364 of file expr.hpp.

Referenced by Assign(), GetResult(), Parse(), and Scan().

◆ m_VStack

CExprValue CExprParser::m_VStack[max_stack_size]
private

Definition at line 363 of file expr.hpp.

Referenced by Assign(), GetResult(), Parse(), and Scan().

◆ sm_lpr

int CExprParser::sm_lpr
staticprivate
Initial value:
= {
2, 0, 0, 0,
4, 4,
5, 98, 98,
98, 98, 98, 98, 98, 98,
90,
80, 80, 80,
70, 70,
60, 60, 60,
50, 50, 50, 50,
40, 40,
38,
36,
34,
20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20,
10
}

Definition at line 360 of file expr.hpp.

Referenced by Parse().

◆ sm_rpr

int CExprParser::sm_rpr
staticprivate
Initial value:
= {
0, 0, 0, 1,
110, 3,
120, 99, 99,
99, 99, 99, 99, 99, 99,
95,
80, 80, 80,
70, 70,
60, 60, 60,
50, 50, 50, 50,
40, 40,
38,
36,
34,
25, 25, 25, 25, 25, 25, 25,
25, 25, 25, 25, 25, 25,
15
}

Definition at line 361 of file expr.hpp.

Referenced by Parse().


The documentation for this class was generated from the following files:
Modified on Tue May 21 11:00:00 2024 by modify_doxy.py rev. 669887