template-project-cpp
Loading...
Searching...
No Matches
tpcpp::Interpreter Class Reference

The tpcpp interpreter, which is a simple calculator. More...

#include <Interpreter.hpp>

Public Member Functions

void run ()
 Start the interpreter REPL loop.
 
Object evaluate (const std::string &expr)
 Evaluate a given string.
 
void error (const std::string &message)
 Indicate a parsing-time error to the intepreter.
 
void runtimeError (const RuntimeError &error)
 Indicate a run-time error to the intepreter.
 
void setVariable (const std::string &name, const Object &value)
 Set a global variable.
 
Object getVariable (const std::string &name)
 Get a global variable.
 

Private Member Functions

void registerFunctions ()
 Register native functions to the tpcpp interpreter.
 

Detailed Description

The tpcpp interpreter, which is a simple calculator.

Definition at line 12 of file Interpreter.hpp.

Member Function Documentation

◆ error()

void tpcpp::Interpreter::error ( const std::string & message)

Indicate a parsing-time error to the intepreter.

Parameters
[in]messageThe error message.

Definition at line 85 of file Interpreter.cpp.

◆ evaluate()

Object tpcpp::Interpreter::evaluate ( const std::string & source)

Evaluate a given string.

Parameters
[in]sourceThe source code to evaluate.
Returns
The result of the evaluation, which is an tpcpp::Object.

Definition at line 57 of file Interpreter.cpp.

Here is the call graph for this function:

◆ getVariable()

Object tpcpp::Interpreter::getVariable ( const std::string & name)

Get a global variable.

Parameters
[in]nameThe name of the variable.
Returns
The value of the variable.

Definition at line 110 of file Interpreter.cpp.

◆ registerFunctions()

void tpcpp::Interpreter::registerFunctions ( )
private

Register native functions to the tpcpp interpreter.

Remarks
Currently the following functions are provided
  • sin
  • cos
  • abs
  • max
  • min

Definition at line 128 of file Interpreter.cpp.

◆ runtimeError()

void tpcpp::Interpreter::runtimeError ( const RuntimeError & error)

Indicate a run-time error to the intepreter.

Parameters
[in]errorA tpcpp::RuntimeError instance.

Definition at line 93 of file Interpreter.cpp.

◆ setVariable()

void tpcpp::Interpreter::setVariable ( const std::string & name,
const Object & value )

Set a global variable.

Parameters
[in]nameThe name of the variable.
[in]valueThe value of the variable.

Definition at line 102 of file Interpreter.cpp.


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