Code Structure
The interpreter structure is kept in the fts_expression_state_t
structure; one is allocated for each evalution, so that recursive
calls are possible; together with the structure there are a number of
functions handling the evalution machine stacks and status.
Then follows two version of the recursive parser, one for simple expressions
(as define in the syntax) fts_expression_eval_simple
and the other for full expressions fts_expression_eval_one
.
These two functions call the fts_op_eval
that apply the top of
the stack operator to the top of the stack values, popping the values
and popping the result; it implement standard C like type promotion,
plus promotion to symbols; currently implements the scope operator,
also if not supported by the variable algorithm.
Finally, the fts_expression_eval
take an object description,
interpret it as a list of expressions and evaluate them all; the result
is stored in the fts_expression_state_t
, together with
some additional information, like the variables referenced during the
evaluation, and the assignement constructs parsed at the end of the expression
list.
The fts_expression_init
initialize a number of essential tables
for operator type (unary/binary) and priority; for the sake of efficency,
symbols are reconized as operators by a kernel supported additional
flag in the symbol structure itself, that work also as an index in the
operator type and priority tables; these indexes are initialized in this function.
Related Files
-
expressions.c
-
expressions.h