In particular, the shunt function is doing all of the heavy lifting and is where the change ought to be made. (The tree can easily be built in evalPostfix.)

Now, I've spent the last few hours looking for a tutorial explaining how to do this, but haven't had any luck. I want to say that I need to be keeping track of how many hanging expressions I have, and if I would do anything that would create three, insert a '&', but that seems inefficient and I'm certain there is a better way. If anyone can see how to make a change to the code or could point me in the right direction, I would much appreciate it.

1 Answer
1

The shunting yard algorithm is mainly designed to handle converting infix operators to postfix operators. The two complications are that the regular expression syntax already has a postfix operator *, and that the infix concatenation operators are implicit. The combination of these makes the parsing annoying.

How does "abcd" look with infix &? It is a&b&c&d. Should this be postfix ab&c&d& or abcd&&&? The first is left-associative and the second is right-associative. I claim the second is more proper for parsing regular expressions.

Now, each of the a,b,c, or d might be a regular expression in parenthesis, and each might be followed by a '*'.

I will see about enhancing your code to add the &...

Update: Your code is wrong on

*Main> toPostfix' "a|bcd"
"abcd|"

I cannot easily fix bugs and extend it to add &, so I give up for now.

After spending some more time on this, I think it may make more sense just to make the shunting-yard algorithm handle explicit '&'s and create a new function that figures out where to insert them. That's still a tricky problem (and I'm not quite sure how to do it), but it seems far more tractable.
–
Ceasar BautistaApr 28 '12 at 18:37