.NET Framework Bookmark and Share   
 index > Microsoft Codename 'Oslo' > Output mismatch between mgx.exe and DynamicParser
 

Output mismatch between mgx.exe and DynamicParser

Given the following MGrammar:

module Demo.Employees{
language EmployeeDSL
{
syntax Main = e:Employee*
=> Employees { valuesof(e) };

syntax Employee = employeeName n:text endEmployee
=> id(n) {Name {n}};


@{Classification["Keyword"]}
token employeeName = "Name: ";

token text = ( 'A'..'Z' | 'a'..'z')+;

token endEmployee = "*";

interleave WhiteSpacing = " " | "\r" | "\n";
}
}


And this input:

Name: Bob
*
Name: Alice
*

...Both Intellipad and mgx.exe procude the following output (Intellipad does not include the module name of course):

module Demo.Employees {
Employees {
Bob {
Name => "Bob"
},
Alice {
Name => "Alice"
}
}
}

When I do thesame programmatically with DynamicParser like this:

    class Program
    {
        static void Main(string[] args)
        {
            DynamicParser parser = null;

            string fileToParse  = "EmployeeData.ed";
            string moduleName   = "Demo.Employees";
            string languageName = "EmployeeDSL";

            System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
            using (var img = MImage.LoadFromResource(assembly, "EmployeeParser.mx"))
            {
                var factory = img.ParserFactories[moduleName+ "." + languageName];
                parser = factory.Create();
                parser.GraphBuilder = new NodeGraphBuilder();
                Node root = (Node)parser.Parse(fileToParse, new ParserErrorReporter());

                // Save the graph as an m file
                string destinationFile = Path.ChangeExtension(fileToParse, "m");
                StringBuilder fullMFile = new StringBuilder();
                fullMFile.AppendFormat("module {0} ", moduleName);
                fullMFile.AppendLine("{");
                fullMFile.Append(root.WriteToString());
                fullMFile.AppendLine("}");
                File.WriteAllText(destinationFile, fullMFile.ToString());
            }
        }
    }

...the generated graph looks like the following:

module Demo.Employees {
Employees {
Bob {
Name {
'Bob'
}
},
Alice {
Name {
'Alice'
}
}
}

Again, for comparison, the mgx.exe version:

module Demo.Employees {
Employees {
Bob {
Name => "Bob"
},
Alice {
Name => "Alice"
}
}
}


Whatam I missing here?

  • Edited byslyVx Friday, July 17, 2009 9:53 AM
  • Edited byslyVx Friday, July 17, 2009 9:55 AM
  •  
slyVx
Ah, yes. I've seen issues like this as well. The graph object model is in the process of being revised. This sort of thing should get much more consistent in a future release.

Formerly, I believe => and {} were identical. Now, they're not. Ithink I had better results if I used => instead of {} in my grammar. (Apparently, that way there's less guesswork in determining a labeled value vs. a successor) Try something like the following:

module Demo.Employees{
language EmployeeDSL
{
syntax Main = e:Employee*
=> Employees { valuesof(e) };

syntax Employee = employeeName n:text endEmployee
=> id(n) {Name => n};

@{Classification["Keyword"]}
token employeeName = "Name: ";

token text = ( 'A'..'Z' | 'a'..'z')+;

token endEmployee = "*";

interleave WhiteSpacing = " " | "\r" | "\n";
}
}

Let me know if that helps.

For more details on the new graph model, check out the paper by Clemens Szyperski (http://msdn.microsoft.com/en-us/library/dd878360.aspx).

David

dmatson
Ah, yes. I've seen issues like this as well. The graph object model is in the process of being revised. This sort of thing should get much more consistent in a future release.

Formerly, I believe => and {} were identical. Now, they're not. Ithink I had better results if I used => instead of {} in my grammar. (Apparently, that way there's less guesswork in determining a labeled value vs. a successor) Try something like the following:

module Demo.Employees{
language EmployeeDSL
{
syntax Main = e:Employee*
=> Employees { valuesof(e) };

syntax Employee = employeeName n:text endEmployee
=> id(n) {Name => n};

@{Classification["Keyword"]}
token employeeName = "Name: ";

token text = ( 'A'..'Z' | 'a'..'z')+;

token endEmployee = "*";

interleave WhiteSpacing = " " | "\r" | "\n";
}
}

Let me know if that helps.

For more details on the new graph model, check out the paper by Clemens Szyperski (http://msdn.microsoft.com/en-us/library/dd878360.aspx).

David

dmatson
Yes! It worked.
Perfect.
slyVx

You can use google to search for other answers

Custom Search

More Threads

• timestamp columns
• Moving from Janurary CTP to May
• What is "A" grammar ?
• Using Model Image file
• Grammar for CSharp?
• Oslo, ready for take off?
• Oslo usage for two-way binding project
• Compiled Grammar Sizes - Jan to May
• Compiling MGrammar as a resource
• Example from MIX09 presentation issue