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