/*********************************************************************
Copyright (C) 2001/2 by
Alexander Berthold, alexander-berthold@web.de.
Hoegestr. 54
79108 Freiburg i. Breisgau
Germany
-- This file is part of cxAnalyzer --
"cxAnalyzer" is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or any later version.
"cxAnalyzer" is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with "cxAnalyzer"; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
---------------------------------------------------------------
If you find any bugs or if you make other corrections/
enhancements, i'd appreciate if you'd let me know about
that. My email is
alexander-berthold@web.de
If you share this code, do not remove this text.
---------------------------------------------------------------
Class: cxaToken / cxaTokenStream / cxaParseElement /
cxaParseNode / cxaParseBranch
Author: Alexander Berthold
Copyright: Alexander Berthold
Date: 2001/12/19
Version: 0.2.01
Purpose: - cxaToken:
Contains data for a token
- cxaTokenStream:
Implements cxTokenizerListener. Accepts the output token stream
from the tokenizer and builds a list from the tokens.
- cxaParseElement / cxaParseNode / cxaParseBranch
Derived from the appropriate ctkHLinkedListXXX classes.
Build the parse tree.
Version history:
- 2001/12/15
Created
*********************************************************************/
// cxaToken.inl: interface for the cxaToken class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_CXATOKEN_INL__0CD5BF48_9045_4916_B780_68258BC9D524__INCLUDED_)
#define AFX_CXATOKEN_INL__0CD5BF48_9045_4916_B780_68258BC9D524__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
inline void cxaParseBranch::enumerate(ctkSortedEnumerator<LPCTSTR>& enumerator, int nNestLevel, int *pnCounter) const
{
sit_data_t sit;
bool fContinue = true;
std::tstring str0,str00;
TCHAR szTemp[257];
szTemp[256] ='\0';
for(int i=0;i<nNestLevel-1;i++) str0+='|',str0+=' ',str00+='|',str00+=' ';
if(nNestLevel!=0) str00+='+', str00+='-',str0+='|', str0+=' ';
if(pnCounter==NULL) pnCounter = (int*)_alloca(sizeof(*pnCounter));
vEnumBegin(&sit);
_sntprintf(szTemp,256,_T("%s[ Rule: AtmID#=%d, IDValue=%d, Prio=%d"), str00.c_str(), nAtmType, nIDValue, nPrecPrio );
enumerator.enumElement( (*pnCounter)++, szTemp );
while(fContinue)
{
const cxaParseElement* papeCur = papeEnumGetAt(&sit);
std::tstringstream strmLine;
if(papeCur->fIsBranch())
{
if(nNestLevel==-1)
{
const cxaParseBranch *papbCur = papeCur->papbElem();
_sntprintf(szTemp,256,_T("%s> Rule: AtmID#=%d, IDValue=%d, Prio=%d"),str0.c_str(),papbCur->nAtmType,papbCur->nIDValue,papbCur->nPrecPrio);
enumerator.enumElement( (*pnCounter)++, szTemp );
}
else
{
const cxaParseBranch *papbCur = papeCur->papbElem();
papbCur->enumerate(enumerator,nNestLevel+1,pnCounter);
}
}
else
{
const cxaParseNode *papnCur = papeCur->papnElem();
const cxaToken *patToken = papnCur->patGetToken();
if(patToken!=NULL)
{
_sntprintf(szTemp,256,_T("%s| Token: AtmID#=%d, IDValue=%d, Text='%s'"),
str0.c_str(), patToken->nAtmType, patToken->nIDValue,
patToken->lpszTokenText!=NULL?patToken->lpszTokenText:"<N/A>");
}
else
_tcscpy(szTemp,"<<NULL TOKEN>>");
enumerator.enumElement( (*pnCounter)++, szTemp );
}
fContinue =fEnumNext(&sit);
}
vEnumEnd(&sit);
_sntprintf(szTemp,256,_T("%s] ENDS."),str00.c_str());
enumerator.enumElement( (*pnCounter)++, szTemp);
};
inline void cxaParseBranch::enumerateRaw(ctkSortedEnumerator<LPCTSTR>& enumerator, int nNestLevel, int *pnCounter) const
{
const_iterator it;
std::tstring str0,str00;
TCHAR szTemp[257];
szTemp[256] ='\0';
for(int i=0;i<nNestLevel-1;i++) str0+='|',str0+=' ',str00+='|',str00+=' ';
if(nNestLevel!=0) str00+='+', str00+='-',str0+='|', str0+=' ';
if(pnCounter==NULL) pnCounter = (int*)_alloca(sizeof(*pnCounter));
_sntprintf(szTemp,256,_T("%s[ Rule: AtmID#=%d, IDValue=%d, Prio=%d"), str00.c_str(), nAtmType, nIDValue, nPrecPrio);
enumerator.enumBegin();
enumerator.enumElement( (*pnCounter)++, szTemp );
for(it=begin();it!=end();it++)
{
const cxaParseElement* papeCur = (*it);
std::tstringstream strmLine;
if(papeCur->fIsBranch())
{
if(nNestLevel==-1)
{
const cxaParseBranch *papbCur = papeCur->papbElem();
_sntprintf(szTemp,256,_T("%s> Rule: AtmID#=%d, IDValue=%d"),str0.c_str(),papbCur->nAtmType,papbCur->nIDValue);
enumerator.enumElement( (*pnCounter)++, szTemp );
}
else
{
const cxaParseBranch *papbCur = papeCur->papbElem();
papbCur->enumerateRaw(enumerator,nNestLevel+1,pnCounter);
}
}
else
{
const cxaParseNode *papnCur = papeCur->papnElem();
const cxaToken *patToken = papnCur->patGetToken();
if(patToken==NULL)
_sntprintf(szTemp,256,_T("%s| NULL Token"), str0.c_str() );
else
_sntprintf(szTemp,256,_T("%s| Token: AtmID#=%d, IDValue=%d, Text='%s'"),
str0.c_str(), patToken->nAtmType, patToken->nIDValue,
patToken->lpszTokenText!=NULL?patToken->lpszTokenText:"<N/A>");
enumerator.enumElement( (*pnCounter)++, szTemp );
}
}
_sntprintf(szTemp,256,_T("%s] ENDS."),str00.c_str());
enumerator.enumElement( (*pnCounter)++, szTemp);
enumerator.enumEnd();
};
#endif // !defined(AFX_CXATOKEN_INL__0CD5BF48_9045_4916_B780_68258BC9D524__INCLUDED_)