|
Boost : |
From: Larry Evans (cppljevans_at_[hidden])
Date: 2005-03-06 15:54:27
On 03/06/2005 07:59 AM, Pavel Chikulaev wrote:
> I'm currently working on library "Lazy".
>
> Library description:
> Library eases creation of classes which needs lazy evalution and n-arity
> operators
[snip]
> Library features are:
> * n-arity operators support;
> * operator aliasing, such as a + -b will be computed as a - b;
[snip]
> Library's sample usage:
[snip]
> class Matrix
> {
> LAZY_CLASS(Matrix)
> static lazy::type<Matrix> Matrix_; //Similar to Andrei Alexandrescu's
[snip]
> Matrix(LAZY_OP(Matrix_ + Matrix_ * Matrix_)); //ternary operator
>
> //Now enable operators
> LAZY_ENABLE_OP(Matrix_ = Matrix_ + Matrix_);
> LAZY_ENABLE_OP(Matrix_ = Matrix_ * Matrix_);
> LAZY_ENABLE_OP(Matrix_ = -Matrix_);
> LAZY_ENABLE_OP(Matrix_ = Matrix_ + Matrix_ * Matrix_);
>
> //Actually we can make declaration of lazy operators and enabling them
> using only one macro e.g.
> LAZY_CONSTUCTOR(Matrix_ = Matrix_ * Matrix_ * Matrix_);
>
[snip]
> Is there any need of such library?
Maybe. If "aliasing" can convert (a+b+c)*x to a*x+b*x+c*x then maybe
it can be used to "normalize" a grammar:
X = ('a'|'b'|'c') X | 'd' -> X = 'a'X | 'b'X | 'c'X | 'd'
which would enable, I think, conversion to a boolean matrix
representation of the First relation of the grammar:
X 'a' 'b' 'c' 'd'
X 0 1 1 1 1
'a' 0 0 0 0 0
'b' 0 0 0 0 0
'c' 0 0 0 0 0
'd' 0 0 0 0 0
and then the operator* and + could be used to maybe make a lazy
transtive closure, First^*, of this relation. Similarly, it could
be used for calculation of Last relation and and transitive closure
of the transpose of that. These are all needed by the method described
here:
http://facweb.cs.depaul.edu/tchristopher/grmanl.pdf
to generate a parser.
In addition to the above, I'd also like to see if the value
of a matrix multiplication and addition can be computed at compile
time. If so, then I'm guessing that, given enough resources,
a spirit grammar (normalized as described above) can be analyzed at
compile time and used to generate a parser with compile-time generated
look-ahead sets.
OK, maybe that's dreaming, but that's me :)
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk