amath  1.8.5 Simple command line calculator
EvalStatement Class Reference

Evaluate arithmetic expression. More...

`#include <eval.h>`

Inheritance diagram for EvalStatement:
Collaboration diagram for EvalStatement:

Public Member Functions

EvalStatement (ExpressionNode *expression)

~EvalStatement ()

char * Execute ()

SyntaxNodeGetNext ()

void Attach (SyntaxNode *node)

void Detach (SyntaxNode *node)

void Replace (SyntaxNode *n, SyntaxNode *x)

Public Member Functions inherited from StatementNode
StatementNode ()

StatementNode (const char *text)

virtual ~StatementNode ()

NodeType GetNodeType ()

virtual char * GetTextCode ()

Public Member Functions inherited from SyntaxNode
SyntaxNode ()

virtual ~SyntaxNode ()

void SetFirstNode ()

bool GetFirstNode () const

SyntaxNodeGetParent () const

void SetParent (SyntaxNode *node)

virtual ReductionType GetReductionType ()

virtual void ResetIterator ()

Private Attributes

ExpressionNodeexpression

Protected Attributes inherited from StatementNode
char * statementText

Protected Attributes inherited from SyntaxNode
CharBufferoutput

SyntaxNodeparent

SyntaxNodeiterator

bool leftBottom

Detailed Description

Evaluate arithmetic expression.

Definition at line 39 of file eval.h.

◆ EvalStatement()

 EvalStatement::EvalStatement ( ExpressionNode * expression )
explicit

Definition at line 35 of file eval.cpp.

References expression, and StatementNode::StatementNode().

Referenced by Parser::ParseEvaluation(), and Parser::ParseStatement().

35  :
36  StatementNode(), expression(expression)
37 {
38 }
ExpressionNode * expression
Definition: eval.h:52
StatementNode()
Definition: node.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~EvalStatement()

 EvalStatement::~EvalStatement ( )

Definition at line 40 of file eval.cpp.

References expression.

41 {
42  if (expression != nullptr)
43  {
44  delete expression;
45  }
46 }
ExpressionNode * expression
Definition: eval.h:52

◆ Attach()

 void EvalStatement::Attach ( SyntaxNode * node )
virtual

Reimplemented from StatementNode.

Definition at line 83 of file eval.cpp.

References expression, and SyntaxNode::SetParent().

84 {
85  if (expression == nullptr)
86  {
87  expression = static_cast<ExpressionNode*>(node);
88  node->SetParent(this);
89  }
90 }
ExpressionNode * expression
Definition: eval.h:52
void SetParent(SyntaxNode *node)
Definition: nodes.cpp:75
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99
Here is the call graph for this function:

◆ Detach()

 void EvalStatement::Detach ( SyntaxNode * node )
virtual

Reimplemented from StatementNode.

Definition at line 92 of file eval.cpp.

References expression.

93 {
94  if (expression == node)
95  {
96  expression = nullptr;
97  }
98 }
ExpressionNode * expression
Definition: eval.h:52

◆ Execute()

 char * EvalStatement::Execute ( )
virtual

Implements StatementNode.

Definition at line 48 of file eval.cpp.

49 {
50  Number* result = expression->Evaluate();
51  Number* temp = result->Clone();
52  const char* text = expression->GetText();
53  const char* val = Program->Output->GetText(result);
54
55  Program->SetLastResult(temp);
56  delete temp;
57
58  output->Empty();
60  StrLen(text) + 3 +
61  StrLen(val) +
62  StrLen(NEWLINE) + 1);
63
64  output->Append(text);
65  output->Append(" = ");
66  output->Append(val);
68
69  return output->GetString();
70 }
#define NEWLINE
Definition: amath.h:222
Master control class.
Definition: program.h:55
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
void Append(const char *source)
Definition: charbuf.cpp:262
Definition: numb.h:66
virtual Number * Clone()=0
virtual const char * GetText(Number *number)=0
ExpressionNode * expression
Definition: eval.h:52
virtual Number * Evaluate()=0
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
virtual char * GetText()=0
CharBuffer * output
Definition: nodes.h:85
void SetLastResult(Number *number)
Definition: program.cpp:127
void EnsureSize(unsigned int size)
Ensure a memory block of specified size is allocated.
Definition: charbuf.cpp:114
class NumeralSystem * Output
Definition: program.h:76
Here is the call graph for this function:

◆ GetNext()

 SyntaxNode * EvalStatement::GetNext ( )
virtual

Reimplemented from StatementNode.

Definition at line 72 of file eval.cpp.

References expression, and SyntaxNode::iterator.

73 {
74  if (iterator == nullptr)
75  {
77  return iterator;
78  }
79
80  return nullptr;
81 }
ExpressionNode * expression
Definition: eval.h:52
SyntaxNode * iterator
Definition: nodes.h:87

◆ Replace()

 void EvalStatement::Replace ( SyntaxNode * n, SyntaxNode * x )
virtual

Reimplemented from StatementNode.

Definition at line 100 of file eval.cpp.

References expression.

101 {
102  if (expression == n)
103  {
104  delete expression;
105  expression = static_cast<ExpressionNode*>(x);
106  }
107 }
ExpressionNode * expression
Definition: eval.h:52
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99

◆ expression

 ExpressionNode* EvalStatement::expression
private

Definition at line 52 of file eval.h.

Referenced by Attach(), Detach(), EvalStatement(), Execute(), GetNext(), Replace(), and ~EvalStatement().

The documentation for this class was generated from the following files: