⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stdinterpreter.h

📁 Standard Grammar Toolkit
💻 H
字号:
/*=========================================================
StdInterpreter.h
Copyright (C) 2001, ClearJump, All Rights Reserved

=========================================================*/

#ifndef __StdInterpreter_h
#define __StdInterpreter_h

#include "Interpreter.h"
#include "stdgram.h"

//DEFINES
//=======


//DATA TYPES AND FUNCTIONS
//========================
//---------------------------------------------------------
//	InterpreterError
//  StdInterpreter generates InterpreterError objects
//  and calls error_notify() when an error occurs.
//---------------------------------------------------------
class InterpreterError
{
public:
	enum ErrorCode
	{
		E_BADTREE,  //invalid parsing tree structure
		E_NUMBER_TOOLONG,  //number is too long and cannot be converted
		E_PARSER_ERROR  //m_cperr has the error code
	};

public:
//attributes
	ErrorCode m_code;
	HPTNODE   m_node;
	CPERR     m_cperr;

//methods
	inline InterpreterError( HPTNODE node, CPERR err )
	{
		m_code = E_PARSER_ERROR;
		m_node = node;
		m_cperr = err;
	}
	inline InterpreterError( HPTNODE node, ErrorCode code )
	{
		m_code = code;
		m_node = node;
		m_cperr = 0;
	}
};


//---------------------------------------------------------
//	StdInterpreter
//  extracts simple elements such as strings and numbers
//  from the parsing tree.  The grammar is defined in 
//  stdgram.gdm
//---------------------------------------------------------
class StdInterpreter : public Interpreter
{
public:
//attributes

//methods
	StdInterpreter();
	virtual ~StdInterpreter();

	//'node' is of nid_String type
	//this method appends the new string to 'str',
	//it returns FALSE if there is an error
	BOOL process_string( HPTNODE node, string& str );
	//nid_Integer
	BOOL process_integer( HPTNODE node, UINT& num );
	//nid_HexInteger
	BOOL process_hexint( HPTNODE node, UINT& num );
	//nid_DecInteger
	BOOL process_decint( HPTNODE node, UINT& num );
	//nid_SignedInteger
	BOOL process_signed_integer( HPTNODE node, INT& num );
	//nid_FloatNumber
	BOOL process_float( HPTNODE node, double& num );
	//nid_Number
	BOOL process_number( HPTNODE node, double& num );
	//nid_Symbol
	BOOL process_symbol( HPTNODE node, CPCHAR& sym );
	//nid_Identifer
	BOOL process_identifier( HPTNODE node, CPCSTR *pid );

	//overload this function to process error messages
	//from the interpreter
	virtual void error_notify( InterpreterError& err );

protected:
//attributes

//methods
	//nid_EscCode
	BOOL process_esccode( HPTNODE node, string& code );
	//nid_NumberSign
	BOOL process_number_sign( HPTNODE node, BOOL& minus );
	//nid_FloatIntNumber & nid_Number
	BOOL reconstruct_number( HPTNODE node, string& numstr );

	//nid_DecInteger
	BOOL append_decint( HPTNODE node, string& numstr );

	CPCSTR get_child_identifier( HPTNODE node );

	//get matching string for the terminal node
	CPCSTR get_match( const SPtnInfo& info );

	inline BOOL error( HPTNODE node, CPERR err )
	{
		error_notify( InterpreterError(node, err) );
		return FALSE;
	}

	inline BOOL error( HPTNODE node, InterpreterError::ErrorCode code )
	{
		error_notify( InterpreterError(node, code) );
		return FALSE;
	}

private:
//attributes

//methods
};


#endif //__StdInterpreter_h

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -