amath  1.8.5
Simple command line calculator
operators.h
Go to the documentation of this file.
1 /*-
2  * Copyright (c) 2014-2018 Carsten Sonne Larsen <cs@innolan.net>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
15  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
18  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  *
25  * Project homepage:
26  * https://amath.innolan.net
27  *
28  */
29 
30 #ifndef AMATH_OPERATORS_H
31 #define AMATH_OPERATORS_H
32 
33 /**
34  * @file operators.h
35  * @brief Application logic tied to arithmetic operators.
36  *
37  */
38 
39 #include "nodes.h"
40 #include "values.h"
41 
42 class UnaryNode : virtual public ExpressionNode
43 {
44 public:
45  UnaryNode(ExpressionNode* expression);
46  ~UnaryNode();
47 
48  ReductionType GetReductionType();
49  int GetPrecedence();
51  char* GetText();
52  Number* Evaluate();
53  void Attach(SyntaxNode* node);
54  void Detach(SyntaxNode* node);
55  void Replace(SyntaxNode* n, SyntaxNode* x);
56 
57 protected:
58  char* GetNodeText();
59 
60 private:
62 };
63 
64 class AbsoluteNode : virtual public ExpressionNode
65 {
66 public:
67  AbsoluteNode(ExpressionNode* expression);
68  ~AbsoluteNode();
69 
70  char* GetText();
71  Number* Evaluate();
72  int GetPrecedence();
74  void Attach(SyntaxNode* node);
75  void Detach(SyntaxNode* node);
76  void Replace(SyntaxNode* n, SyntaxNode* x);
77 
78 protected:
79  char* GetNodeText();
80 
81 private:
83 };
84 
85 class FactorialNode : virtual public ExpressionNode
86 {
87 public:
88  FactorialNode(ExpressionNode* expression);
89  ~FactorialNode();
90 
91  char* GetText();
92  Number* Evaluate();
93  int GetPrecedence();
95  void Attach(SyntaxNode* node);
96  void Detach(SyntaxNode* node);
97  void Replace(SyntaxNode* n, SyntaxNode* x);
98 
99 protected:
100  char* GetNodeText();
101 
102 private:
104 };
105 
106 class NumericOperator : virtual public ExpressionNode
107 {
108 public:
110  ~NumericOperator();
111 
112  SyntaxNode* GetNext();
113  char* GetText();
114  void Attach(SyntaxNode* node);
115  void Detach(SyntaxNode* node);
116  void Replace(SyntaxNode* n, SyntaxNode* x);
117 
118 protected:
121 };
122 
124 {
125 public:
127  ReductionType GetReductionType();
128  int GetPrecedence();
129  Number* Evaluate();
130 
131 protected:
132  char* GetNodeText();
133 };
134 
136 {
137 public:
139  ReductionType GetReductionType();
140  int GetPrecedence();
141  Number* Evaluate();
142 
143 protected:
144  char* GetNodeText();
145 };
146 
148 {
149 public:
151  int GetPrecedence();
152  Number* Evaluate();
153 
154 protected:
155  char* GetNodeText();
156 };
157 
159 {
160 public:
162  int GetPrecedence();
163  Number* Evaluate();
164 
165 protected:
166  char* GetNodeText();
167 };
168 
170 {
171 public:
172  PowerNode(ExpressionNode* left, ExpressionNode* right);
173  int GetPrecedence();
174  Number* Evaluate();
175 
176 protected:
177  char* GetNodeText();
178 };
179 
181 {
182 public:
183  AssignmentNode(VariableNode* variable, ExpressionNode* expression);
184  int GetPrecedence();
185  bool IsSilent();
186  Number* Evaluate();
187 
188 protected:
189  char* GetNodeText();
190 
191 private:
194 };
195 
196 #endif
DivisionNode(ExpressionNode *left, ExpressionNode *right)
Definition: operators.cpp:519
int GetPrecedence()
Definition: operators.cpp:441
Number * Evaluate()
Definition: operators.cpp:583
AbsoluteNode(ExpressionNode *expression)
Definition: operators.cpp:139
Number * Evaluate()
Definition: operators.cpp:255
ExpressionNode * expression
Definition: operators.h:61
void Detach(SyntaxNode *node)
Definition: operators.cpp:287
char * GetNodeText()
Definition: operators.cpp:62
char * GetNodeText()
Definition: operators.cpp:595
void Attach(SyntaxNode *node)
Definition: operators.cpp:278
NumericOperator(ExpressionNode *left, ExpressionNode *right)
Definition: operators.cpp:308
char * GetNodeText()
Definition: operators.cpp:452
SyntaxNode * GetNext()
Definition: operators.cpp:362
ReductionType GetReductionType()
Definition: operators.cpp:467
Base class for all nodes in a syntax tree.
Definition: nodes.h:65
char * GetText()
Definition: operators.cpp:326
int GetPrecedence()
Definition: operators.cpp:166
void Detach(SyntaxNode *node)
Definition: operators.cpp:203
ExpressionNode * expression
Definition: operators.h:103
PowerNode(ExpressionNode *left, ExpressionNode *right)
Definition: operators.cpp:545
void Detach(SyntaxNode *node)
Definition: operators.cpp:118
void Replace(SyntaxNode *n, SyntaxNode *x)
Definition: operators.cpp:126
MultiplicationNode(ExpressionNode *left, ExpressionNode *right)
Definition: operators.cpp:493
char * GetNodeText()
Definition: operators.cpp:483
Definition: numb.h:66
void Replace(SyntaxNode *n, SyntaxNode *x)
Definition: operators.cpp:295
char * GetNodeText()
Definition: operators.cpp:177
int GetPrecedence()
Definition: operators.cpp:57
void Attach(SyntaxNode *node)
Definition: operators.cpp:379
AssignmentNode(VariableNode *variable, ExpressionNode *expression)
Definition: operators.cpp:572
void Attach(SyntaxNode *node)
Definition: operators.cpp:109
char * GetText()
Definition: operators.cpp:237
Number * Evaluate()
Definition: operators.cpp:503
char * GetNodeText()
Definition: operators.cpp:509
SyntaxNode * GetNext()
Definition: operators.cpp:267
ExpressionNode * left
Definition: operators.h:119
AdditionNode(ExpressionNode *left, ExpressionNode *right)
Definition: operators.cpp:431
UnaryNode(ExpressionNode *expression)
Definition: operators.cpp:39
char * GetNodeText()
Definition: operators.cpp:562
int GetPrecedence()
Definition: operators.cpp:524
SyntaxNode * GetNext()
Definition: operators.cpp:183
ExpressionNode * right
Definition: operators.h:120
Number * Evaluate()
Definition: operators.cpp:171
Number * Evaluate()
Definition: operators.cpp:555
void Attach(SyntaxNode *node)
Definition: operators.cpp:194
ReductionType GetReductionType()
Definition: operators.cpp:436
Number * Evaluate()
Definition: operators.cpp:529
char * GetNodeText()
Definition: operators.cpp:261
Number * Evaluate()
Definition: operators.cpp:477
ExpressionNode * expression
Definition: operators.h:193
int GetPrecedence()
Definition: operators.cpp:550
int GetPrecedence()
Definition: operators.cpp:250
VariableNode * variable
Definition: operators.h:192
Use of a variable in a syntax tree.
Definition: values.h:110
char * GetNodeText()
Definition: operators.cpp:535
void Detach(SyntaxNode *node)
Definition: operators.cpp:393
ReductionType GetReductionType()
Definition: operators.cpp:52
int GetPrecedence()
Definition: operators.cpp:578
void Replace(SyntaxNode *n, SyntaxNode *x)
Definition: operators.cpp:211
void Replace(SyntaxNode *n, SyntaxNode *x)
Definition: operators.cpp:405
char * GetText()
Definition: operators.cpp:152
SubtractionNode(ExpressionNode *left, ExpressionNode *right)
Definition: operators.cpp:462
ExpressionNode * expression
Definition: operators.h:82
SyntaxNode * GetNext()
Definition: operators.cpp:98
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99
char * GetText()
Definition: operators.cpp:68
FactorialNode(ExpressionNode *expression)
Definition: operators.cpp:224
Number * Evaluate()
Definition: operators.cpp:92
Number * Evaluate()
Definition: operators.cpp:446