H++ Lexer header in C/C++   Leave a comment

// HCCLexer.h: interface for the HCCLexer class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_HCCLEXER_H__E9AAE4C9_7B3B_4680_9FD9_061BB1B054F1__INCLUDED_)
#define AFX_HCCLEXER_H__E9AAE4C9_7B3B_4680_9FD9_061BB1B054F1__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/*
********************************************************************************************************
*																									   *
*																									   *
*	MODULE			: <hcclexer.h>																   *	
*																									   *
*	DESCRIPTION		: HCC Compiler Lexer class (token retrieval and lexical analysis for HC)		   *
*																									   *
*	AUTHOR			: Harold L. Marzan																   *	
*																									   *
*	LAST-MODIFIED	: (unknown)																		   *	
*																									   *
********************************************************************************************************
*/

#include "HCCLib\errors.h"
#include "HCCLib\corecommon.h"
#include "HCCLib\corelisting.h"

class HCCLexer  
{
	source_buffer * const source_ptr;
public:
 	HCCLexer(source_buffer* _source_ptr);		
	virtual ~HCCLexer() {}

	class NumberLexer
	{
		static __int64 maxInteger;
		static int maxExponent;		
		int digitCount;
		bool bTooManyDigitsFlag;
		bool bIsHexNumber;
		TCHAR* in_ptr;
		bool acumulateValue(source_buffer* source_ptr, double& value, HccErrorManager::HccError err);
	public:
		NumberLexer() : bTooManyDigitsFlag(false), digitCount(0), in_ptr(0) {}
		~NumberLexer(){}

		LPHCC_TOKEN getNumberToken(source_buffer* source_ptr);

		class HexNumberLexer
		{		
			unsigned char BinaryToHex(char ch)
			{
				if ( ch >= '0' && ch = 'A' && ch = 'a' && ch  0)
				{
					char AH = BinaryToHex(*szSource++);
					char AL = 0;
					count--;
					if(AH==-1)
					{
						HccErrorManager::Error(HccErrorManager::errInvalidHexNumber, info);
					}	
					nByte = AH;
					if(count > 0)
					{
						nByte = (AH < 0)
						{
							if(count > 1)
							{
								*pi64Dest = *pi64Dest << 8;
							}else{
								*pi64Dest = *pi64Dest <begin();
		source_buffer::iterator& _L = source_ptr->end();
SKIP_WS_AND_COMMENTS:
		while(_F!=_L && _istspace(*_F))
			_F++;
		/* 
			Also skip this type of C++ comment style
		*//*		another comment in test		*/
		if(_F!=_L)
			if(*_F==_T('/')){
				_F++;//skip it
				if(_F!=_L)
				{					
					if(*_F==_T('*')){
						TCHAR prev = _T('');
						_F++;
						while(_F!=_L){							
							if(prev==_T('*') && *_F==_T('/'))
								break;
							prev = *_F++;
						}
						if(_F!=_L)
						{
							if(*_F==_T('/')){
								_F++;
								goto SKIP_WS_AND_COMMENTS;
							}

						}else{
							//Unexpected EOF
							HccErrorManager::Error(HccErrorManager::errUnexpectedEndOfFile);
						}
					}else if(*_F==_T('/')){ //an inline comment
							_F++;
							while(_F!=_L && *_F!=_T('\n'))
								_F++;
							goto SKIP_WS_AND_COMMENTS;
					}else
						_F--;

				}else{
					//Unexpected EOF
					HccErrorManager::Error(HccErrorManager::errUnexpectedEndOfFile);
				}
			}		
	}
public:
	bool m_bSilentEscapedString;
};

#endif // !defined(AFX_HCCLEXER_H__E9AAE4C9_7B3B_4680_9FD9_061BB1B054F1__INCLUDED_)
Advertisements

Posted February 2, 2013 by hmarzan

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: