June Meeting - Summary of DSL's & MGrammar Talk

Last night's presentation from Simon Cuce was fantastic and a great geek-out session. A big thanks once again to Simon for coming along and sharing his knowledge and passion of DSL's and MGrammar with the group. And don't forget to keep and eye out for Martin Fowler's book on DSL's :)

The following is a list of resources provided by Simon for anyone interested in learning more:


Videos
Pages
Sample Code

More Links

Also as promised the code from Simon's presentation:

MGrammar Sample Code
  1. module ConsoleApplication2
  2. {
  3.     language Language1
  4.     {
  5.            syntax Main=  a:List(DomainName) b:List(EmailDetails)  => {Domains [valuesof(a)], valuesof(b)};
  6.         
  7.           syntax EmailDetails =(a:EmailAddress b:EmailFullname => {Address {a}, Fullname {b}})
  8.            | (a:EmailAddress c:EmailAlias b:EmailFullname => {Address {a}, Fullname {b}, Alias {c}});
  9.         
  10.         syntax EmailAddress = Email a:NameWithDot => a;
  11.         syntax EmailFullname = Fullname b:QuotedName => b;
  12.         syntax EmailAlias = Alias c:NameWithDot => c;
  13.         
  14.           syntax DomainName = Domain a:NameWithDot =>a;
  15.         
  16.         syntax List(element) = e:element | es:List(element) e:element => [valuesof(es),e];
  17.        
  18.         
  19.            interleave whitespace = '\t' | ' ' | '\r' | '\n';
  20.     
  21.          @{Classification["Keyword"]} token Begin = "Begin";
  22.          @{Classification["Keyword"]} token End = "End";
  23.          @{Classification["Keyword"]} token Domain = "Domain";
  24.          @{Classification["Keyword"]} token Email = "Email";
  25.          @{Classification["Keyword"]} token Fullname = "Fullname";
  26.          @{Classification["Keyword"]} token Alias = "Alias";
  27.     
  28.     
  29.        token TextEscape = '\\"';
  30.        token TextCharacter = !( '"' ) | TextEscape | '_';
  31.        token TextCharacters = TextCharacter*;
  32.       
  33.        @{Classification["String"]} token QuotedName = '"' TextCharacters '"';
  34.     
  35.         token Name = ('A'..'Z'| 'a'..'z')+;
  36.         token NameWithDot = (Name | "." | DecimalDigit)+;
  37.           token DecimalDigit ='0'..'9';
  38.     
  39.     }
  40. }


Compiler Code in C#
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.M;
  6. using System.Reflection;
  7. using System.Dataflow;
  8.  
  9. namespace ConsoleApplication2
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.             using (var image = MImage.LoadFromAssembly(Assembly.GetExecutingAssembly()))
  17.             {
  18.  
  19.                 var language = image.ParserFactories["ConsoleApplication2.Language1"].Create();
  20.  
  21.                 language.GraphBuilder = new NodeGraphBuilder();
  22.  
  23.                 Node root = (Node)language.Parse(@"..\..\TextFile1.txt", ErrorReporter.Standard);
  24.  
  25.                 foreach (var item in root.ViewAllNodes())
  26.                 {
  27.                     if (item.Brand.Text == "Domains")
  28.                     {
  29.                         Console.WriteLine("Domains");
  30.  
  31.                         foreach (var i in item.Edges)
  32.                         {
  33.                             Console.WriteLine(i.Node.AtomicValue);
  34.                         }
  35.  
  36.                     }
  37.                     else if (item.Brand.Text == "EmailDetails")
  38.                     {
  39.                         Console.WriteLine("Emails");
  40.  
  41.                         foreach (var i in item.Edges)
  42.                         {
  43.                             foreach (var j in i.Node.Edges)
  44.                             {
  45.                                 if (j.Node.Brand.Text == "Address")
  46.                                 { Console.WriteLine("Address " + j.Node.Edges.First().Node.AtomicValue); }
  47.                                 else if (j.Node.Brand.Text == "Fullname")
  48.                                 { Console.WriteLine("Fullname " + j.Node.Edges.First().Node.AtomicValue); }
  49.                                 else if (j.Node.Brand.Text == "Alias")
  50.                                 { Console.WriteLine("Alias " + j.Node.Edges.First().Node.AtomicValue); }
  51.                             }
  52.                         }
  53.  
  54.  
  55.                     }
  56.  
  57.                 }
  58.  
  59.                 Console.WriteLine("Code Compiled");
  60.  
  61.             }
  62.             Environment.Exit(0);
  63.  
  64.         }
  65.     }
  66. }

Update (29/06/10):

David Burela who filmed Simon's presentation has uploaded the video to his blog.
Nice one, thanks for that David.

June Meeting - DSL's

This month we're having a presentation from Dr Simon Cuce on DSL's.


Simon will explore the hidden gem within the SQL Server Modelling tool (formally Olso), called MGrammer. This is a language to create languages in a similar vain as YACC and Antlr. He will cover in detail how to build a language grammar in MGrammar, including understanding tokens, white space parsing and language syntax. As part of demo, he will show how InteilliPad can be used to speed up the creation of these grammars. The final part will be to create an actual compiler, using the newly created grammar and dealing with the resulting Abstract Syntax Tree (AST). Afterwards there will be plenty of time for Q&A.


Simon's Bio:
Dr Simon Cuce is a Melbourne software developer working mainly in the .NET area. He has worked for start ups, academia and large organisations creating unique software solutions using .NET technologies. Simon was one of the few Australians involved in the early adopter program for both .NET and the Compact Framework. Some of his claims to fame include building Australia’s first commercial XML web service for Solution 6 and the first SOAP enabled web server for Mobile Devices. Simon has a Bachelor in Computing (with Honours) and a PhD and is currently undertaking an MBA.


Don't forget that we're on for the 23rd of June and not the 30th this month. And please just click on the poll on the right to indicate if you're coming along.