--- a/cmajor++/Cm/Cm.Parser/CompilationUnit.cpp
+++ b/cmajor++/Cm/Cm.Parser/CompilationUnit.cpp
@@ -12,6 +12,7 @@
 #include <Cm.Parser/Enumeration.hpp>
 #include <Cm.Parser/Typedef.hpp>
 #include <Cm.Parser/Class.hpp>
+#include <Cm.Parser/Delegate.hpp>
 #include <Cm.Parser/Concept.hpp>
 
 namespace Cm { namespace Parser {
@@ -532,6 +533,8 @@
         typedefDefinitionNonterminalParser->SetPreCall(PreCallPtr(new MemberPreCall<DefinitionRule>(this, &DefinitionRule::PreTypedefDefinition)));
         NonterminalParserPtr classDefinitionNonterminalParser = GetNonterminal("ClassDefinition");
         classDefinitionNonterminalParser->SetPreCall(PreCallPtr(new MemberPreCall<DefinitionRule>(this, &DefinitionRule::PreClassDefinition)));
+        NonterminalParserPtr delegateDefinitionNonterminalParser = GetNonterminal("DelegateDefinition");
+        delegateDefinitionNonterminalParser->SetPreCall(PreCallPtr(new MemberPreCall<DefinitionRule>(this, &DefinitionRule::PreDelegateDefinition)));
         NonterminalParserPtr conceptDefinitionNonterminalParser = GetNonterminal("ConceptDefinition");
         conceptDefinitionNonterminalParser->SetPreCall(PreCallPtr(new MemberPreCall<DefinitionRule>(this, &DefinitionRule::PreConceptDefinition)));
     }
@@ -561,6 +564,11 @@
         stack.push(ObjectPtr(new ValueObject<ParsingContextPtr>(context->ctx)));
     }
     void PreClassDefinition(ObjectStack& stack)
+    {
+        stack.push(ObjectPtr(new ValueObject<Cm::Core::ScopePtr>(context->enclosingScope)));
+        stack.push(ObjectPtr(new ValueObject<ParsingContextPtr>(context->ctx)));
+    }
+    void PreDelegateDefinition(ObjectStack& stack)
     {
         stack.push(ObjectPtr(new ValueObject<Cm::Core::ScopePtr>(context->enclosingScope)));
         stack.push(ObjectPtr(new ValueObject<ParsingContextPtr>(context->ctx)));
@@ -1023,6 +1031,68 @@
     ContextPtr context;
 };
 
+class CompilationUnitGrammar::DelegateDefinitionRule : public Rule
+{
+public:
+    DelegateDefinitionRule(const std::string& name_, ScopePtr enclosingScope_, ParserPtr definition_):
+        Rule(name_, enclosingScope_, definition_), contextStack(), context()
+    {
+        AddInheritedAttribute(AttrOrVariable("Cm::Core::ScopePtr", "enclosingScope"));
+        AddInheritedAttribute(AttrOrVariable("ParsingContextPtr", "ctx"));
+    }
+    virtual void Enter(ObjectStack& stack)
+    {
+        contextStack.push(context);
+        context = ContextPtr(new Context());
+        context->ctx = *std::static_pointer_cast<ValueObject<ParsingContextPtr>>(stack.top());
+        stack.pop();
+        context->enclosingScope = *std::static_pointer_cast<ValueObject<Cm::Core::ScopePtr>>(stack.top());
+        stack.pop();
+    }
+    virtual void Leave(ObjectStack& stack, bool matched)
+    {
+        context = contextStack.top();
+        contextStack.pop();
+    }
+    virtual void Link()
+    {
+        ActionParserPtr a0ActionParser = GetAction("A0");
+        a0ActionParser->SetAction(ParsingActionPtr(new MemberParsingAction<DelegateDefinitionRule>(this, &DelegateDefinitionRule::A0Action)));
+        NonterminalParserPtr delegateNonterminalParser = GetNonterminal("Delegate");
+        delegateNonterminalParser->SetPreCall(PreCallPtr(new MemberPreCall<DelegateDefinitionRule>(this, &DelegateDefinitionRule::PreDelegate)));
+        delegateNonterminalParser->SetPostCall(PostCallPtr(new MemberPostCall<DelegateDefinitionRule>(this, &DelegateDefinitionRule::PostDelegate)));
+    }
+    void A0Action(const std::string& match, const std::string& content, const Position& position, const std::string& fileName, bool& pass)
+    {
+        context->fromDelegate->AddToScope();
+        context->ctx->GetCompilationUnit()->AddObject(context->fromDelegate);
+    }
+    void PreDelegate(ObjectStack& stack)
+    {
+        stack.push(ObjectPtr(new ValueObject<Cm::Core::ScopePtr>(context->enclosingScope)));
+        stack.push(ObjectPtr(new ValueObject<ParsingContextPtr>(context->ctx)));
+    }
+    void PostDelegate(ObjectStack& stack, bool matched)
+    {
+        if (matched)
+        {
+            context->fromDelegate = *std::static_pointer_cast<ValueObject<DelegateTypePtr>>(stack.top());
+            stack.pop();
+        }
+    }
+private:
+    struct Context
+    {
+        Context(): enclosingScope(), ctx(), fromDelegate() {}
+        Cm::Core::ScopePtr enclosingScope;
+        ParsingContextPtr ctx;
+        DelegateTypePtr fromDelegate;
+    };
+    typedef std::shared_ptr<Context> ContextPtr;
+    std::stack<ContextPtr> contextStack;
+    ContextPtr context;
+};
+
 class CompilationUnitGrammar::ConceptDefinitionRule : public Rule
 {
 public:
@@ -1112,30 +1182,36 @@
         grammar3 = Cm::Parser::ConstantGrammar::Create(parsingDomain);
     }
     AddGrammarReference(grammar3);
-    GrammarPtr grammar4 = parsingDomain->GetGrammar("Cm.Parser.EnumerationGrammar");
+    GrammarPtr grammar4 = parsingDomain->GetGrammar("Cm.Parser.DelegateGrammar");
     if (!grammar4)
     {
-        grammar4 = Cm::Parser::EnumerationGrammar::Create(parsingDomain);
+        grammar4 = Cm::Parser::DelegateGrammar::Create(parsingDomain);
     }
     AddGrammarReference(grammar4);
-    GrammarPtr grammar5 = parsingDomain->GetGrammar("Cm.Parser.FunctionGrammar");
+    GrammarPtr grammar5 = parsingDomain->GetGrammar("Cm.Parser.EnumerationGrammar");
     if (!grammar5)
     {
-        grammar5 = Cm::Parser::FunctionGrammar::Create(parsingDomain);
+        grammar5 = Cm::Parser::EnumerationGrammar::Create(parsingDomain);
     }
     AddGrammarReference(grammar5);
-    GrammarPtr grammar6 = parsingDomain->GetGrammar("Cm.Parser.IdentifierGrammar");
+    GrammarPtr grammar6 = parsingDomain->GetGrammar("Cm.Parser.FunctionGrammar");
     if (!grammar6)
     {
-        grammar6 = Cm::Parser::IdentifierGrammar::Create(parsingDomain);
+        grammar6 = Cm::Parser::FunctionGrammar::Create(parsingDomain);
     }
     AddGrammarReference(grammar6);
-    GrammarPtr grammar7 = parsingDomain->GetGrammar("Cm.Parser.TypedefGrammar");
+    GrammarPtr grammar7 = parsingDomain->GetGrammar("Cm.Parser.IdentifierGrammar");
     if (!grammar7)
     {
-        grammar7 = Cm::Parser::TypedefGrammar::Create(parsingDomain);
+        grammar7 = Cm::Parser::IdentifierGrammar::Create(parsingDomain);
     }
     AddGrammarReference(grammar7);
+    GrammarPtr grammar8 = parsingDomain->GetGrammar("Cm.Parser.TypedefGrammar");
+    if (!grammar8)
+    {
+        grammar8 = Cm::Parser::TypedefGrammar::Create(parsingDomain);
+    }
+    AddGrammarReference(grammar8);
 }
 
 void CompilationUnitGrammar::CreateRules()
@@ -1147,6 +1223,7 @@
     AddRuleLink(RuleLinkPtr(new RuleLink("Identifier", std::static_pointer_cast<Grammar>(GetPtr()), "IdentifierGrammar.Identifier")));
     AddRuleLink(RuleLinkPtr(new RuleLink("QualifiedId", std::static_pointer_cast<Grammar>(GetPtr()), "IdentifierGrammar.QualifiedId")));
     AddRuleLink(RuleLinkPtr(new RuleLink("Class", std::static_pointer_cast<Grammar>(GetPtr()), "ClassGrammar.Class")));
+    AddRuleLink(RuleLinkPtr(new RuleLink("Delegate", std::static_pointer_cast<Grammar>(GetPtr()), "DelegateGrammar.Delegate")));
     AddRuleLink(RuleLinkPtr(new RuleLink("Concept", std::static_pointer_cast<Grammar>(GetPtr()), "ConceptGrammar.Concept")));
     AddRuleLink(RuleLinkPtr(new RuleLink("spaces_and_comments", std::static_pointer_cast<Grammar>(GetPtr()), "Soul.Parsing.stdlib.spaces_and_comments")));
     AddRule(RulePtr(new CompilationUnitRule("CompilationUnit", GetScope(),
@@ -1195,12 +1272,14 @@
                     ParserPtr(new AlternativeParser(
                         ParserPtr(new AlternativeParser(
                             ParserPtr(new AlternativeParser(
-                                ParserPtr(new NonterminalParser("NamespaceDefinition", "NamespaceDefinition", 2)),
-                                ParserPtr(new NonterminalParser("FunctionDefinition", "FunctionDefinition", 2)))),
-                            ParserPtr(new NonterminalParser("ConstantDefinition", "ConstantDefinition", 2)))),
-                        ParserPtr(new NonterminalParser("EnumerationDefinition", "EnumerationDefinition", 2)))),
-                    ParserPtr(new NonterminalParser("TypedefDefinition", "TypedefDefinition", 2)))),
-                ParserPtr(new NonterminalParser("ClassDefinition", "ClassDefinition", 2)))),
+                                ParserPtr(new AlternativeParser(
+                                    ParserPtr(new NonterminalParser("NamespaceDefinition", "NamespaceDefinition", 2)),
+                                    ParserPtr(new NonterminalParser("FunctionDefinition", "FunctionDefinition", 2)))),
+                                ParserPtr(new NonterminalParser("ConstantDefinition", "ConstantDefinition", 2)))),
+                            ParserPtr(new NonterminalParser("EnumerationDefinition", "EnumerationDefinition", 2)))),
+                        ParserPtr(new NonterminalParser("TypedefDefinition", "TypedefDefinition", 2)))),
+                    ParserPtr(new NonterminalParser("ClassDefinition", "ClassDefinition", 2)))),
+                ParserPtr(new NonterminalParser("DelegateDefinition", "DelegateDefinition", 2)))),
             ParserPtr(new NonterminalParser("ConceptDefinition", "ConceptDefinition", 2)))))));
     AddRule(RulePtr(new NamespaceDefinitionRule("NamespaceDefinition", GetScope(),
         ParserPtr(new NonterminalParser("Namespace", "Namespace", 2)))));
@@ -1234,6 +1313,9 @@
     AddRule(RulePtr(new ClassDefinitionRule("ClassDefinition", GetScope(),
         ParserPtr(new ActionParser("A0",
             ParserPtr(new NonterminalParser("Class", "Class", 2)))))));
+    AddRule(RulePtr(new DelegateDefinitionRule("DelegateDefinition", GetScope(),
+        ParserPtr(new ActionParser("A0",
+            ParserPtr(new NonterminalParser("Delegate", "Delegate", 2)))))));
     AddRule(RulePtr(new ConceptDefinitionRule("ConceptDefinition", GetScope(),
         ParserPtr(new ActionParser("A0",
             ParserPtr(new NonterminalParser("Concept", "Concept", 2)))))));