2006-03-07 03:31:31 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2006 The ScummVM project
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GUI_EVAL_H
|
|
|
|
#define GUI_EVAL_H
|
|
|
|
|
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/str.h"
|
2006-03-28 10:05:25 +00:00
|
|
|
#include "common/hashmap.h"
|
2006-03-07 03:31:31 +00:00
|
|
|
|
|
|
|
namespace GUI {
|
|
|
|
|
|
|
|
using Common::String;
|
2006-03-28 10:05:25 +00:00
|
|
|
using Common::HashMap;
|
2006-03-07 03:31:31 +00:00
|
|
|
|
2006-06-05 12:35:33 +00:00
|
|
|
enum {
|
|
|
|
EVAL_UNDEF_VAR = -13375
|
2006-03-07 03:31:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class Eval {
|
|
|
|
public:
|
|
|
|
Eval();
|
|
|
|
~Eval();
|
|
|
|
|
|
|
|
int eval(const String &input, const String §ion, const String &name, int startpos);
|
2006-06-05 17:43:30 +00:00
|
|
|
void setVar(const String §ion, const String &name, const String &value);
|
2006-03-07 03:31:31 +00:00
|
|
|
|
2006-06-03 13:33:39 +00:00
|
|
|
void setParent(const String &name);
|
2006-03-07 03:31:31 +00:00
|
|
|
|
2006-06-05 17:43:30 +00:00
|
|
|
void setVar(const String &name, int val) { _vars[name.c_str()] = val; }
|
2006-06-03 13:33:39 +00:00
|
|
|
void setAlias(const char *name, const String &val) { _aliases[name] = val; }
|
2006-03-07 03:31:31 +00:00
|
|
|
|
2006-06-03 13:33:39 +00:00
|
|
|
int getVar(const String &s) { return getVar_(s.c_str()); }
|
|
|
|
int getVar(const String &s, int def) {
|
2006-04-16 10:23:36 +00:00
|
|
|
int val = getVar_(s.c_str());
|
|
|
|
return (val == EVAL_UNDEF_VAR) ? def : val;
|
|
|
|
};
|
2006-03-07 03:31:31 +00:00
|
|
|
|
2006-03-31 23:51:19 +00:00
|
|
|
uint getNumVars() { return _vars.size(); }
|
|
|
|
|
2006-03-07 03:31:31 +00:00
|
|
|
void reset();
|
|
|
|
|
2006-06-02 17:51:20 +00:00
|
|
|
struct CharStar_EqualTo {
|
|
|
|
bool operator()(const char *x, const char *y) const { return strcmp(x, y) == 0; }
|
|
|
|
};
|
|
|
|
|
|
|
|
//typedef HashMap<String, int> VariablesMap;
|
|
|
|
typedef HashMap<const char *, int, Common::Hash<const char *>, CharStar_EqualTo> VariablesMap;
|
|
|
|
typedef HashMap<const char *, String, Common::Hash<const char *>, CharStar_EqualTo> AliasesMap;
|
2006-03-07 03:31:31 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void getToken();
|
|
|
|
void level2(int *);
|
|
|
|
void level3(int *);
|
|
|
|
void level4(int *);
|
|
|
|
void level5(int *);
|
|
|
|
void primitive(int *);
|
|
|
|
void arith(char op, int *r, int *h);
|
|
|
|
void unary(char op, int *r);
|
|
|
|
void exprError(int error);
|
2006-03-08 01:42:02 +00:00
|
|
|
int getVar_(const char *s, bool includeAliases = true);
|
2006-03-07 03:31:31 +00:00
|
|
|
int getBuiltinVar(const char *s);
|
2006-03-24 01:24:26 +00:00
|
|
|
void loadConstants();
|
2006-03-07 03:31:31 +00:00
|
|
|
|
|
|
|
char _input[256];
|
|
|
|
String _section;
|
|
|
|
String _name;
|
|
|
|
|
|
|
|
int _startpos;
|
|
|
|
|
|
|
|
int _tokenType;
|
|
|
|
int _pos;
|
|
|
|
|
|
|
|
char _token[256];
|
|
|
|
|
|
|
|
AliasesMap _aliases;
|
|
|
|
VariablesMap _vars;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // end of namespace GUI
|
|
|
|
|
|
|
|
#endif
|