panthema / 2007 / stx-exparser / stx-exparser-0.7 / perl-binding / README (Download File)
This directory contains a perl-binding for the STX Expression Parser
library. The binding is generated by SWIG and compiled if configure detects
perl and SWIG on your system.

The interface is encapsulated into the STX::ExpressionParser package and
consists of all public interface classes exposed by the C++ library. The main
ones are thus named
 * STX::ExpressionParser::AnyScalar,
 * STX::ExpressionParser::ParseTree and
 * STX::ExpressionParser::BasicSymbolTable.

A string can be parsed into a parse tree by
 * STX::ExpressionParser::parseExpression().

All other C++ functions and class methods are also available.

See the file exprcalc.pl for a short example program.

*** Example Runs ***

$ ./exprcalc.pl '(5 + 3) * 5.25'
Parsed.toString(): 42
Evaluated: 42

$ ./exprcalc.pl '(2 * x) + 1'
Parsed.toString(): ((2 * x) + 1)
Evaluated: 85

$ ./exprcalc.pl 'c + 1'
Parsed.toString(): (c + 1)
Cannot convert string to integer. at exprcalc.pl line 17.

$ ./exprcalc.pl 'x * 5 + 3 + EXP( LOGN(2) ) + COS( PI() / 2 )'
Parsed.toString(): ((((x * 5) + 3) + EXP(LOGN(2))) + COS((PI() / 2)))
Evaluated: 215

One function was added to the public interface of BasicSymbolTable:

# Nicer Function to add a hash of variables to the symbol table. Directly calls
# the constructor new($$hashref{$k})
sub setVariables($\%);