-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddfOperator.h
More file actions
84 lines (65 loc) · 1.88 KB
/
Copy pathAddfOperator.h
File metadata and controls
84 lines (65 loc) · 1.88 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//----------------------------------------------------------------------
/// \autor Group: 20
/// \brief The operator for the addf function.
/// Last Changes: 22.06.2008
//----------------------------------------------------------------------
#ifndef ADDFOPERATOR_H_
#define ADDFOPERATOR_H_
#include "GMLOperator.h"
#include "GMLToken.h"
#include "TokenTypes.h"
#include <exception>
#include <stdexcept>
#include <vector>
#include <string>
#include <memory>
#include <string>
#include <iostream>
class AddfOperator : public GMLOperator
{
public:
//-------------------------------------------------------------------
/// \param stack execution stack of the interpreter
AddfOperator(std::vector<GMLToken> &stack) :
GMLOperator(stack)
{
m_name = "addf";
};
//-------------------------------------------------------------------
~AddfOperator()
{};
//-------------------------------------------------------------------
/// \brief execution of the token
void execute() const
{
GMLToken operand1;
GMLToken operand2;
if (m_stack.empty())
throw std::runtime_error("ERROR addf: Stack is empty");
operand1 = m_stack.back();
m_stack.pop_back();
if (m_stack.empty())
throw std::runtime_error("ERROR addf: Stack is empty");
operand2 = m_stack.back();
m_stack.pop_back();
if (operand1.m_type == INTEGER)
{
operand1.m_float[0] = (float)operand1.m_int[0];
operand1.m_type = FLOAT;
}
if (operand2.m_type == INTEGER)
{
operand2.m_float[0] = (float)operand2.m_int[0];
operand2.m_type = FLOAT;
}
if ((operand1.m_type == FLOAT) && (operand2.m_type == FLOAT))
{
float result = operand1.m_float[0] + operand2.m_float[0];
GMLToken token;
token.m_type = FLOAT;
token.m_float[0] = result;
m_stack.push_back(token);
}
};
};
#endif /*ADDFOPERATOR_H_*/