PEBL 2.2
Psychology Experiment Building Language - Cross-platform psychological experiment development system
Evaluator.h
Go to the documentation of this file.
1//* -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*- */
3// Name: src/base/Evaluator.h
4// Purpose: Defines an class that can evaluate PNodes
5// Author: Shane T. Mueller, Ph.D.
6// Copyright: (c) 2003--2013 Shane T. Mueller <smueller@obereed.net>
7// License: GPL 2
8//
9//
10//
11//
12// This file is part of the PEBL project.
13//
14// PEBL is free software; you can redistribute it and/or modify
15// it under the terms of the GNU General Public License as published by
16// the Free Software Foundation; either version 2 of the License, or
17// (at your option) any later version.
18//
19// PEBL is distributed in the hope that it will be useful,
20// but WITHOUT ANY WARRANTY; without even the implied warranty of
21// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22// GNU General Public License for more details.
23//
24// You should have received a copy of the GNU General Public License
25// along with PEBL; if not, write to the Free Software
26// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
29#ifndef __EVALUATOR_H__
30#define __EVALUATOR_H__
31
32
33
34
35#include <stack>
36#include <list>
37//#include "PNode.h"
38#include "Variant.h"
39
40#include "FunctionMap.h"
41#include "../utility/PEBLPath.h"
42#include "VariableMap.h"
43#include "../utility/PError.h"
44//#include "../devices/PEventLoop.h"
45
46
47class PNode;
48class OpNode;
49class DataNode;
50class Variant;
51class FunctionMap;
52class VariableMap;
53class PEventLoop;
54
55
56
58class Evaluator
59{
60public:
61
63 Evaluator(Variant & stacktop, string scope);
65
66 void CallFunction(const OpNode * node);
67
68
69 //If Evaluate returns with true, continue; otherwise, exit.
70 bool Evaluate(const PNode * node);
71 bool Evaluate(const OpNode * node);
72 bool Evaluate(const DataNode * node);
73
74 void Push(const Variant & v);
76 const Variant & Peek() const;
77
78 unsigned long int GetStackDepth(){return mStack.size();};
79
81
83
90
95
96 //Ditto with mEventLoop:
97 static PEventLoop * mEventLoop;
98
99 static PEBLPath gPath;
100
101
102
108 static const PNode * gEvalNode;
109
110
111 static PCallStack gCallStack;
112
113
114
115private:
116
117 //This list keeps track of the call sequence
118 //of evaluators, so that when an error is found,
119 //all the calls can be traced back. It is a list
120 //instead of a stack so that we can examine it easily.
121
122
123
125 std::stack<Variant> mStack;
126
130 unsigned int mStackMax;
131
133 VariableMap mLocalVariableMap;
134
137 std::string mScope;
138
139};
140
141
142#endif
This class has got everything you need to evaluate stuff.
bool Evaluate(const PNode *node)
static const PNode * gEvalNode
static PEBLPath gPath
Evaluator(Variant &stacktop, string scope)
PEventLoop * GetEventLoop()
Definition Evaluator.h:80
void Push(Variant v)
static PCallStack gCallStack
static PEventLoop * mEventLoop
bool IsVariableName(Variant v)
static VariableMap gGlobalVariableMap
Variant Peek()
Variant Pop()
static FunctionMap mFunctionMap
Initiate some static member data.
unsigned long int GetStackDepth()
Definition Evaluator.h:78
void CallFunction(const OpNode *node)
Definition PNode.h:45