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.

3 comments:

  1. Awesome blog. I would love to see true life prepared to walk, so please share more informative updates. Great work keeps it up. 300-101 exam questions

    ReplyDelete
  2. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. cfa level 1 summary notes pdf

    ReplyDelete