Irony in SL

Apr 20, 2009 at 10:44 PM

in my current project I need to parse a specific file format and I thought give Irony a try. It was quite easy to define the grammar in Irony and to test it via the explorer. The problem is that I need the parser in Silverlight. So I started to copy the Irony code into a SL library. I had to fix some problems where methods are not available or had different signatures but not big issues. The problem is when I instantiate a compiler with a given grammar it takes forever. I could drill down the problem to the PropagateLookaheads() method in the ParserControlDataBuilder class.
The currentList gets never a zero items and the while loop runs forever. I tried with my own grammar as well as the calcgrammar from the tutorial project.
Any ideas? Or maybe a irony dll compiled against the SL runtime?


private void PropagateLookaheads() {
      LRItemList currentList = new LRItemList();
      //first collect all items
      foreach (ParserState state in Data.States)
      //Main loop - propagate until done
      while (currentList.Count > 0) {
        LRItemList newList = new LRItemList();
        foreach (LRItem item in currentList) {
          if (item.NewLookaheads.Count == 0) continue;
          int oldCount = item.Lookaheads.Count;
          if (item.Lookaheads.Count != oldCount) {
            foreach (LRItem targetItem in item.PropagateTargets) {
            }//foreach targetItem
        }//foreach item
        currentList = newList;
Apr 21, 2009 at 2:03 AM
The only guess I can make is that during "refactoring" for SL you changed item.Lookaheads or item.NewLookaheads from Hashset/StringSet to List<>. In this case you for sure will get ever growing lists...
Apr 21, 2009 at 6:15 AM
Good guess! I changed at some point a HasshSet<> to a List<> because there is no HashSet in SL. Than I have to implement my own SL HashSet<>.
I will check this and give a feedback here.

Many thanks!!!
Apr 21, 2009 at 6:33 AM
Instead of reimplementing hashset, just use Dictionary<string, int>; you'll be using just Keys set of the dictionary; when adding string "abc" to the dict, add it as value 1 with key "abc"; then all works just as with hashsets
Apr 21, 2009 at 2:40 PM
you might want to consider a different approach.

so what happens when the next version of irony comes out... would you merge again all the changes? - sounds like a lot of work IMHO

Instead i would consider exposing a wcf service that provides the parser on the server side and returns the evaluated input back to silverlight.

Apr 21, 2009 at 4:46 PM
Edited Apr 21, 2009 at 8:20 PM

I already thought about this approach in case I couldn’t fix theproblem. But in my case I just use Irony for parsing a string format fordescribing trees. A kind of overkill but this time I thought I use my knowledgefrom my study and use a grammar to get a clean and robust parser instead ofjuggling with recursive string operations. When you look at the grammar it’squite easy to implement it in Irony but it can be a mess with handcrafted parser.

   Tree --> Subtree ";"

   Subtree --> Leaf | Internal

   Leaf --> Name

   Internal --> "(" BranchList ")" Name

   BranchList --> Branch | Branch "," BranchList

   Branch --> Subtree Length

   Name --> empty | string

   Length --> empty | ":" number

Btw, how can I define action in order to build object tree whilea string is parsed by Irony. Whenever a Branch is found I get a inner node ofthe tree and leaf of course when Leaf was found.