Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Tokenizer and analyzer package supporting precedence prioritized rules

, 1 Jan 2002
A library allowing you to conveniently build a custom tokenizer and analyzer supporting precedence priorized rules
cxtpackagetut_win32vc.zip
cxTokenizer
cxTokenizer.dsp
cxTokenizer.plg
cxtPackage
cxtPackage.plg
cxtPackage.dsp
mathTok
mathTok.plg
mathTok.dsp
simpleCalc
simpleCalc.bmp
simpleCalc.dsp
simpleCalc.plg
tkCommon
cxAnalyzer
cxAnalyzer.dsp
cxAnalyzer.plg
COPYING
cpAbsd.dsw
cxtpackage_win32vc.zip
cxTokenizer.dsp
cxTokenizer.plg
Debug
cxAnalyzer.dsp
cxAnalyzer.plg
cxtPackage.plg
cxtPackage.dsp
COPYING
cpAbsd.dsw
grammaride.zip
stlport_vc645.dll
grammarIDE.exe
pkgcomplete.zip
cxTokenizerMatchTokenRule.inl
cxTokenizer.dsp
cxtPackage.dsp
emptyTestApp
emptyTestApp.clw
res
emptyTestApp.ico
emptyTestApp.dsp
grammarIDE
grammarIDE.clw
res
grammarIDEDoc.ico
icon1.ico
zoomable.ico
Toolbar.bmp
grammarIDE.ico
vssver.scc
grammarIDE.dsp
simpleCalc.bmp
simpleCalc.dsp
vssver.scc
cxaToken.inl
cxAnalyzer.dsp
COPYING
cpAbsd.dsw
pkgsrconly.zip
cxTokenizerMatchTokenRule.inl
cxTokenizer.dsp
cxtPackage.dsp
emptyTestApp.clw
emptyTestApp.ico
emptyTestApp.dsp
vssver.scc
cxaToken.inl
cxAnalyzer.dsp
COPYING
cpAbsd.dsw
/*********************************************************************
	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:      cxAnalyzerException
Author:     Alexander Berthold
Copyright:  Alexander Berthold
Date:       2001/06/12
Version:	0.1.07
Purpose:    This class stores the pattern for a specific expression.
			It can perform a check on a given token pattern if it
			matches the expression (fCheck).

			'fInitFromRule' can be used to initialize the expression.
			The syntax is like this:
			{.RULE}=PRIO:PATTERN

			where 'RULE' stands for the name of the rule. 'PRIO'
			tells the precedence priority, and 'PATTERN' describes
			the pattern, consisting of a sequence of segments embraced
			by '{}' braces.

			{.RULE} -> refers to a rule 'RULE'
			{$TOKEN} -> refers to a token 'TOKEN'
			{!number} -> refers to a computed token (a number in this case)
			{!string} -> refers to a computed token (a string in this case)


Version history:

	-	2001/05/19
		Released the version 0.1.05

	-	2001/06/02
		Added support for cxaStatusCookie status report (fCheck).
		See cxAnalyzerMain.

	-	2001/06/12
		Fixed some problems with cxaStatusCookie.
		New version number is 0.1.07.

    -	2001/12/02
		Added support for on-the-fly resolving literal tokens.
		Found and fixed swapped token bug when creating the parse tree.

	-	2001/12/16
		Improved speed by introducing a rule cache and by minor
		other optimizations. Currently, the rule cache caches only successfully
		parsed sub-expressions. I will extend it to cache also failed sub-expressions,
		because this saves even more time under certain (but probable) circumstances.

	-	2001/12/19
		Labeled version 0.2.01

ToDo:
	-	Optimize the code someday. Is pretty fast already, but	
		'fCheckComp' can be optimized a lot.

*********************************************************************/

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

#if !defined(AFX_CXANALYZEREXPRESSION_H__086331A7_62F3_47CC_B6F3_B7CFEBF4E061__INCLUDED_)
#define AFX_CXANALYZEREXPRESSION_H__086331A7_62F3_47CC_B6F3_B7CFEBF4E061__INCLUDED_

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

// Forward declarations
class	cxAnalyzerMain;
class	cxAnalyzerTree;
class	cxAnalyzerTypeMap;
class	cxAnalyzerTypeInfo;
class	cxaStatusCookie;

class cxAnalyzerExpression  
{
// Construction/Destruction
public:
	cxAnalyzerExpression(cxAnalyzerTypeMap* patmTypeMap);
	virtual ~cxAnalyzerExpression();

// Typedefs
public:
/*#ifndef ANALYZER_NO_OPTIMIZATION
	typedef std::multimap<int, const cxAnalyzerExpression*>
						aeexclude_mmap_type;
#endif*/


// Attributes
protected:
	// Fully initialized?
	bool				m_fInitializeComplete;
	// Treat implicit conversions in-place instead of expanding a sub rule
	bool				m_fImplicitIgnore;
	// Temporary pointer to the string passed to fInitFromRule()
	std::tstring*		m_pstrInitTemp;
	// The TypeMap this expression belongs to
	cxAnalyzerTypeMap	*m_patmTypeMap;
	// The precedence priority of this expression
	int					m_nPrecPrio;
	// The ID in the TypeMap of this expression
	int					m_nAtmType;
	// User-defined ID of this expression
    int                 m_nIDValue;
	// Is this a cacheable expression?
	bool				m_fIsCacheable;

	// The number of 'pttm'-Patterns (see below)
	int					m_nSizePattern;
	// The pattern of this expression
	cxAnalyzerTypeInfo **m_apatiPattern;

// Protected operations
// Operations
public:
	operator cxAnalyzerTypeInfo ** const() const { return m_apatiPattern; };
	const std::string*	pstrGetInitString() const { return m_pstrInitTemp; };

#ifndef ANALYZER_NO_OPTIMIZATION
	/*** Optimization operations ***/
	bool				fIsCacheable() const { return m_fIsCacheable; };
#endif

	/*** Status check operations ***/
	bool				fCheckValid() const;
	bool				fUsesAtm(const cxAnalyzerTypeMap* patm) const
						{ return (m_patmTypeMap==patm); };
	int					nGetAtmType() const { return m_nAtmType; };
	int					nGetIDValue() const { return m_nIDValue; };
	int					nGetPrecPrio() const { return m_nPrecPrio; };
	int					nGetPatternSize() const { return m_nSizePattern; };
	int					nGetEquivFirstAtmType() const
		{	if( m_nSizePattern!=1 ) return ATM_ID_INVALID;
			return m_apatiPattern[0]->nGetAtmType();	};

	bool				fIsLeftBound(int nAtmType) const;
	bool				fIsRightBound(int nAtmType) const;
	bool				fImplicitIgnore() const { return m_fImplicitIgnore; };


	/*** Status initialization and manipulation ***/
	bool				fInitFromRule(std::tstring strRule);
	bool				fFinishInit();


	/*** Analyzer operations ***/
	// Tests if this 'cxAnalyzerExpression' is just a simple
	// mapping rule like expr:=string or something.
	bool				fIsImplicitExpressionToAtm(int* pnAtmType) const;

	// Check if the expression matches the criteria
	bool				fCheckComp( cxAnalyzerMain* paHost,
									const cxaTokenStream* patsContext,
									int nAtmTypeFirstIs, /* ATM_ID_INVALID? */
                                    const cxaToken* patFirstToken,
									cxaStatusCookie* pascCondition,
									cxaTokenStream::const_iterator start,
									cxaTokenStream::const_iterator *pend,
									cxAnalyzerTree* patTree = NULL);

};

#endif // !defined(AFX_CXANALYZEREXPRESSION_H__086331A7_62F3_47CC_B6F3_B7CFEBF4E061__INCLUDED_)

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

Share

About the Author

Alexander Berthold
Web Developer
Germany Germany
No Biography provided

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 2 Jan 2002
Article Copyright 2001 by Alexander Berthold
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid