2 // Author: Alexander SOLOVYOV
4 #ifndef __QTX_PARSER_HEADER__
5 #define __QTX_PARSER_HEADER__
8 #include <qvaluestack.h>
12 #pragma warning( disable:4251 )
18 typedef QVariant QtxValue;
21 //================================================================
24 //================================================================
25 class QTX_EXPORT QtxParser
30 OK, OperandsNotMatch, InvalidResult, InvalidOperation,
31 OperationsNull, InvalidToken, CloseExpected, ExcessClose,
32 BracketsNotMatch, StackUnderflow, ExcessData
37 QtxParser( QtxOperations*, const QString& = QString::null );
41 QtxValue calculate( const QString& );
42 bool setExpr( const QString& );
45 virtual bool has ( const QString& name ) const;
46 virtual void set ( const QString& name, const QtxValue& value );
47 virtual bool remove( const QString& name );
48 virtual QtxValue value ( const QString& name ) const;
50 bool firstInvalid( QString& ) const;
51 void removeInvalids();
53 Error lastError() const;
54 void paramsList( QStringList& );
56 static QString toString( const QValueList< QtxValue >& );
59 typedef enum { Value, Param, Open, Close, Pre, Post, Binary } PostfixItemType;
64 PostfixItemType myType;
68 typedef QValueList< PostfixItem > Postfix;
69 typedef Postfix::const_iterator PostfixIterator;
72 QString dump( const Postfix& ) const;
73 virtual bool prepare( const QString&, Postfix& );
74 virtual bool setOperationTypes( Postfix& );
75 virtual bool sort( const Postfix&, Postfix&,
76 const QStringList&, const QStringList&,
79 virtual bool parse( const QString& );
80 virtual void setLastError( const Error );
82 bool calculate( const QString&, QtxValue&, QtxValue& );
84 static int search ( const QStringList&, const QString&, int offset,
85 int& matchLen, int& listind );
86 static QString note ( const QString& str, int pos, int len );
87 static int globalBrackets( const Postfix&, int, int );
90 typedef QValueStack < QtxValue > QtxValueStack;
93 QtxOperations* myOperations;
94 QMap< QString, QtxValue > myParameters;