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

If-then-else expression. More...

#include <syntax.hpp>

Inheritance diagram for IfExpr:
Expr GCObj

Public Member Functions

 IfExpr (GCMain &gc, const TokenPos &pos, Expr *condition, Expr *exprTrue, Expr *exprFalse)
 
const Expr & getCondition () const noexcept
 Condition of the if-then-else expression. More...
 
const Expr & getTrue () const noexcept
 
const Expr & getFalse () const noexcept
 Evaluated if condition evaluated to the atom .true.
 
virtual std::string toString () const noexcept override
 
virtual void mark (GCMain &gc) noexcept override
 Mark self, condition, exprTrue and exprFalse.
 
virtual Expr * eval (GCMain &gc, Environment &env) noexcept override
 Evaluates expression one time. More...
 
virtual Expr * replace (GCMain &gc, const std::string &name, Expr *expr) const noexcept override
 Replace all identifiers equal to name with expr. More...
 
virtual bool equals (const Expr *expr, bool exact=false) const noexcept override
 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 override
 
virtual Expr * optimize (GCMain &gc) noexcept override
 
virtual Expr * optimize (GCMain &gc, std::vector< Expr * > &exprs) noexcept
 
- 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
 
- 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

If-then-else expression.

if \<expr_condition\> then \<expr_true\> else \<expr_false\>

Member Function Documentation

◆ equals()

virtual bool IfExpr::equals ( const Expr *  expr,
bool  exact = false 
) const
overridevirtualnoexcept

Checks if this expression and expr have the same structure, Every expression has the same structure as '_' (it's called ANY after all).

Parameters
exprThe expression to compare to this.
exactIf true any must equal any and nothing else. Otherwise any is equal to anyting else.

Reimplemented from Expr.

◆ eval()

virtual Expr* IfExpr::eval ( GCMain &  gc,
Environment &  env 
)
overridevirtualnoexcept

Evaluates expression one time.

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

Reimplemented from Expr.

◆ getCondition()

const Expr& IfExpr::getCondition ( ) const
inlinenoexcept

Condition of the if-then-else expression.

Returns
Returns abitrary expression (which SHOULD evaluate to .false or .true).

◆ getIdentifiers()

virtual std::vector<std::string> IfExpr::getIdentifiers ( ) const
inlineoverridevirtualnoexcept
Returns
Returns all identifiers used in expression.

Reimplemented from Expr.

◆ getTrue()

const Expr& IfExpr::getTrue ( ) const
inlinenoexcept

Evaluated if condition evaluated not to the atom .false (but to an atom).

◆ optimize()

virtual Expr* IfExpr::optimize ( GCMain &  gc)
overridevirtualnoexcept
Returns
Returns an optimized version of this expression. If nothing was optimized, returns itself.

Reimplemented from Expr.

◆ replace()

virtual Expr* IfExpr::replace ( GCMain &  gc,
const std::string &  name,
Expr *  expr 
) const
overridevirtualnoexcept

Replace all identifiers equal to name with expr.

Parameters
gc
nameIdentifer name to replace. If name is empty, every identifier will be replaced by AnyExpr(expr_any).
exprThe expression to replaces identifiers.
Returns
Returns new expression, where matching identifiers are replaced. Returns itself if not possible (expression can't contain any identifiers) or if expression is a lambda function, where the <id> is equal to name.

Reimplemented from Expr.

◆ toString()

virtual std::string IfExpr::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: