Click here to Skip to main content
15,886,919 members
Articles / Programming Languages / C++

Tokenizer and analyzer package supporting precedence prioritized rules

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
1 Jan 20023 min read 181.7K   2.8K   54  
A library allowing you to conveniently build a custom tokenizer and analyzer supporting precedence priorized rules
// DlgProperties.cpp : implementation file
//

#include "stdafx.h"
#include "grammaride.h"
#include "DlgProperties.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDlgProperties dialog


CDlgProperties::CDlgProperties(cxtPackage *pPkg, const cxaParseElement *papeElem, CWnd* pParent /*=NULL*/)
: CDialog(CDlgProperties::IDD, pParent)
	{
	//{{AFX_DATA_INIT(CDlgProperties)
	m_strProperties = _T("");
	//}}AFX_DATA_INIT
	
	if(papeElem->fIsNode())
		{
		m_strCaption = "cxaParseNode Properties";
		m_strProperties.Format(
			"ID-Value:\t\t%d\r\n"
			"AtmType:\t\t%d\r\n"
			"Text:\t\t%s\r\n",
			papeElem->nGetIDValue(),
			papeElem->nGetAtmType(),
			(papeElem->lpszGetElemText()!=NULL)?papeElem->lpszGetElemText():"NULL");
		}
	else
		{
		m_strCaption = "cxaParseBranch Properties";
		const cxAnalyzerMain::ae_vec_type& aevec = pPkg->pamGetParser()->paevecGetExpressionsVector();
		cxAnalyzerMain::ae_vec_type::const_iterator it;
		const std::tstring *pstr = NULL;
		
		for(it=aevec.begin();it!=aevec.end();it++)
			{
			if( (*it)->nGetIDValue()==papeElem->nGetIDValue())
				pstr = (*it)->pstrGetInitString();
			}
		
		m_strProperties.Format(
			"ID-Value:\t\t%d\r\n"
			"AtmType:\t\t%d\r\n"
			"Prec.Prio:\t\t%d\r\n"
			"Init:\t\t%s\r\n",
			papeElem->nGetIDValue(),
			papeElem->nGetAtmType(),
			papeElem->papbElem()->nGetPrecPrio(),
			(pstr!=NULL)?pstr->c_str():"NULL");
		}
	}

CDlgProperties::CDlgProperties(cxtPackage *pPkg, int nAtmType, CWnd* pParent /*=NULL*/)
: CDialog(CDlgProperties::IDD, pParent)
	{
	//{{AFX_DATA_INIT(CDlgProperties)
	m_strProperties = _T("");
	//}}AFX_DATA_INIT
	
	m_strCaption = "Analyzer Expression Class Properties";
	const cxAnalyzerTypeInfo *pInfo = pPkg->patmGetAnalyzerMap()->patiGetTypeInfo(nAtmType);

	if(pInfo!=NULL)
		{
		LPCTSTR lpszMType = "NULL";
		LPCTSTR lpszSubType = "NULL";
		if(pInfo->nGetMType()==ATM_MTYPE_TOKEN)
			lpszMType="ATM_MTYPE_TOKEN";
		if(pInfo->nGetMType()==ATM_MTYPE_COMP_TOKEN)
			lpszMType="ATM_MTYPE_COMP_TOKEN";
		if(pInfo->nGetMType()==ATM_MTYPE_RULE)
			lpszMType="ATM_MTYPE_RULE";

		if(pInfo->nGetSubType()==ATM_SUBT_RULE_UNDEF)
			lpszSubType="ATM_SUBT_RULE_UNDEF";
		if(pInfo->nGetSubType()==ATM_SUBT_RULE_FINITE)
			lpszSubType="ATM_SUBT_RULE_FINITE";
		if(pInfo->nGetSubType()==ATM_SUBT_RULE_OPEN)
			lpszSubType="ATM_SUBT_RULE_OPEN";
		
		m_strProperties.Format(
			"nAtmType:\t%d\r\n"
			"MType:\t\t%s\r\n"
			"SubType:\t\t%s\r\n",
			pInfo->nGetAtmType(),
			lpszMType,
			lpszSubType);
		}
	else
		m_strProperties = "<NULL>";
	}

CDlgProperties::CDlgProperties(cxtPackage *pPkg, const cxaTokenStream* patsTokens, CWnd* pParent /*=NULL*/)
: CDialog(CDlgProperties::IDD, pParent)
	{
	//{{AFX_DATA_INIT(CDlgProperties)
	m_strProperties = _T("");
	//}}AFX_DATA_INIT
	
	m_strCaption = "Raw token stream";
	
	cxaTokenStream::const_iterator it;
	for(it=patsTokens->begin(); it!=patsTokens->end(); it++)
		{
		CString strTemp;
		strTemp.Format("AtmType:%3d, IDValue:%5d, TOID:%4d, Text: [%s]\r\n",
			(*it).nAtmType, (*it).nIDValue, (*it).nToid,
			((*it).lpszTokenText==NULL)?"<<NULL>>":(*it).lpszTokenText);
		m_strProperties += strTemp;
		}
	}

void CDlgProperties::DoDataExchange(CDataExchange* pDX)
	{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgProperties)
	DDX_Text(pDX, IDC_PROPERTIES, m_strProperties);
	//}}AFX_DATA_MAP
	}


BEGIN_MESSAGE_MAP(CDlgProperties, CDialog)
//{{AFX_MSG_MAP(CDlgProperties)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgProperties message handlers

BOOL CDlgProperties::OnInitDialog() 
	{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	SetWindowText(m_strCaption);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
	}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions