amath  1.8.5
Simple command line calculator
ExecuteStatement Class Reference

#include <execute.h>

Inheritance diagram for ExecuteStatement:
Collaboration diagram for ExecuteStatement:

Public Member Functions

 ExecuteStatement (const char *file)
 
 ~ExecuteStatement ()
 
char * Execute ()
 
- Public Member Functions inherited from StatementNode
 StatementNode ()
 
 StatementNode (const char *text)
 
virtual ~StatementNode ()
 
NodeType GetNodeType ()
 
virtual SyntaxNodeGetNext ()
 
virtual char * GetTextCode ()
 
void Attach (SyntaxNode *node)
 
void Detach (SyntaxNode *node)
 
void Replace (SyntaxNode *n, SyntaxNode *x)
 
- 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

char * file
 

Additional Inherited Members

- Protected Attributes inherited from StatementNode
char * statementText
 
- Protected Attributes inherited from SyntaxNode
CharBufferoutput
 
SyntaxNodeparent
 
SyntaxNodeiterator
 
bool leftBottom
 

Detailed Description

Definition at line 35 of file execute.h.

Constructor & Destructor Documentation

◆ ExecuteStatement()

ExecuteStatement::ExecuteStatement ( const char *  file)
explicit

Definition at line 37 of file execute.cpp.

References AllocAndCopy(), file, and StatementNode::StatementNode().

Referenced by Parser::ParseFileStatement().

38  : StatementNode()
39 {
40  AllocAndCopy(&this->file, file);
41 }
char * file
Definition: execute.h:43
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
StatementNode()
Definition: node.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~ExecuteStatement()

ExecuteStatement::~ExecuteStatement ( )

Definition at line 43 of file execute.cpp.

References file.

44 {
45  delete [] file;
46 }
char * file
Definition: execute.h:43

Member Function Documentation

◆ Execute()

char * ExecuteStatement::Execute ( )
virtual

Implements StatementNode.

Definition at line 48 of file execute.cpp.

References CharBuffer::ClearAndCopy(), SyntaxNode::Execute(), file, Program::Filesystem, CharBuffer::GetString(), FilesystemBase::LoadTextFile(), SyntaxNode::output, Parser::Parse(), and Parser::Parser().

49 {
51  if (input == nullptr)
52  {
53  return static_cast<char*>(MSGNOFILE);
54  }
55 
56  Parser* parser = new Parser(input->GetString());
57  delete input;
58 
59  SyntaxNode* node = parser->Parse();
60  delete parser;
61 
62  const char* res = node->Execute();
63  output->ClearAndCopy(res);
64  delete node;
65 
66  return output->GetString();
67 }
Master control class.
Definition: program.h:55
char * GetString() const
Definition: charbuf.cpp:306
Base class for all nodes in a syntax tree.
Definition: nodes.h:65
class FilesystemBase * Filesystem
Definition: program.h:74
char * file
Definition: execute.h:43
virtual char * Execute()=0
virtual CharBuffer * LoadTextFile(const char *name)=0
CharBuffer * output
Definition: nodes.h:85
void ClearAndCopy(const char *source)
Release memory, allocate and copy source.
Definition: charbuf.cpp:81
#define MSGNOFILE
Definition: text.h:102
SyntaxNode * Parse()
Parses the input into a syntax tree.
Definition: parser.cpp:56
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
Encapsulates a recursive descent parser.
Definition: parser.h:49
Here is the call graph for this function:

Member Data Documentation

◆ file

char* ExecuteStatement::file
private

Definition at line 43 of file execute.h.

Referenced by Execute(), ExecuteStatement(), and ~ExecuteStatement().


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