-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLessiOperator.h
More file actions
80 lines (58 loc) · 1.78 KB
/
Copy pathLessiOperator.h
File metadata and controls
80 lines (58 loc) · 1.78 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
//----------------------------------------------------------------------
/// \author Group: 20
/// \brief The operator for the lessi function.
/// Last Changes: 22.06.2008
//----------------------------------------------------------------------
#ifndef LESSIOPERATOR_H_
#define LESSIOPERATOR_H_
#include "GMLOperator.h"
#include "GMLToken.h"
#include "TokenTypes.h"
#include <vector>
#include <string>
#include <memory>
#include <stdexcept>
class LessiOperator : public GMLOperator
{
public:
//-------------------------------------------------------------------
/// \param stack execution stack of the interpreter
LessiOperator(std::vector<GMLToken> &stack) :
GMLOperator(stack)
{
m_name = "lessi";
};
//-------------------------------------------------------------------
~LessiOperator()
{};
//-------------------------------------------------------------------
/// \brief execution of the token
void execute() const
{
GMLToken operand1;
GMLToken operand2;
if (m_stack.empty())
throw std::runtime_error("ERROR lessf: Stack is empty");
operand1 = m_stack.back();
m_stack.pop_back();
if (m_stack.empty())
throw std::runtime_error("ERROR lessf: Stack is empty");
operand2 = m_stack.back();
m_stack.pop_back();
if ((operand1.m_type == INTEGER) && (operand2.m_type == INTEGER))
{
int result = 0;
if (operand2.m_int[0] < operand1.m_int[0])
result = 1;
else
result = 0;
GMLToken token;
token.m_type = INTEGER;
token.m_int[0] = result;
m_stack.push_back(token);
}
else
throw std::runtime_error("ERROR lessi: wrong operand-type");
};
};
#endif /*LESSIOPERATOR_H_*/