www.mooseframework.org
Public Types | Public Member Functions | Protected Attributes | List of all members
ExpressionBuilder::EBBinaryOpTermNode Class Reference

Node representing a binary operator. More...

#include <ExpressionBuilder.h>

Inheritance diagram for ExpressionBuilder::EBBinaryOpTermNode:
[legend]

Public Types

enum  NodeType {
  ADD, SUB, MUL, DIV,
  MOD, POW, LESS, GREATER,
  LESSEQ, GREATEREQ, EQ, NOTEQ
}
 

Public Member Functions

 EBBinaryOpTermNode (EBTermNode *left, EBTermNode *right, NodeType type)
 
virtual EBBinaryOpTermNodeclone () const
 
virtual std::string stringify () const
 
virtual int precedence () const
 
virtual unsigned int substitute (const EBSubstitutionRuleList &rule)
 

Protected Attributes

NodeType _type
 
EBTermNode_left
 
EBTermNode_right
 

Detailed Description

Node representing a binary operator.

Definition at line 201 of file ExpressionBuilder.h.

Member Enumeration Documentation

Constructor & Destructor Documentation

ExpressionBuilder::EBBinaryOpTermNode::EBBinaryOpTermNode ( EBTermNode left,
EBTermNode right,
NodeType  type 
)
inline

Definition at line 220 of file ExpressionBuilder.h.

221  : EBBinaryTermNode(left, right), _type(type){};
EBBinaryTermNode(EBTermNode *left, EBTermNode *right)

Member Function Documentation

virtual EBBinaryOpTermNode* ExpressionBuilder::EBBinaryOpTermNode::clone ( ) const
inlinevirtual

Implements ExpressionBuilder::EBTermNode.

Definition at line 222 of file ExpressionBuilder.h.

223  {
224  return new EBBinaryOpTermNode(_left->clone(), _right->clone(), _type);
225  };
virtual EBTermNode * clone() const =0
EBBinaryOpTermNode(EBTermNode *left, EBTermNode *right, NodeType type)
int ExpressionBuilder::EBBinaryOpTermNode::precedence ( ) const
virtual

Implements ExpressionBuilder::EBTermNode.

Definition at line 114 of file ExpressionBuilder.C.

std::string ExpressionBuilder::EBBinaryOpTermNode::stringify ( ) const
virtual

Implements ExpressionBuilder::EBTermNode.

Definition at line 89 of file ExpressionBuilder.C.

90 {
91  const char * name[] = {"+", "-", "*", "/", "%", "^", "<", ">", "<=", ">=", "=", "!="};
92  std::ostringstream s;
93 
94  if (_left->precedence() > precedence())
95  s << '(' << *_left << ')';
96  else
97  s << *_left;
98 
99  s << name[_type];
100 
101  // these operators are left associative at equal precedence
102  // (this matters for -,/,&,^ but not for + and *)
103  if (_right->precedence() > precedence() ||
104  (_right->precedence() == precedence() &&
105  (_type == SUB || _type == DIV || _type == MOD || _type == POW)))
106  s << '(' << *_right << ')';
107  else
108  s << *_right;
109 
110  return s.str();
111 }
virtual int precedence() const =0
unsigned int ExpressionBuilder::EBBinaryTermNode::substitute ( const EBSubstitutionRuleList rule)
virtualinherited

Reimplemented from ExpressionBuilder::EBTermNode.

Reimplemented in ExpressionBuilder::EBTernaryTermNode.

Definition at line 323 of file ExpressionBuilder.C.

324 {
325  unsigned int nrule = rules.size();
326  unsigned int success = 0;
327 
328  for (unsigned int i = 0; i < nrule; ++i)
329  {
330  EBTermNode * replace = rules[i]->apply(_left);
331  if (replace != NULL)
332  {
333  delete _left;
334  _left = replace;
335  success = 1;
336  break;
337  }
338  }
339 
340  if (success == 0)
341  success += _left->substitute(rules);
342 
343  for (unsigned int i = 0; i < nrule; ++i)
344  {
345  EBTermNode * replace = rules[i]->apply(_right);
346  if (replace != NULL)
347  {
348  delete _right;
349  _right = replace;
350  return success + 1;
351  }
352  }
353 
354  return success + _right->substitute(rules);
355 }
virtual unsigned int substitute(const EBSubstitutionRuleList &)

Member Data Documentation

EBTermNode* ExpressionBuilder::EBBinaryTermNode::_left
protectedinherited

Definition at line 196 of file ExpressionBuilder.h.

EBTermNode* ExpressionBuilder::EBBinaryTermNode::_right
protectedinherited

Definition at line 197 of file ExpressionBuilder.h.

NodeType ExpressionBuilder::EBBinaryOpTermNode::_type
protected

Definition at line 231 of file ExpressionBuilder.h.


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