/*********************************************************************
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_)