Left vs Right recursion
Bwain| No Comments »I think I found some Spirit examples that could solve my grammar problems. I haven’t been able to implement any post expression operators recusively, such as ++, generalized functions, or dot operators. They require left recursion, which is something Spirit can’t handle. But I found some examples that can transform them to right recursion grammars.
Getting some good results. Currently I’m hacking the prefix operators, and the only postfix operator ([]) is also a hack. It would be good to get all this working.
The right recursion worked. I can create and chain post operators. That means that I can do matrix[i][j][k], things like that. Also, the way I was linking parameters subtypes using ‘prm(”opName.i”)’, which is a hack. Now I can do ‘prm(”opName”)[i]’, which is what i originally intended. I have to verify that the []operator works properly with the smd code generation. Post-increment operators (++,–) are now possible.
Another things that got taken care of, is the fact that my previous method for handling [] never allowed for an expression, or a varying index argument. I would have found this out eventually, so I’m glad I found it now. Promoting the [] to a full blown operator was the only way to move forward.
vector[i] = 1.23 works.
I had some trouble with the pre-post operator precedence. So ++p[0] was evaluated as (++p)[0] instead of ++(p[0]). This gives the wrong results since we want to increment the first element of p, not increment the entire vector, then return the first element. But that works now.
The remaining thing is whether I can get the callable chaining, methods, etc. to play nicely with the existing function calling mechanism I have in place. Hopefully not….
As a first test, I was able to implement callable functions on complex numbers. Deciding where to hook in the functionality went back and forth for a bit. First, I bundled it with spa::Value, but it ended up being bundled with the spa::Type. It ended up being a neater implementation, and I had to change fewer header files.
Methods work. So I got z(10.)(20.).abc(-3) to parse and execute correctly.
Members work. z.re = z.im = z[0] works.
To re-iterate how to do this, we call spa::setMethodCtor and spa::setMemberCtor for defining methods/members for an object type. The symbolTable calls spa::getTypeMethod and spa::getTypeMember on the object type for resolving.


