kformula

fsparser.h
1/* This file is part of the KDE project
2 Copyright (C) 2002 Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef FSPARSER_H
21#define FSPARSER_H
22
23#include <tqstring.h>
24#include <tqstringlist.h>
25#include <tqdom.h>
26
27namespace KFormula { class SymbolTable; }
28class ParserNode;
29
33class FormulaStringParser {
34public:
35 FormulaStringParser( const KFormula::SymbolTable& symbolTable, TQString formula );
36 ~FormulaStringParser();
37
38 TQDomDocument parse();
39
40 TQStringList errorList() const { return m_errorList; }
41
42private:
43
44 enum TokenType { NUMBER, NAME, PLUS, SUB, MUL, DIV, POW, INDEX, LP, RP, LB, RB,
45 ASSIGN, COMMA, SEMIC, NEWLINE, OTHER, EOL };
46
47 ParserNode* parseAssign();
48 ParserNode* parseExpr();
49 ParserNode* parseTerm();
50 ParserNode* parsePower();
51 ParserNode* parsePrimary();
52 void expect( TokenType type, TQString msg );
53
54 TQString nextToken();
55 bool eol() { return m_formula.length() == pos; }
56
57 void readNumber();
58 void readDigits();
59
60 void error( TQString err );
61 TQStringList m_errorList;
62
63 const KFormula::SymbolTable& m_symbolTable;
64 TQString m_formula;
65 uint pos;
66 uint line;
67 uint column;
68 bool m_newlineIsSpace;
69
70 TokenType currentType;
71 TQString current;
72
73 ParserNode* head;
74};
75
76#endif