reader.h
// Math Type Library
// $Id: reader.h,v 1.6 2002/04/20 06:35:05 cparpart Exp $
// (This file contains the reader (parser) specific interface)
//
// Copyright (c) 2002 by Christian Parpart <cparpart@surakware.net>
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Library General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with this library; see the file COPYING.LIB. If not, write to
// the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
#ifndef libmath_reader_h
#define libmath_reader_h
#include <math++/error.h>
#include <string>
namespace math {
template<class> class TNode;
class EReadError : public EMath {
public:
EReadError(const std::string& AReason) : EMath(AReason) {}
};
template<class T>
class TReader {
private:
enum TToken {
/* TAKE CARE : THE VALUES ARE HARD CODED */
tkInvalid, tkEnd,
tkNumber = 1000, tkSymbol,
tkUnEqu, tkLess, tkGreater, tkLessEqu, tkGreaterEqu,
tkVeryLess, tkVeryGreat,
tkEqu = '=', tkComma = ',',
tkPlus = '+', tkMinus = '-', tkMul = '*', tkDiv = '/', tkPow = '^',
tkRndOpen = '(', tkRndClose = ')', tkBrOpen = '[', tkBrClose = ']',
tkAngOpen = '<', tkAngClose = '>', tkSetOpen = '{', tkSetClose = '}'
};
std::string FExprStr; // holds the current parsed expression
std::string::size_type FPos;// holds the current read index
TToken FToken; // holds current parsed token id
T FNumber; // holds last read number
std::string FSymbol; // holds last read symbol
private:
TReader(const std::string& AInput);
TNode<T> *equation(bool get);
// parses an expression (really any expression, even sub equations)
TNode<T> *expr(bool get);
TNode<T> *simpleExpr(bool get);
TNode<T> *term(bool get);
TNode<T> *factor(bool get);
TNode<T> *prim(bool get);
TNode<T> *createSymbol();
TNode<T> *param();
bool eof() const;
TToken nextToken();
bool readOperator();
bool readNumber();
bool readSymbol();
static std::string tok2str(TToken AToken);
void consume(TToken AToken);
public:
static TNode<T> *parse(const std::string& AInput, bool AEquation = false);
};
} // namespace math
#include <math++/reader.tcc>
#endif
math::EMath
Definition: error.h:34
math::TNode< T >
math::TReader::parse
static TNode< T > * parse(const std::string &AInput, bool AEquation=false)
math::TReader
Definition: reader.h:49
math::EReadError
Definition: reader.h:38