2008-08-08 12:35:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2008 Andrew Garrett.
|
|
|
|
* Copyright (c) 2008 River Tarnell <river@wikimedia.org>
|
|
|
|
* Derived from public domain code contributed by Victor Vasiliev.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any purpose,
|
|
|
|
* including commercial applications, and to alter it and redistribute it
|
|
|
|
* freely. This software is provided 'as-is', without any express or
|
|
|
|
* implied warranty.
|
|
|
|
*/
|
|
|
|
|
2008-08-08 00:01:22 +00:00
|
|
|
#ifndef EXPRESSOR_H
|
|
|
|
#define EXPRESSOR_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2008-08-09 14:34:17 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <iostream>
|
2008-08-08 00:01:22 +00:00
|
|
|
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <boost/function.hpp>
|
2008-08-10 03:52:17 +00:00
|
|
|
#include <boost/spirit/symbols.hpp>
|
2008-08-09 14:34:17 +00:00
|
|
|
|
|
|
|
#include <unicode/uchar.h>
|
2008-08-08 00:01:22 +00:00
|
|
|
|
|
|
|
#include "aftypes.h"
|
2008-08-09 16:18:04 +00:00
|
|
|
#include "afstring.h"
|
2008-08-10 04:21:28 +00:00
|
|
|
#include "affunctions.h"
|
2008-08-10 03:52:17 +00:00
|
|
|
#include "fray.h"
|
2008-08-10 15:36:48 +00:00
|
|
|
#include "parserdefs.h"
|
2008-08-08 00:01:22 +00:00
|
|
|
|
2008-08-08 03:23:34 +00:00
|
|
|
namespace afp {
|
|
|
|
|
2008-08-12 14:02:33 +00:00
|
|
|
struct parser_grammar;
|
2008-08-08 00:01:22 +00:00
|
|
|
|
2008-08-12 14:02:33 +00:00
|
|
|
struct expressor : boost::noncopyable {
|
|
|
|
typedef boost::function<u32datum (std::vector<u32datum>)> func_t;
|
2008-08-08 00:01:22 +00:00
|
|
|
|
2008-08-12 14:02:33 +00:00
|
|
|
expressor();
|
|
|
|
~expressor();
|
2008-08-08 00:01:22 +00:00
|
|
|
|
2008-08-12 14:02:33 +00:00
|
|
|
u32datum evaluate(u32fray const &expr) const;
|
|
|
|
void print_xml(std::ostream &strm, u32fray const &expr) const;
|
2008-08-08 00:01:22 +00:00
|
|
|
|
2008-08-12 14:02:33 +00:00
|
|
|
void add_variable(u32fray const &name, u32datum const &value);
|
|
|
|
void add_function(u32fray const &name, func_t value);
|
2008-08-10 03:52:17 +00:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
void clear_functions();
|
|
|
|
void clear_variables();
|
2008-08-08 00:01:22 +00:00
|
|
|
|
|
|
|
private:
|
2008-08-12 14:02:33 +00:00
|
|
|
parser_state state_;
|
|
|
|
parser_grammar *grammar_;
|
2008-08-09 14:34:17 +00:00
|
|
|
};
|
|
|
|
|
2008-08-08 03:23:34 +00:00
|
|
|
} // namespace afp
|
|
|
|
|
2008-08-08 00:01:22 +00:00
|
|
|
#endif /* !EXPRESSOR_H */
|