65.9K
CodeProject is changing. Read more.
Home

ALXParser - a single expression dBase parser

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.71/5 (16 votes)

Sep 3, 2002

viewsIcon

61991

downloadIcon

957

A dBASE syntax parser of one expression. Functions and variables are supported.

Example of use parser

Introduction

This is a dBASE language parser with support of functions, variables, evaluation and processing of mistakes. The parser was was written by me and is contained in the CALXParser class. 

The process of calculation is broken on two stages: 

  1. syntactic analysis and filling of structures necessary for calculation, 
  2. execution of the prepared script. 

It has allowed a reduction in execution time when using the parser in the big cycles.

Base methods

These methods are necessary to get the results of analysis of expression.

void Parse(LPCSTR lpszExpression);
VARIANT* Execute();

Methods for work with variables

These methods are intended for definition of variables or change of values.

BOOL AddVariable(LPCSTR szName, VARIANT& varValue);
BOOL DelVariable(LPCSTR szName);
void DelUnusedVariables(LPCSTR szName);

BOOL SetVariableValue(LPCSTR szName, VARIANT& varValue);
BOOL SetVariableValue(VARIANT& varValue);
BOOL GetVariableValue(LPCSTR szName, VARIANT& varValue);
BOOL GetVariableValue(VARIANT& varValue);

LPCSTR GetFirstVariableName();
LPCSTR GetNextVariableName();	

Example

Example of use.

// pointer on result
VARIANT* pvarResult = NULL;

try
{
	// prepare script
	m_Parser.Parse(strExpression);
	// execute script
	pvarResult = m_Parser.Execute();
}
catch(CALXParserException* e)
{
	// processing of errors
	for(int i = 0; i < e->GetErrorCount(); i++)
	{
		e->GetErrorInfo(i);
		e->ReportError();
	}
	e->Delete();
	return;
}

// work with result
// ...