Filters

Mar 21, 2008 at 3:24 PM
First of all I'd like to thank the developers for making this great software, i've always been confused by this stuff but now I can manage it easily.

I've been developing a grammer for parsing advanced expessions, based on the template provided. I found it easy to add features but now I've run into a problem and I think filters would solve this problem, but I don't know how to proceed.

I have a MultipliedVar NonTerminal for handling productions such as: 3X, 3sin(x) and 13(4x + 7)

Using the 3X example, I need a filter to reduce each MultipliedVar terminal like this,

MultipliedVar
3, number
X, variable

into this:

Expr
3, number
*
X, variable

Any suggestions?
Coordinator
Mar 21, 2008 at 4:43 PM
Hi
I think the best way to do this is to create a filter that expands your MultipliedVar token into 3 tokens. The constituent tokens may be prepared by MultipliedVar.TryMatch method, and saved into token.Attributes dictionary. Yea, I know, it looks ugly, but that's the only way I see it for now.
The better way would be to return 3 tokens from TryMatch method directly, while current structure allows only a single one. I was thinking about scenario like this before, and I think the best way to accomodate this is to introduce a MultiToken - a special Token that is a container for several tokens. TryMatch can return this token and Scanner would recognize it and "expand" automatically, without any extra filters. This thing is on my to-do list, I'll move it up, so expect it soon. For now - writing a special filter is the only way.
thanks
Roman
Mar 21, 2008 at 9:54 PM
Thanks for the reply, I guess I will wait for the next version of Irony then.