kformula

fsparser.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #ifndef FSPARSER_H
00021 #define FSPARSER_H
00022 
00023 #include <qstring.h>
00024 #include <qstringlist.h>
00025 #include <qdom.h>
00026 
00027 namespace KFormula { class SymbolTable; }
00028 class ParserNode;
00029 
00033 class FormulaStringParser {
00034 public:
00035     FormulaStringParser( const KFormula::SymbolTable& symbolTable, QString formula );
00036     ~FormulaStringParser();
00037 
00038     QDomDocument parse();
00039 
00040     QStringList errorList() const { return m_errorList; }
00041 
00042 private:
00043 
00044     enum TokenType { NUMBER, NAME, PLUS, SUB, MUL, DIV, POW, INDEX, LP, RP, LB, RB,
00045                      ASSIGN, COMMA, SEMIC, NEWLINE, OTHER, EOL };
00046 
00047     ParserNode* parseAssign();
00048     ParserNode* parseExpr();
00049     ParserNode* parseTerm();
00050     ParserNode* parsePower();
00051     ParserNode* parsePrimary();
00052     void expect( TokenType type, QString msg );
00053 
00054     QString nextToken();
00055     bool eol() { return m_formula.length() == pos; }
00056 
00057     void readNumber();
00058     void readDigits();
00059 
00060     void error( QString err );
00061     QStringList m_errorList;
00062 
00063     const KFormula::SymbolTable& m_symbolTable;
00064     QString m_formula;
00065     uint pos;
00066     uint line;
00067     uint column;
00068     bool m_newlineIsSpace;
00069 
00070     TokenType currentType;
00071     QString current;
00072 
00073     ParserNode* head;
00074 };
00075 
00076 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys