Marsyas  0.5.0-beta1
Public Member Functions | Data Fields
ExNode Class Reference

ExNode is the base class for an expression tree node. More...

#include <ExNode.h>

Inherits ExRefCount.

Inherited by ExFun, ExNode_ADD, ExNode_AND, ExNode_AsgnVar, ExNode_BoolNeg, ExNode_BoolToString, ExNode_Conditional, ExNode_DIV, ExNode_EQ, ExNode_GE, ExNode_GetCtrlBool, ExNode_GetCtrlNatural, ExNode_GetCtrlReal, ExNode_GetCtrlString, ExNode_GetElem, ExNode_GT, ExNode_IterFor, ExNode_IterIter, ExNode_IterMap, ExNode_IterRFor, ExNode_LE, ExNode_Link, ExNode_LT, ExNode_MathNeg_Natural, ExNode_MathNeg_Real, ExNode_MOD, ExNode_MUL, ExNode_NaturalToReal, ExNode_NaturalToString, ExNode_NE, ExNode_OR, ExNode_Range, ExNode_ReadVar, ExNode_RealToNatural, ExNode_RealToString, ExNode_SetCtrlBool, ExNode_SetCtrlNatural, ExNode_SetCtrlReal, ExNode_SetCtrlString, ExNode_SetElem, ExNode_StringFor, ExNode_StringIter, ExNode_StringMap, ExNode_StringRFor, and ExNode_SUB.

Public Member Functions

virtual ExVal calc ()
virtual ExNodecopy ()
virtual ExVal eval ()
 ExNode ()
 ExNode (int k, std::string t)
 ExNode (int k, std::string t, ExVal v)
 ExNode (ExVal v)
 ExNode (const ExNode &v)
std::string getElemType () const
std::string getEvalType () const
int getKind () const
ExVal getSeqElem (int idx)
ExVal getSeqRange (int lidx, int ridx)
std::string getType () const
ExVal getValue ()
void init ()
virtual bool is_const ()
bool is_list () const
bool is_seq () const
virtual std::string oot ()
void setKind (const int k)
void setSeqElem (int idx, ExVal v)
void setType (const std::string t)
void setValue (mrs_natural x)
void setValue (std::string x)
void setValue (mrs_real x)
void setValue (mrs_bool x)
virtual std::string toString ()
mrs_natural valToNatural ()
virtual ~ExNode ()

Data Fields

std::string val_str
ExVal value

Detailed Description

ExNode is the base class for an expression tree node.

ExNode represents an expression tree node. Additional nodes may be added later, but may also need to be added to the parser.

There should only ever exist a single parent of any node, that is, a node may only be referenced by one object.

To add library functions add a line like this to ExParser.h::preload() :- library->addRecord("Real|R.cos(mrs_real)|cos(mrs_natural)",new ExRecord(T_FUN,new ExNode_RealCos("mrs_real","Real.cos(mrs_real)"),true)); then define the function as an ExNode class, you must support the calc and copy functions. In the constructor make sure you set is_pure to true if the function can be reduced to a const value given const parameters, or false otherwise.

class ExNode_NatDbl : public ExNode_Fun {
    ExNode* child; public:
    ExNode_NatDbl(std::string typ, std::string sig, ExNode* x) : ExNode_Fun(typ,sig,true) { child=x; }
    virtual ExVal calc() { return false; }
    ExNode* copy() { return new ExNode_NatDbl(type,signature); }
Neil Burroughs
Jan 04, 2007

Definition at line 97 of file ExNode.h.

Constructor & Destructor Documentation

ExNode ( )

Definition at line 128 of file ExNode.cpp.

ExNode ( int  k,
std::string  t 

Definition at line 133 of file ExNode.cpp.

ExNode ( int  k,
std::string  t,
ExVal  v 

Definition at line 140 of file ExNode.cpp.

ExNode ( ExVal  v)

Definition at line 148 of file ExNode.cpp.

ExNode ( const ExNode v)

Definition at line 157 of file ExNode.cpp.

~ExNode ( ) [virtual]

Definition at line 199 of file ExNode.cpp.

Member Function Documentation

virtual ExVal calc ( ) [inline, virtual]

Reimplemented in ExFun_ListLen, ExFun_TimerUpdBool, ExFun_TimerUpdString, ExFun_TimerUpdNatural, ExFun_TimerUpdReal, ExFun_TimerIntrvlSize, ExFun_TimerGetTime, ExFun_TimerGetType, ExFun_TimerGetName, ExFun_TimerGetPrefix, ExFun_StreamOutNVal, ExFun_StreamOutNBool, ExFun_StreamOutNNatural, ExFun_StreamOutNReal, ExFun_StreamOutNString, ExFun_StreamOutBool, ExFun_StreamOutNatural, ExFun_StreamOutReal, ExFun_StreamOutString, ExFun_StrSub, ExFun_StrLen, ExFun_RealRand, ExFun_RealLog2, ExFun_RealAbs, ExFun_RealLog10, ExFun_RealLog, ExFun_RealTan, ExFun_RealSinH, ExFun_RealCosH, ExFun_RealATan, ExFun_RealASin, ExFun_RealACos, ExFun_RealSin, ExFun_RealSqrt, ExFun_RealCos, ExFun_NaturalAbs, ExFun_NaturalSRand, ExFun_NaturalRandRange2, ExFun_NaturalRandRange1, ExFun_NaturalRand, ExFun_NaturalMax, ExFun_NaturalMin, ExNode_ReadVar, ExNode_AsgnVar, ExNode_Link, ExNode_SetCtrlBool, ExNode_SetCtrlNatural, ExNode_SetCtrlString, ExNode_SetCtrlReal, ExNode_GetCtrlBool, ExNode_GetCtrlNatural, ExNode_GetCtrlString, ExNode_GetCtrlReal, ExNode_GetElem, ExNode_Range, ExNode_SetElem, ExNode_StringRFor, ExNode_StringFor, ExNode_StringIter, ExNode_StringMap, ExNode_IterRFor, ExNode_IterFor, ExNode_IterIter, ExNode_IterMap, ExNode_Conditional, ExNode_AND, ExNode_OR, ExNode_LE, ExNode_LT, ExNode_GE, ExNode_GT, ExNode_NE, ExNode_EQ, ExNode_MOD, ExNode_DIV, ExNode_MUL, ExNode_SUB, ExNode_ADD, ExNode_BoolToString, ExNode_NaturalToString, ExNode_RealToString, ExNode_RealToNatural, ExNode_NaturalToReal, ExNode_BoolNeg, ExNode_MathNeg_Natural, and ExNode_MathNeg_Real.

Definition at line 137 of file ExNode.h.

ExNode * copy ( ) [virtual]
ExVal eval ( ) [virtual]

Definition at line 259 of file ExNode.cpp.

std::string getElemType ( ) const

Definition at line 232 of file ExNode.cpp.

std::string getEvalType ( ) const

Definition at line 218 of file ExNode.cpp.

int getKind ( ) const [inline]

Definition at line 121 of file ExNode.h.

ExVal getSeqElem ( int  idx)

Definition at line 273 of file ExNode.cpp.

ExVal getSeqRange ( int  lidx,
int  ridx 

Definition at line 267 of file ExNode.cpp.

std::string getType ( void  ) const

Definition at line 211 of file ExNode.cpp.

ExVal getValue ( ) [inline]

Definition at line 126 of file ExNode.h.

void init ( )

Definition at line 168 of file ExNode.cpp.

bool is_const ( ) [virtual]

Reimplemented in ExFun.

Definition at line 175 of file ExNode.cpp.

bool is_list ( ) const

Definition at line 181 of file ExNode.cpp.

bool is_seq ( ) const

Definition at line 194 of file ExNode.cpp.

std::string oot ( ) [virtual]

Definition at line 253 of file ExNode.cpp.

void setKind ( const int  k)

Definition at line 239 of file ExNode.cpp.

void setSeqElem ( int  idx,
ExVal  v 

Definition at line 279 of file ExNode.cpp.

void setType ( const std::string  t)

Definition at line 226 of file ExNode.cpp.

void setValue ( mrs_natural  x) [inline]

Definition at line 129 of file ExNode.h.

void setValue ( std::string  x) [inline]

Definition at line 130 of file ExNode.h.

void setValue ( mrs_real  x) [inline]

Definition at line 131 of file ExNode.h.

void setValue ( mrs_bool  x) [inline]

Definition at line 132 of file ExNode.h.

std::string toString ( ) [virtual]

Definition at line 245 of file ExNode.cpp.

mrs_natural valToNatural ( ) [inline]

Definition at line 127 of file ExNode.h.

Field Documentation

Definition at line 103 of file ExNode.h.

std::string val_str

Definition at line 100 of file ExNode.h.

Definition at line 101 of file ExNode.h.

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