File: expressionbuilder.h

package info (click to toggle)
freespace2 24.0.2%2Brepack-1
  • links: PTS, VCS
  • area: non-free
  • in suites: trixie
  • size: 43,188 kB
  • sloc: cpp: 583,107; ansic: 21,729; python: 1,174; sh: 464; makefile: 248; xml: 181
file content (42 lines) | stat: -rw-r--r-- 1,202 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#ifndef EXPRESSIONBUILDER_H
#define EXPRESSIONBUILDER_H

#include "parsing.h"
#include "../VM/kernel.h"
#include "../VM/random_gen.h"
#include <vector>
#include <string>
#include <map>

namespace anl
{
class CExpressionBuilder
{
public:
    CExpressionBuilder(CKernel &kernel);
    ~CExpressionBuilder();

    CInstructionIndex eval(const std::string &expr);
    CInstructionIndex evalAndStore(const std::string &expr);
    void store(CInstructionIndex i);
    std::vector<Token> getPostfix(const std::string &expr);
    void setRandomSeed(unsigned int seed);

    CInstructionIndex evalAndStoreVar(const std::string &varname, const std::string &expr);
    void storeVar(const std::string &varname, CInstructionIndex idx);
    CInstructionIndex retrieveVar(const std::string &varname);

private:
    CKernel &kernel_;
    std::vector<CInstructionIndex> index_;
    std::map<std::string, int> f_;  // Functions
    std::vector<std::string> vars_;
    std::map<std::string, CInstructionIndex> storedvars_;
    KISS prng_;

    void buildFunction(const std::string &token, std::stack<CInstructionIndex> &stk);
    void buildVar(const std::string &token, std::stack<CInstructionIndex> &stk);
};
};

#endif