To get the parsing tree (a unique_ptr<logic::Expression>
object) you are to do as following:
auto tokens = logic::Lexer(data, size).Tokenize();
auto expression = logic::Parser(tokens.data()).Parse(/*data*/);
Optional parameter data
in logic::Parser::Parse
is used for debugging purposes only.
logic::Expression
objects support the following methods:
-
bool Evaluate(const map<string, bool>&) const;
Evaluates the expression with the given context.
-
void ToString(ostream&) const;
Sends the string representation to the output stream.
-
unique_ptr<logic::Expression> Clone() const;
Returns a deep copy of an object.
-
void Traverse(logic::Visitor*) const;
Traverses the parsing tree using the Visitor design pattern.
There are two built-in visitors:
logic::DependencyVisitor
Has a methodGetResult() -> set<string>
that returns names of all variables used.logic::SubsetVisitor
Has a methodGetResult() -> vector<const logic::Expression*>
that returns all the subexpressions (without repetitions).
For more information, see file main.cpp
.