File indexing completed on 2024-04-28 03:40:38
0001 /************************************************************************************* 0002 * Copyright (C) 2008 by Aleix Pol <aleixpol@kde.org> * 0003 * * 0004 * This program is free software; you can redistribute it and/or * 0005 * modify it under the terms of the GNU General Public License * 0006 * as published by the Free Software Foundation; either version 2 * 0007 * of the License, or (at your option) any later version. * 0008 * * 0009 * This program is distributed in the hope that it will be useful, * 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0012 * GNU General Public License for more details. * 0013 * * 0014 * You should have received a copy of the GNU General Public License * 0015 * along with this program; if not, write to the Free Software * 0016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA * 0017 *************************************************************************************/ 0018 0019 #ifndef ABSTRACTLEXER_H 0020 #define ABSTRACTLEXER_H 0021 0022 #include <QString> 0023 #include <QStringList> 0024 #include <QHash> 0025 #include <QQueue> 0026 #include "analitzaexport.h" 0027 0028 class ANALITZA_EXPORT AbstractLexer 0029 { 0030 public: 0031 struct TOKEN 0032 { 0033 TOKEN(int _type=-1, uint _pos=0, const QString& _val=QString(), unsigned char _len=0) : 0034 type(_type), val(_val), len(_len), pos(_pos) {} 0035 0036 int type; 0037 QString val; 0038 unsigned char len; 0039 uint pos; 0040 }; 0041 0042 explicit AbstractLexer(const QString &source); 0043 virtual ~AbstractLexer(); 0044 int lex(); 0045 int lineNumber() const { return m_lines; } 0046 bool isCompletelyRead() const { return m_openPr==0 && m_openCb==0; } 0047 0048 TOKEN current; 0049 QString error() const { return m_err; } 0050 bool isCompleteExpression(bool justempty=false); 0051 0052 protected: 0053 QString m_err; 0054 QString m_source; 0055 0056 int m_lines; 0057 int m_openPr, m_openCb; 0058 QQueue<TOKEN> m_tokens; 0059 static QHash<QChar, int> m_operators; 0060 static QHash<QString, int> m_longOperators; 0061 virtual void getToken()=0; 0062 void printQueue(const QQueue<TOKEN>& q) const; 0063 }; 0064 0065 #endif