KOffice – TDE office suite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fsparser.h 2.1KB

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