-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLessfOperator.h
More file actions
76 lines (56 loc) · 1.74 KB
/
LessfOperator.h
File metadata and controls
76 lines (56 loc) · 1.74 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
//----------------------------------------------------------------------
/// \author Group: 20
/// \brief The operator for the lessf function.
/// Last Changes: 22.06.2008
//----------------------------------------------------------------------
#ifndef LESSFOPERATOR_H_
#define LESSFOPERATOR_H_
#include "GMLOperator.h"
#include "GMLToken.h"
#include "TokenTypes.h"
#include <vector>
#include <string>
#include <memory>
#include <iostream>
class LessfOperator : public GMLOperator
{
public:
//-------------------------------------------------------------------
/// \param stack execution stack of the interpreter
LessfOperator(std::vector<GMLToken> &stack) :
GMLOperator(stack)
{
m_name = "lessf";
};
//-------------------------------------------------------------------
~LessfOperator()
{};
//-------------------------------------------------------------------
/// \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 == FLOAT) && (operand2.m_type == FLOAT))
{
int result = 0;
if (operand2.m_float[0] > operand1.m_float[0])
result = 1;
GMLToken token;
token.m_type = INTEGER;
token.m_int[0] = result;
m_stack.push_back(token);
}
else
throw std::runtime_error("ERROR lessf: Wrong operand-type");
};
};
#endif /*LESSFOPERATOR_H_*/