Data::Typed::Expression - Parsing typed expressions
Version 0.005
use Data::Typed::Expression; use Data::Typed::Expression::Env; my $env = Data::Typed::Expression::Env->new({ vertex => { id => 'int', lon => 'double', lat => 'double' }, arc => { from => 'vertex', to => 'vertex', cost => 'double' }, graph => { arcs => 'arc[]', vertices => 'vertex[]' }, 'int' => undef, 'double' => undef }, { G => 'graph', i => 'int' }); my $expr = Data::Typed::Expression->new('G.arcs[G.v[i]+1]'); $env->validate($expr);
When I was writing a LaTeX paper on mathematical model of an optimization problem, I was in a need to use C-like expressions to illustrate ideas I was writing about. I felt really uncomfortable beacuse I couldn't easily validate the expressions I was using. Hence this module.
The module can parse standard C expressions (or rather a small subset of them) and validate them in the context of some types. Validation step checks if the types of values on which artihmetics is performed are numeric, whether array indices are of int type and if compund types (struct-s) have components referenced by the expression.
int
struct
The idea was born on this Perlmonks thread: http://perlmonks.org/?node_id=807424.
Creates a new expression object. The only argument is a string containing expression to be parsed.
The method dies if the expression can't be parsed (i.e. is invalid or to complicated).
Usefulness of an object itself is limited. Pass the object to e.g. Data::Typed::Expression::Env to check type correctness of the expression.
To install Data::Typed::Expression, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Typed::Expression
CPAN shell
perl -MCPAN -e shell install Data::Typed::Expression
For more information on module installation, please visit the detailed CPAN module installation guide.