Reranker Framework (ReFr)
Reranking framework for structure prediction and discriminative language modeling
|
Provides an interpreter for assigning primitives and Factory-constructible objects to named variables, as well as vectors thereof. More...
#include <interpreter.H>
Public Member Functions | |
Interpreter (int debug=0) | |
Constructs a new instance with the specified debug level. More... | |
virtual | ~Interpreter () |
Destroys this interpreter. More... | |
void | Eval (const string &filename) |
Evaluates the statements in the specified text file. More... | |
void | EvalString (const string &input) |
Evaluates the statements in the specified string. More... | |
void | Eval (istream &is) |
Evaluates the statements in the specified stream. More... | |
void | PrintEnv (ostream &os) const |
void | PrintFactories (ostream &os) const |
template<typename T > | |
bool | Get (const string &varname, T *value) const |
Retrieves the value of the specified variable. More... | |
EnvironmentImpl * | env () |
Returns a pointer to the environment of this interpreter. More... | |
Provides an interpreter for assigning primitives and Factory-constructible objects to named variables, as well as vectors thereof.
The interpreter maintains an internal environment whereby previously defined variables may be used in the definition of subsequent ones. The syntax of this language extends the syntax of the Factory class, described in the documentation of the Factory::CreateOrDie method.
Statements in this language look like the following:
Additionally, the interpreter can do type inference, so all the type specifiers in the previous examples are optional. For example, one may write the following statements:
Here's an example of using the interpreter after it has read the three statements from the previous example from a file called "example.infact"
:
More formally, a statement in this language must conform to the following grammar, defined on top of the BNF syntax in the documentation of the Factory::CreateOrDie method:
<statement_list> | ::= | [ <statement> ]* | ||
<statement> | ::= | [ <type_specifier> ] <variable_name> '=' <value> ';' | ||
<type_specifier> | ::= |
| ||
<variable_name> | ::= | any valid C++ identifier | ||
<value> | ::= | <literal> | '{' <literal_list> '}' | |
The above grammar doesn’t contain rules covering C++ style line comments, but they have the same behavior in this language as they do in C++, i.e., everything after the //
to the end of the current line is treated as a comment and ignored. There are no C-style comments in this language.
Definition at line 165 of file interpreter.H.
|
inline |
Constructs a new instance with the specified debug level.
The wrapped Environment will also have the specified debug level.
Definition at line 170 of file interpreter.H.
|
inlinevirtual |
Destroys this interpreter.
Definition at line 175 of file interpreter.H.
|
inline |
Returns a pointer to the environment of this interpreter.
Crucially, this method returns a pointer to the Environment implementation class, EnvironmentImpl, so that its templated EnvironmentImpl::Get method may be invoked.
Definition at line 227 of file interpreter.H.
|
inline |
Evaluates the statements in the specified text file.
Definition at line 180 of file interpreter.H.
|
inline |
Evaluates the statements in the specified stream.
Definition at line 193 of file interpreter.H.
|
inline |
Evaluates the statements in the specified string.
Definition at line 187 of file interpreter.H.
|
inline |
Retrieves the value of the specified variable.
It is an error if the type of the specified pointer to a value object is different from the specified variable in this interpreter’s environment.
the | type of value object being set by this method |
varname | the name of the variable for which to retrieve the value |
value | a pointer to the object whose value to be set by this method |
Definition at line 217 of file interpreter.H.
|
inline |
Definition at line 199 of file interpreter.H.
|
inline |
Definition at line 203 of file interpreter.H.