Functional-lang  0.0
An example functional programming language
Public Member Functions | List of all members
FunctionExpr Class Reference

Represents a named function. More...

#include <syntax.hpp>

Inheritance diagram for FunctionExpr:
Expr GCObj

Public Member Functions

 FunctionExpr (GCMain &gc, const TokenPos &pos, const std::string &name, std::pair< std::vector< Expr * >, Expr * > fncase) noexcept
 
void calcDepth () noexcept
 
bool addCase (std::pair< std::vector< Expr * >, Expr * > fncase) noexcept
 Adds function evaluation case to function. More...
 
const std::string & getName () const noexcept
 
std::vector< std::pair< std::vector< Expr * >, Expr * > > & getFunctionCases () noexcept
 
const std::vector< std::pair< std::vector< Expr * >, Expr * > > & getFunctionCases () const noexcept
 
virtual void mark (GCMain &gc) noexcept override
 If not marked mark itself and children.
 
virtual Expr * eval (GCMain &gc, Environment &env) noexcept
 Evaluates expression one time. More...
 
virtual std::string toString () const noexcept override
 
- Public Member Functions inherited from Expr
 Expr (GCMain &gc, ExprType type, const TokenPos &pos)
 
std::size_t getDepth () const noexcept
 
bool hasLastEval () const noexcept
 
const TokenPos & getTokenPos () const noexcept
 
ExprType getExpressionType () const noexcept
 
Expr * evalWithLookup (GCMain &gc, Environment &env) noexcept
 
virtual Expr * replace (GCMain &gc, const std::string &name, Expr *expr) const noexcept
 Replace all identifiers equal to name with expr. More...
 
virtual bool equals (const Expr *expr, bool exact=false) const noexcept
 Checks if this expression and expr have the same structure, Every expression has the same structure as '_' (it's called ANY after all). More...
 
virtual std::vector< std::string > getIdentifiers () const noexcept
 
virtual Expr * optimize (GCMain &gc) noexcept
 
- Public Member Functions inherited from GCObj
 GCObj (GCMain &main) noexcept
 Initialize as not marked.
 
virtual bool isMarked (GCMain &main) const noexcept
 

Additional Inherited Members

- Protected Member Functions inherited from GCObj
virtual void markSelf (GCMain &main)
 Marks itself.
 
- Protected Attributes inherited from Expr
std::size_t depth
 
Expr * lastEval = nullptr
 

Detailed Description

Represents a named function.

Member Function Documentation

◆ addCase()

bool FunctionExpr::addCase ( std::pair< std::vector< Expr * >, Expr * >  fncase)
noexcept

Adds function evaluation case to function.

Parameters
fncase
Returns
Returns
fncase.first.size() == getFunctionCases().front().first.size()

◆ eval()

virtual Expr* FunctionExpr::eval ( GCMain &  gc,
Environment &  env 
)
virtualnoexcept

Evaluates expression one time.

Parameters
gc
envEnvironment for accessing variables.
Returns
Returns itself if nothing evaluated, otherwise a new expression.

Reimplemented from Expr.

◆ getName()

const std::string& FunctionExpr::getName ( ) const
inlinenoexcept
Returns
Returns name of function.

◆ toString()

virtual std::string FunctionExpr::toString ( ) const
inlineoverridevirtualnoexcept
Returns
Returns expression in functional-lang (the programming language to parse).

Reimplemented from Expr.


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