1 using System;
   2 using System.Collections;
   3 using System.IO;
   4 using System.Text;
   5 using Cm.Ast;
   6 
   7 // this file has been semiautomatically generated from 'D:/work/soulngcm/soulngcm/sngcmpg/CodeGeneratorVisitor.hpp' using cpp2cm version 1.0.0
   8 
   9 // this file has been semiautomatically generated from 'D:/work/soulngcm/soulngcm/sngcmpg/CodeGeneratorVisitor.cpp' using cpp2cm version 1.0.0
  10 
  11 namespace soulcm.scmpg
  12 {
  13     public class CodeGeneratorVisitor : Visitor
  14     {
  15         public CodeGeneratorVisitor(bool verbose_bool debug_bool noParserDebugSupport_const Uuid& moduleId_) : 
  16             verbose(verbose_)debug(debug_)noParserDebugSupport(noParserDebugSupport_)domain(null)currentParser(null)currentRule(null)lexerTypeName(u"System.Lex.Lexer")
  17             parentMatchNumber(0)setParentMatchNumber(-1)sn(0)currentBlock(null)currentClass(null)currentCompileUnit(null)tokenSwitch(null)stage(Stage.generateSource)
  18             moduleId(moduleId_)
  19         {
  20         }
  21         public enum Stage
  22         {
  23             generateSourcegenerateTokenSwitchbeginGenerateTokenSwitchendGenerateTokenSwitch
  24         }
  25         public override void Visit(EmptyParser& parser)
  26         {
  27             Cm.Ast.ConstructionStatementNode* matchTrueStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
  28             matchTrueStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue));
  29             currentBlock->AddStatement(matchTrueStmt);
  30         }
  31         public override void Visit(AnyParser& parser)
  32         {
  33             Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
  34             matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
  35             currentBlock->AddStatement(matchFalseStmt);
  36             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
  37             thenS->AddStatement(new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))));
  38             thenS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)));
  39             Cm.Ast.Node* endToken = new Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Lex"))
  40                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"END_TOKEN"));
  41             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.NotEqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))endToken)thenSnull);
  42             currentBlock->AddStatement(ifStmt);
  43         }
  44         public override void Visit(TokenParser& parser)
  45         {
  46             if (stage == Stage.beginGenerateTokenSwitch)
  47             {
  48                 blockStack.Push(currentBlock);
  49                 currentBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
  50                 currentBlock->AddStatement(new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))));
  51             }
  52             else if (stage == Stage.endGenerateTokenSwitch)
  53             {
  54                 Cm.Ast.CaseStatementNode* caseStmt = new Cm.Ast.CaseStatementNode(System.Lex.Span()moduleId);
  55                 caseStmt->AddCaseExpr(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdparser.TokenName()));
  56                 currentBlock->AddStatement(new Cm.Ast.BreakStatementNode(System.Lex.Span()moduleId));
  57                 caseStmt->AddStatement(currentBlock);
  58                 currentBlock = blockStack.Top();
  59                 blockStack.Pop();
  60                 tokenSwitch->AddCase(caseStmt);
  61             }
  62             else
  63             {
  64                 Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
  65                 matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
  66                 currentBlock->AddStatement(matchFalseStmt);
  67                 Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
  68                 thenS->AddStatement(new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))));
  69                 thenS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)));
  70                 Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.EqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdparser.TokenName()))thenSnull);
  71                 currentBlock->AddStatement(ifStmt);
  72             }
  73         }
  74         public override void Visit(CharParser& parser)
  75         {
  76             Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
  77             matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
  78             currentBlock->AddStatement(matchFalseStmt);
  79             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
  80             thenS->AddStatement(new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))));
  81             thenS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)));
  82             Cm.Ast.IntLiteralNode* parserChar = new Cm.Ast.IntLiteralNode(System.Lex.Span()moduleIdcast<int>(parser.Chr()));
  83             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.EqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))parserChar)thenSnull);
  84             currentBlock->AddStatement(ifStmt);
  85         }
  86         public override void Visit(StringParser& parser)
  87         {
  88             Cm.Ast.ConstructionStatementNode* matchTrueStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
  89             matchTrueStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue));
  90             currentBlock->AddStatement(matchTrueStmt);
  91             if (!parser.Str().IsEmpty())
  92             {
  93                 Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
  94                 thenS->AddStatement(new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleId
  95                     new Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))));
  96                 Cm.Ast.CompoundStatementNode* elseS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
  97                 elseS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleId
  98                     new Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")
  99                     new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse)));
 100                 elseS->AddStatement(new Cm.Ast.BreakStatementNode(System.Lex.Span()moduleId));
 101                 Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleId
 102                     new Cm.Ast.EqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleId
 103                     new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"__i"))thenSelseS);
 104                 Cm.Ast.ConstructionStatementNode* constructI = new Cm.Ast.ConstructionStatementNode(
 105                     System.Lex.Span()moduleIdnew Cm.Ast.IntNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"__i"));
 106                 constructI->SetAssignment();
 107                 Cm.Ast.IndexingNode* indexNode = new Cm.Ast.IndexingNode(System.Lex.Span()moduleId
 108                     new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdToUtf32(parser.ArrayName()))
 109                     new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"__k"));
 110                 constructI->AddArgument(indexNode);
 111                 Cm.Ast.CompoundStatementNode* actionS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 112                 actionS->AddStatement(constructI);
 113                 actionS->AddStatement(ifStmt);
 114                 Cm.Ast.ConstructionStatementNode* constructLenNode = new Cm.Ast.ConstructionStatementNode(
 115                     System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"__n"));
 116                 constructLenNode->AddArgument(new Cm.Ast.LongLiteralNode(System.Lex.Span()moduleIdparser.Str().Length()));
 117                 constructLenNode->SetAssignment();
 118                 currentBlock->AddStatement(constructLenNode);
 119                 Cm.Ast.ConstructionStatementNode* initS = new Cm.Ast.ConstructionStatementNode(
 120                     System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"__k"));
 121                 initS->AddArgument(new Cm.Ast.LongLiteralNode(System.Lex.Span()moduleId0));
 122                 initS->SetAssignment();
 123                 Cm.Ast.LessNode* cond = new Cm.Ast.LessNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"__k")
 124                     new IdentifierNode(System.Lex.Span()moduleIdu"__n"));
 125                 Cm.Ast.PrefixIncrementNode* prefixIncNode = new Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"__k"));
 126                 Cm.Ast.ExpressionStatementNode* loopS = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdprefixIncNode);
 127                 Cm.Ast.ForStatementNode* forStatementNode = new Cm.Ast.ForStatementNode(
 128                     System.Lex.Span()moduleIdinitScondloopSactionS);
 129                 currentBlock->AddStatement(forStatementNode);
 130             }
 131         }
 132         public override void Visit(CharSetParser& parser)
 133         {
 134             if (parser.Set().Inverse())
 135             {
 136                 Cm.Ast.InvokeNode* lexerPos = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Pos")));
 137                 Cm.Ast.InvokeNode* lexerEnd = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"End")));
 138                 Cm.Ast.NotEqualNode* posNotEnd = new Cm.Ast.NotEqualNode(System.Lex.Span()moduleIdlexerPoslexerEnd);
 139                 Cm.Ast.ConstructionStatementNode* matchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 140                 matchStmt->AddArgument(posNotEnd);
 141                 currentBlock->AddStatement(matchStmt);
 142                 Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 143                 thenS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse)));
 144                 thenS->AddStatement(new Cm.Ast.BreakStatementNode(System.Lex.Span()moduleId));
 145                 Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ConjunctionNode(System.Lex.Span()moduleIdnew Cm.Ast.GreaterOrEqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))new Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"range")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"first")))new Cm.Ast.LessOrEqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))new Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"range")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"last"))))thenSnull);
 146                 Cm.Ast.CompoundStatementNode* actionS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 147                 actionS->AddStatement(ifStmt);
 148                 Cm.Ast.RangeForStatementNode* rangeFor = new Cm.Ast.RangeForStatementNode(System.Lex.Span()moduleId
 149                     new Cm.Ast.ConstNode(System.Lex.Span()moduleId
 150                     new Cm.Ast.LValueRefNode(System.Lex.Span()moduleId
 151                     new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Range")))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"range")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdToUtf32(parser.ArrayName()))actionS);
 152                 currentBlock->AddStatement(rangeFor);
 153                 Cm.Ast.CompoundStatementNode* then2S = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 154                 then2S->AddStatement(new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))));
 155                 Cm.Ast.IfStatementNode* if2Stmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))then2Snull);
 156                 currentBlock->AddStatement(if2Stmt);
 157             }
 158             else
 159             {
 160                 Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 161                 matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 162                 currentBlock->AddStatement(matchFalseStmt);
 163                 Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 164                 thenS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)));
 165                 thenS->AddStatement(new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))));
 166                 thenS->AddStatement(new Cm.Ast.BreakStatementNode(System.Lex.Span()moduleId));
 167                 Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ConjunctionNode(System.Lex.Span()moduleIdnew Cm.Ast.GreaterOrEqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))new Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"range")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"first")))new Cm.Ast.LessOrEqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))new Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"range")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"last"))))thenSnull);
 168                 Cm.Ast.CompoundStatementNode* actionS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 169                 actionS->AddStatement(ifStmt);
 170                 Cm.Ast.RangeForStatementNode* rangeFor = new Cm.Ast.RangeForStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ConstNode(System.Lex.Span()moduleId
 171                     new Cm.Ast.LValueRefNode(System.Lex.Span()moduleId
 172                     new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Range")))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"range")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdToUtf32(parser.ArrayName()))actionS);
 173                 currentBlock->AddStatement(rangeFor);
 174             }
 175         }
 176         public override void Visit(OptionalParser& parser)
 177         {
 178             Cm.Ast.ConstructionStatementNode* matchTrueStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 179             matchTrueStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue));
 180             currentBlock->AddStatement(matchTrueStmt);
 181             Cm.Ast.ConstructionStatementNode* saveStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 182             saveStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetPos"))));
 183             saveStmt->SetAssignment();
 184             currentBlock->AddStatement(saveStmt);
 185             int prevSetParentMatchNumber = setParentMatchNumber;
 186             setParentMatchNumber = parentMatchNumber;
 187             Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 188             parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 189             parentMatchStmt->SetAssignment();
 190             currentBlock->AddStatement(parentMatchStmt);
 191             Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 192             Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 193             currentBlock = childBlock;
 194             parser.Child()->Accept(*this);
 195             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 196             Cm.Ast.AssignmentStatementNode* assignS = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 197             thenS->AddStatement(assignS);
 198             Cm.Ast.CompoundStatementNode* elseS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 199             Cm.Ast.InvokeNode* invoke = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"SetPos")));
 200             invoke->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 201             Cm.Ast.ExpressionStatementNode* setSaveS = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvoke);
 202             elseS->AddStatement(setSaveS);
 203             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenSelseS);
 204             childBlock->AddStatement(ifStmt);
 205             currentBlock = prevBlock;
 206             currentBlock->AddStatement(childBlock);
 207             setParentMatchNumber = prevSetParentMatchNumber;
 208         }
 209         public override void Visit(KleeneParser& parser)
 210         {
 211             Cm.Ast.ConstructionStatementNode* matchTrueStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 212             matchTrueStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue));
 213             currentBlock->AddStatement(matchTrueStmt);
 214             int prevSetParentMatchNumber = setParentMatchNumber;
 215             setParentMatchNumber = parentMatchNumber;
 216             Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 217             parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 218             parentMatchStmt->SetAssignment();
 219             currentBlock->AddStatement(parentMatchStmt);
 220             Cm.Ast.CompoundStatementNode* saveBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 221             Cm.Ast.ConstructionStatementNode* saveStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 222             saveStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetPos"))));
 223             saveStmt->SetAssignment();
 224             saveBlock->AddStatement(saveStmt);
 225             Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 226             Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 227             currentBlock = childBlock;
 228             parser.Child()->Accept(*this);
 229             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 230             Cm.Ast.AssignmentStatementNode* assignS = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 231             thenS->AddStatement(assignS);
 232             Cm.Ast.CompoundStatementNode* elseS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 233             Cm.Ast.InvokeNode* invoke = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"SetPos")));
 234             invoke->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 235             Cm.Ast.ExpressionStatementNode* setSaveS = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvoke);
 236             elseS->AddStatement(setSaveS);
 237             elseS->AddStatement(new Cm.Ast.BreakStatementNode(System.Lex.Span()moduleId));
 238             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenSelseS);
 239             childBlock->AddStatement(ifStmt);
 240             currentBlock = prevBlock;
 241             saveBlock->AddStatement(childBlock);
 242             Cm.Ast.CompoundStatementNode* whileBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 243             Cm.Ast.WhileStatementNode* whileTrue = new Cm.Ast.WhileStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)saveBlock);
 244             whileBlock->AddStatement(whileTrue);
 245             currentBlock->AddStatement(whileBlock);
 246             setParentMatchNumber = prevSetParentMatchNumber;
 247         }
 248         public override void Visit(PositiveParser& parser)
 249         {
 250             Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 251             matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 252             currentBlock->AddStatement(matchFalseStmt);
 253             int prevSetParentMatchNumber0 = setParentMatchNumber;
 254             setParentMatchNumber = parentMatchNumber;
 255             Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 256             parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 257             parentMatchStmt->SetAssignment();
 258             currentBlock->AddStatement(parentMatchStmt);
 259             Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 260             Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 261             currentBlock = childBlock;
 262             parser.Child()->Accept(*this);
 263             Cm.Ast.AssignmentStatementNode* assignS = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 264             childBlock->AddStatement(assignS);
 265             currentBlock = prevBlock;
 266             currentBlock->AddStatement(childBlock);
 267             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 268             Cm.Ast.ConstructionStatementNode* matchTrueStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 269             matchTrueStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue));
 270             thenS->AddStatement(matchTrueStmt);
 271             int prevSetParentMatchNumber1 = setParentMatchNumber;
 272             setParentMatchNumber = parentMatchNumber;
 273             Cm.Ast.ConstructionStatementNode* parentMatchStmt2 = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 274             parentMatchStmt2->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 275             parentMatchStmt2->SetAssignment();
 276             thenS->AddStatement(parentMatchStmt2);
 277             Cm.Ast.CompoundStatementNode* saveBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 278             Cm.Ast.ConstructionStatementNode* saveStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 279             saveStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetPos"))));
 280             saveStmt->SetAssignment();
 281             saveBlock->AddStatement(saveStmt);
 282             Cm.Ast.CompoundStatementNode* childBlock2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 283             Cm.Ast.CompoundStatementNode* prevBlock2 = currentBlock;
 284             currentBlock = childBlock2;
 285             parser.Child()->Accept(*this);
 286             Cm.Ast.CompoundStatementNode* thenS2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 287             Cm.Ast.AssignmentStatementNode* assignS2 = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 288             thenS2->AddStatement(assignS2);
 289             Cm.Ast.CompoundStatementNode* elseS2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 290             Cm.Ast.InvokeNode* invoke2 = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"SetPos")));
 291             invoke2->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 292             Cm.Ast.ExpressionStatementNode* setSaveS2 = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvoke2);
 293             elseS2->AddStatement(setSaveS2);
 294             elseS2->AddStatement(new Cm.Ast.BreakStatementNode(System.Lex.Span()moduleId));
 295             Cm.Ast.IfStatementNode* ifStmt2 = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenS2elseS2);
 296             childBlock2->AddStatement(ifStmt2);
 297             currentBlock = prevBlock2;
 298             saveBlock->AddStatement(childBlock2);
 299             Cm.Ast.WhileStatementNode* whileTrue = new Cm.Ast.WhileStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)saveBlock);
 300             thenS->AddStatement(whileTrue);
 301             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenSnull);
 302             currentBlock->AddStatement(ifStmt);
 303             setParentMatchNumber = prevSetParentMatchNumber1;
 304             setParentMatchNumber = prevSetParentMatchNumber0;
 305         }
 306         public override void Visit(ExpectationParser& parser)
 307         {
 308             Cm.Ast.ConstructionStatementNode* matchTrueStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 309             matchTrueStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue));
 310             currentBlock->AddStatement(matchTrueStmt);
 311             int prevSetParentMatchNumber0 = setParentMatchNumber;
 312             setParentMatchNumber = parentMatchNumber;
 313             Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 314             parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 315             parentMatchStmt->SetAssignment();
 316             currentBlock->AddStatement(parentMatchStmt);
 317             Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 318             Cm.Ast.ConstructionStatementNode* spanStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Lex"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Span"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 319             spanStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetSpan"))));
 320             spanStmt->SetAssignment();
 321             childBlock->AddStatement(spanStmt);
 322             Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 323             currentBlock = childBlock;
 324             parser.Child()->Accept(*this);
 325             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 326             Cm.Ast.AssignmentStatementNode* assignS = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 327             thenS->AddStatement(assignS);
 328             Cm.Ast.CompoundStatementNode* elseS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 329             if (parser.Child()->IsNonterminal())
 330             {
 331                 if (parser.IsNothrow())
 332                 {
 333                     elseS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)));
 334                     Cm.Ast.AssignmentStatementNode* assignS = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 335                     elseS->AddStatement(assignS);
 336                     Cm.Ast.InvokeNode* addErrorExpr = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"AddError")));
 337                     addErrorExpr->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 338                     Cm.Ast.ExpressionStatementNode* addErrorStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdaddErrorExpr);
 339                     NonterminalParser* nonterminalParser = cast<NonterminalParser*>(parser.Child());
 340                     RuleParser* rule = nonterminalParser->Rule();
 341                     ustring ruleInfo = rule->Info();
 342                     if (ruleInfo.IsEmpty())
 343                     {
 344                         ruleInfo = rule->Name();
 345                     }
 346                     addErrorExpr->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdruleInfo));
 347                     elseS->AddStatement(addErrorStmt);
 348                 }
 349                 else
 350                 {
 351                     Cm.Ast.InvokeNode* throwExpr = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"ThrowExpectationFailure")));
 352                     throwExpr->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 353                     Cm.Ast.ExpressionStatementNode* throwStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdthrowExpr);
 354                     NonterminalParser* nonterminalParser = cast<NonterminalParser*>(parser.Child());
 355                     RuleParser* rule = nonterminalParser->Rule();
 356                     ustring ruleInfo = rule->Info();
 357                     if (ruleInfo.IsEmpty())
 358                     {
 359                         ruleInfo = rule->Name();
 360                     }
 361                     throwExpr->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdruleInfo));
 362                     elseS->AddStatement(throwStmt);
 363                 }
 364             }
 365             else if (parser.Child()->IsToken())
 366             {
 367                 if (parser.IsNothrow())
 368                 {
 369                     elseS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)));
 370                     Cm.Ast.AssignmentStatementNode* assignS = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 371                     elseS->AddStatement(assignS);
 372                     Cm.Ast.InvokeNode* addErrorExpr = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"AddError")));
 373                     addErrorExpr->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 374                     Cm.Ast.ExpressionStatementNode* addErrorStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdaddErrorExpr);
 375                     ustring tokenName = cast<TokenParser*>(parser.Child())->TokenName();
 376                     Cm.Ast.InvokeNode* getTokenInfoInvoke = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetTokenName"));
 377                     getTokenInfoInvoke->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdtokenName));
 378                     addErrorExpr->AddArgument(getTokenInfoInvoke);
 379                     elseS->AddStatement(addErrorStmt);
 380                 }
 381                 else
 382                 {
 383                     Cm.Ast.InvokeNode* throwExpr = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"ThrowExpectationFailure")));
 384                     throwExpr->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 385                     Cm.Ast.ExpressionStatementNode* throwStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdthrowExpr);
 386                     ustring tokenName = cast<TokenParser*>(parser.Child())->TokenName();
 387                     Cm.Ast.InvokeNode* getTokenInfoInvoke = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetTokenName"));
 388                     getTokenInfoInvoke->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdtokenName));
 389                     throwExpr->AddArgument(getTokenInfoInvoke);
 390                     elseS->AddStatement(throwStmt);
 391                 }
 392             }
 393             else
 394             {
 395                 if (parser.IsNothrow())
 396                 {
 397                     elseS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue)));
 398                     Cm.Ast.AssignmentStatementNode* assignS = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 399                     elseS->AddStatement(assignS);
 400                     Cm.Ast.InvokeNode* addErrorExpr = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"AddError")));
 401                     addErrorExpr->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 402                     Cm.Ast.ExpressionStatementNode* addErrorStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdaddErrorExpr);
 403                     ustring parserName = parser.Child()->Name();
 404                     addErrorExpr->AddArgument(new Cm.Ast.StringLiteralNode(System.Lex.Span()moduleIdToUtf8(parserName)));
 405                     elseS->AddStatement(addErrorStmt);
 406                 }
 407                 else
 408                 {
 409                     Cm.Ast.InvokeNode* throwExpr = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"ThrowExpectationFailure")));
 410                     throwExpr->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 411                     Cm.Ast.ExpressionStatementNode* throwStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdthrowExpr);
 412                     ustring parserName = parser.Child()->Name();
 413                     throwExpr->AddArgument(new Cm.Ast.StringLiteralNode(System.Lex.Span()moduleIdToUtf8(parserName)));
 414                     elseS->AddStatement(throwStmt);
 415                 }
 416             }
 417             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenSelseS);
 418             childBlock->AddStatement(ifStmt);
 419             currentBlock = prevBlock;
 420             currentBlock->AddStatement(childBlock);
 421             setParentMatchNumber = prevSetParentMatchNumber0;
 422         }
 423         public override void Visit(GroupingParser& parser)
 424         {
 425             Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 426             matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 427             currentBlock->AddStatement(matchFalseStmt);
 428             int prevSetParentMatchNumber = setParentMatchNumber;
 429             setParentMatchNumber = parentMatchNumber;
 430             Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 431             parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 432             parentMatchStmt->SetAssignment();
 433             currentBlock->AddStatement(parentMatchStmt);
 434             Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 435             Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 436             currentBlock = childBlock;
 437             parser.Child()->Accept(*this);
 438             Cm.Ast.AssignmentStatementNode* setParentMatchStmt = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 439             childBlock->AddStatement(setParentMatchStmt);
 440             currentBlock = prevBlock;
 441             currentBlock->AddStatement(childBlock);
 442             setParentMatchNumber = prevSetParentMatchNumber;
 443         }
 444         public override void Visit(SequenceParser& parser)
 445         {
 446             Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 447             matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 448             currentBlock->AddStatement(matchFalseStmt);
 449             int prevSetParentMatchNumber0 = setParentMatchNumber;
 450             setParentMatchNumber = parentMatchNumber;
 451             Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 452             parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 453             parentMatchStmt->SetAssignment();
 454             currentBlock->AddStatement(parentMatchStmt);
 455             Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 456             Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 457             currentBlock = childBlock;
 458             parser.Left()->Accept(*this);
 459             Cm.Ast.AssignmentStatementNode* setParentMatchStmt = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 460             childBlock->AddStatement(setParentMatchStmt);
 461             currentBlock = prevBlock;
 462             currentBlock->AddStatement(childBlock);
 463             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 464             Cm.Ast.ConstructionStatementNode* matchFalseStmt2 = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 465             matchFalseStmt2->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 466             thenS->AddStatement(matchFalseStmt2);
 467             int prevSetParentMatchNumber1 = setParentMatchNumber;
 468             setParentMatchNumber = parentMatchNumber;
 469             Cm.Ast.ConstructionStatementNode* parentMatchStmt2 = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 470             parentMatchStmt2->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 471             parentMatchStmt2->SetAssignment();
 472             thenS->AddStatement(parentMatchStmt2);
 473             Cm.Ast.CompoundStatementNode* childBlock2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 474             Cm.Ast.CompoundStatementNode* prevBlock2 = currentBlock;
 475             currentBlock = childBlock2;
 476             parser.Right()->Accept(*this);
 477             Cm.Ast.AssignmentStatementNode* setParentMatchStmt2 = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 478             childBlock2->AddStatement(setParentMatchStmt2);
 479             currentBlock = prevBlock2;
 480             thenS->AddStatement(childBlock2);
 481             setParentMatchNumber = prevSetParentMatchNumber1;
 482             Cm.Ast.AssignmentStatementNode* setParentMatchStmt3 = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 483             thenS->AddStatement(setParentMatchStmt3);
 484             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenSnull);
 485             currentBlock->AddStatement(ifStmt);
 486             setParentMatchNumber = prevSetParentMatchNumber0;
 487         }
 488         public override void Visit(AlternativeParser& parser)
 489         {
 490             if (stage == Stage.generateTokenSwitch)
 491             {
 492                 parser.Left()->Accept(*this);
 493                 parser.Right()->Accept(*this);
 494             }
 495             else
 496             {
 497                 if (parser.IsTokenSwitch())
 498                 {
 499                     Stage prevStage = stage;
 500                     stage = Stage.generateTokenSwitch;
 501                     Cm.Ast.ConstructionStatementNode* posStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"pos"));
 502                     posStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetPos"))));
 503                     posStmt->SetAssignment();
 504                     currentBlock->AddStatement(posStmt);
 505                     Cm.Ast.ConstructionStatementNode* spanStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Span")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 506                     spanStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetSpan"))));
 507                     spanStmt->SetAssignment();
 508                     currentBlock->AddStatement(spanStmt);
 509                     Cm.Ast.SwitchStatementNode* switchStmt = new Cm.Ast.SwitchStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")));
 510                     Cm.Ast.SwitchStatementNode* prevTokenSwitch = tokenSwitch;
 511                     tokenSwitch = switchStmt;
 512                     parser.Left()->Accept(*this);
 513                     parser.Right()->Accept(*this);
 514                     currentBlock->AddStatement(switchStmt);
 515                     tokenSwitch = prevTokenSwitch;
 516                     stage = prevStage;
 517                 }
 518                 else
 519                 {
 520                     Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 521                     matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 522                     currentBlock->AddStatement(matchFalseStmt);
 523                     int prevSetParentMatchNumber0 = setParentMatchNumber;
 524                     setParentMatchNumber = parentMatchNumber;
 525                     Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 526                     parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 527                     parentMatchStmt->SetAssignment();
 528                     currentBlock->AddStatement(parentMatchStmt);
 529                     Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 530                     Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 531                     currentBlock = childBlock;
 532                     Cm.Ast.ConstructionStatementNode* saveStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 533                     saveStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetPos"))));
 534                     saveStmt->SetAssignment();
 535                     currentBlock->AddStatement(saveStmt);
 536                     parser.Left()->Accept(*this);
 537                     Cm.Ast.AssignmentStatementNode* setParentMatchStmt = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 538                     currentBlock->AddStatement(setParentMatchStmt);
 539                     Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 540                     int prevSetParentMatchNumber1 = setParentMatchNumber;
 541                     Cm.Ast.ConstructionStatementNode* matchFalseStmt2 = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 542                     matchFalseStmt2->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 543                     thenS->AddStatement(matchFalseStmt2);
 544                     setParentMatchNumber = parentMatchNumber;
 545                     Cm.Ast.ConstructionStatementNode* parentMatchStmt2 = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 546                     parentMatchStmt2->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 547                     parentMatchStmt2->SetAssignment();
 548                     thenS->AddStatement(parentMatchStmt2);
 549                     Cm.Ast.InvokeNode* invokeSetPos = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"SetPos")));
 550                     invokeSetPos->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 551                     Cm.Ast.ExpressionStatementNode* setPosStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeSetPos);
 552                     thenS->AddStatement(setPosStmt);
 553                     Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.NotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit")))thenSnull);
 554                     currentBlock->AddStatement(ifStmt);
 555                     Cm.Ast.CompoundStatementNode* childBlock2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 556                     Cm.Ast.CompoundStatementNode* prevBlock2 = currentBlock;
 557                     currentBlock = childBlock2;
 558                     parser.Right()->Accept(*this);
 559                     Cm.Ast.AssignmentStatementNode* setParentMatchStmt2 = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 560                     currentBlock->AddStatement(setParentMatchStmt2);
 561                     currentBlock = prevBlock2;
 562                     thenS->AddStatement(childBlock2);
 563                     setParentMatchNumber = prevSetParentMatchNumber1;
 564                     Cm.Ast.AssignmentStatementNode* setParentMatchStmt3 = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 565                     thenS->AddStatement(setParentMatchStmt3);
 566                     currentBlock = prevBlock;
 567                     currentBlock->AddStatement(childBlock);
 568                     setParentMatchNumber = prevSetParentMatchNumber0;
 569                 }
 570             }
 571         }
 572         public override void Visit(DifferenceParser& parser)
 573         {
 574             Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 575             matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 576             currentBlock->AddStatement(matchFalseStmt);
 577             int prevSetParentMatchNumber0 = setParentMatchNumber;
 578             setParentMatchNumber = parentMatchNumber;
 579             Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 580             parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 581             parentMatchStmt->SetAssignment();
 582             currentBlock->AddStatement(parentMatchStmt);
 583             Cm.Ast.ConstructionStatementNode* saveStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 584             saveStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetPos"))));
 585             saveStmt->SetAssignment();
 586             currentBlock->AddStatement(saveStmt);
 587             Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 588             Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 589             currentBlock = childBlock;
 590             parser.Left()->Accept(*this);
 591             Cm.Ast.AssignmentStatementNode* setParentMatchStmt = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 592             currentBlock->AddStatement(setParentMatchStmt);
 593             currentBlock = prevBlock;
 594             currentBlock->AddStatement(childBlock);
 595             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 596             Cm.Ast.ConstructionStatementNode* matchFalseStmt2 = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 597             matchFalseStmt2->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 598             thenS->AddStatement(matchFalseStmt2);
 599             int prevSetParentMatchNumber1 = setParentMatchNumber;
 600             setParentMatchNumber = parentMatchNumber;
 601             Cm.Ast.ConstructionStatementNode* parentMatchStmt2 = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 602             parentMatchStmt2->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 603             parentMatchStmt2->SetAssignment();
 604             thenS->AddStatement(parentMatchStmt2);
 605             Cm.Ast.CompoundStatementNode* childBlock2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 606             Cm.Ast.CompoundStatementNode* prevBlock2 = currentBlock;
 607             currentBlock = childBlock2;
 608             Cm.Ast.ConstructionStatementNode* tmpStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"tmp"));
 609             tmpStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetPos"))));
 610             tmpStmt->SetAssignment();
 611             currentBlock->AddStatement(tmpStmt);
 612             Cm.Ast.InvokeNode* invokeSetPos = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"SetPos")));
 613             invokeSetPos->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 614             Cm.Ast.ExpressionStatementNode* setPosStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeSetPos);
 615             currentBlock->AddStatement(setPosStmt);
 616             Cm.Ast.AssignmentStatementNode* setSave = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"tmp"));
 617             currentBlock->AddStatement(setSave);
 618             parser.Right()->Accept(*this);
 619             Cm.Ast.AssignmentStatementNode* setParentMatchStmt2 = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 620             currentBlock->AddStatement(setParentMatchStmt2);
 621             currentBlock = prevBlock2;
 622             thenS->AddStatement(childBlock2);
 623             setParentMatchNumber = prevSetParentMatchNumber1;
 624             Cm.Ast.CompoundStatementNode* thenS2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 625             Cm.Ast.InvokeNode* invokeSetPosSave = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"SetPos")));
 626             invokeSetPosSave->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"save"));
 627             Cm.Ast.ExpressionStatementNode* setPosSaveStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeSetPosSave);
 628             thenS2->AddStatement(setPosSaveStmt);
 629             Cm.Ast.IfStatementNode* ifStmt2 = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.NotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit")))thenS2null);
 630             thenS->AddStatement(ifStmt2);
 631             Cm.Ast.InvokeNode* invokeMatch = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"));
 632             invokeMatch->AddArgument(new Cm.Ast.NotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))));
 633             invokeMatch->AddArgument(new Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")));
 634             Cm.Ast.AssignmentStatementNode* setParentMatchStmt3 = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))invokeMatch);
 635             thenS->AddStatement(setParentMatchStmt3);
 636             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenSnull);
 637             currentBlock->AddStatement(ifStmt);
 638             setParentMatchNumber = prevSetParentMatchNumber0;
 639         }
 640         public override void Visit(ListParser& parser)
 641         {
 642             parser.Child()->Accept(*this);
 643         }
 644         public override void Visit(ActionParser& parser)
 645         {
 646             if (stage == Stage.generateTokenSwitch)
 647             {
 648                 CodeEvaluationVisitor codeEvaluationVisitor;
 649                 parser.SuccessCode()->Accept(codeEvaluationVisitor);
 650                 bool hasPass = codeEvaluationVisitor.HasPass();
 651                 if (hasPass)
 652                 {
 653                     throw Exception("token switch does not support pass");
 654                 }
 655                 if (codeEvaluationVisitor.HasReturn())
 656                 {
 657                     currentRule->SetHasReturn();
 658                 }
 659                 stage = Stage.beginGenerateTokenSwitch;
 660                 parser.Child()->Accept(*this);
 661                 bool nonterminalValue = parser.Child()->IsNonterminal();
 662                 bool ptrType = IsPtrType(currentRule->ReturnType());
 663                 ustring nonterminalName;
 664                 Cm.Ast.Node* returnType = null;
 665                 if (!ptrType)
 666                 {
 667                     returnType = currentRule->ReturnType();
 668                 }
 669                 if (nonterminalValue)
 670                 {
 671                     NonterminalParser* nt = cast<NonterminalParser*>(parser.Child());
 672                     nonterminalName = nt->Name();
 673                 }
 674                 NonterminalCountingVisitor countingVisitor(nonterminalInfos);
 675                 parser.SuccessCode()->Accept(countingVisitor);
 676                 CodeEmittingVisitor emittingVisitor(ptrTypenonterminalNamenonterminalInfosreturnTypenoParserDebugSupportcurrentRule->Name()moduleId);
 677                 parser.SuccessCode()->Accept(emittingVisitor);
 678                 Cm.Ast.CompoundStatementNode* code = emittingVisitor.GetCode();
 679                 int n = code->Statements().Count();
 680                 for (int i = 0; i < n; ++i;)
 681                 {
 682                     currentBlock->AddStatement(code->Statements().Release(i));
 683                 }
 684                 stage = Stage.endGenerateTokenSwitch;
 685                 parser.Child()->Accept(*this);
 686                 stage = Stage.generateTokenSwitch;
 687             }
 688             else
 689             {
 690                 Cm.Ast.ConstructionStatementNode* matchFalseStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 691                 matchFalseStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 692                 currentBlock->AddStatement(matchFalseStmt);
 693                 int prevSetParentMatchNumber = setParentMatchNumber;
 694                 setParentMatchNumber = parentMatchNumber;
 695                 Cm.Ast.ConstructionStatementNode* parentMatchStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.PointerNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(parentMatchNumber++))));
 696                 parentMatchStmt->AddArgument(new Cm.Ast.AddrOfNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")));
 697                 parentMatchStmt->SetAssignment();
 698                 currentBlock->AddStatement(parentMatchStmt);
 699                 Cm.Ast.CompoundStatementNode* childBlock = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 700                 Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 701                 currentBlock = childBlock;
 702                 Cm.Ast.ConstructionStatementNode* posStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.LongNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"pos"));
 703                 posStmt->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetPos"))));
 704                 posStmt->SetAssignment();
 705                 currentBlock->AddStatement(posStmt);
 706                 CodeEvaluationVisitor codeEvaluationVisitor;
 707                 parser.SuccessCode()->Accept(codeEvaluationVisitor);
 708                 if (codeEvaluationVisitor.HasReturn())
 709                 {
 710                     currentRule->SetHasReturn();
 711                 }
 712                 bool hasPass = codeEvaluationVisitor.HasPass();
 713                 bool hasSpan = codeEvaluationVisitor.HasSpan();
 714                 if (hasSpan)
 715                 {
 716                     Cm.Ast.ConstructionStatementNode* spanStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Span")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
 717                     Cm.Ast.InvokeNode* invokeLexerGetSpan = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetSpan")));
 718                     spanStmt->AddArgument(invokeLexerGetSpan);
 719                     spanStmt->SetAssignment();
 720                     currentBlock->AddStatement(spanStmt);
 721                 }
 722                 if (hasPass)
 723                 {
 724                     Cm.Ast.ConstructionStatementNode* passStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.BoolNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"pass"));
 725                     passStmt->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdtrue));
 726                     passStmt->SetAssignment();
 727                     currentBlock->AddStatement(passStmt);
 728                 }
 729                 parser.Child()->Accept(*this);
 730                 bool nonterminalValue = parser.Child()->IsNonterminal();
 731                 bool ptrType = IsPtrType(currentRule->ReturnType());
 732                 ustring nonterminalName;
 733                 Cm.Ast.Node* returnType = null;
 734                 if (!ptrType)
 735                 {
 736                     returnType = currentRule->ReturnType();
 737                 }
 738                 if (nonterminalValue)
 739                 {
 740                     NonterminalParser* nt = cast<NonterminalParser*>(parser.Child());
 741                     nonterminalName = nt->Name();
 742                 }
 743                 NonterminalCountingVisitor countingVisitor(nonterminalInfos);
 744                 parser.SuccessCode()->Accept(countingVisitor);
 745                 CodeEmittingVisitor emittingVisitor(ptrTypenonterminalNamenonterminalInfosreturnTypenoParserDebugSupportcurrentRule->Name()moduleId);
 746                 parser.SuccessCode()->Accept(emittingVisitor);
 747                 Cm.Ast.CompoundStatementNode* thenS = emittingVisitor.GetCode();
 748                 Cm.Ast.CompoundStatementNode* elseS = null;
 749                 if ((parser.FailCode() != null))
 750                 {
 751                     elseS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 752                     CodeEmittingVisitor emittingVisitor(ptrTypenonterminalNamenonterminalInfosreturnTypenoParserDebugSupportcurrentRule->Name()moduleId);
 753                     parser.FailCode()->Accept(emittingVisitor);
 754                     elseS = emittingVisitor.GetCode();
 755                 }
 756                 Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenSelseS);
 757                 currentBlock->AddStatement(ifStmt);
 758                 if (hasPass)
 759                 {
 760                     Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 761                     Cm.Ast.InvokeNode* matchFalse = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match"));
 762                     matchFalse->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 763                     thenS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")matchFalse));
 764                     Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ConjunctionNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))new Cm.Ast.NotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"pass")))thenSelseS);
 765                     currentBlock->AddStatement(ifStmt);
 766                 }
 767                 Cm.Ast.AssignmentStatementNode* setParentMatchStmt = new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"parentMatch" + ToUtf32(ToString(setParentMatchNumber))))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 768                 currentBlock->AddStatement(setParentMatchStmt);
 769                 setParentMatchNumber = prevSetParentMatchNumber;
 770                 currentBlock = prevBlock;
 771                 currentBlock->AddStatement(childBlock);
 772             }
 773         }
 774         public override void Visit(NonterminalParser& parser)
 775         {
 776             RuleParser* rule = parser.Rule();
 777             Cm.Ast.ConstructionStatementNode* ruleCallStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 778             ruleCallStmt->SetAssignment();
 779             Cm.Ast.InvokeNode* invokeRule = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdrule->Parent()->Name())new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdrule->Name())));
 780             invokeRule->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"));
 781             int n = parser.Args().Count();
 782             for (int i = 0; i < n; ++i;)
 783             {
 784                 Cm.Ast.CloneContext cloneContext;
 785                 Cm.Ast.Node* arg = parser.Args()[i]->Clone(cloneContext);
 786                 invokeRule->AddArgument(arg);
 787             }
 788             ruleCallStmt->AddArgument(invokeRule);
 789             currentBlock->AddStatement(ruleCallStmt);
 790             RuleParser* calledRule = parser.Rule();
 791             if (calledRule->ReturnType() != null)
 792             {
 793                 Cm.Ast.Node* targetType = null;
 794                 if (IsPtrType(calledRule->ReturnType()))
 795                 {
 796                     Cm.Ast.CloneContext cloneContext;
 797                     targetType = calledRule->ReturnType()->Clone(cloneContext);
 798                 }
 799                 else
 800                 {
 801                     Cm.Ast.TemplateIdNode* value = new Cm.Ast.TemplateIdNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Value"));
 802                     Cm.Ast.CloneContext cloneContext;
 803                     value->AddTemplateArgument(calledRule->ReturnType()->Clone(cloneContext));
 804                     targetType = new Cm.Ast.PointerNode(System.Lex.Span()moduleIdvalue);
 805                 }
 806                 Cm.Ast.InvokeNode* invokeReset = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdparser.Name())new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Reset")));
 807                 Cm.Ast.CastNode* castedValue = new Cm.Ast.CastNode(System.Lex.Span()moduleIdtargetTypenew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")));
 808                 invokeReset->AddArgument(castedValue);
 809                 Cm.Ast.ExpressionStatementNode* resetStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeReset);
 810                 currentBlock->AddStatement(resetStmt);
 811             }
 812         }
 813         public override void Visit(RuleParser& parser)
 814         {
 815             if (debug)
 816             {
 817                 Console.Error() << ">> " << parser.Name() << endl();
 818             }
 819             parentMatchNumber = 0;
 820             setParentMatchNumber = -1;
 821             currentRule = &parser;
 822             Specifiers specifiers = Specifiers.public_ | Specifiers.static_;
 823             if (parser.IsNothrow())
 824             {
 825                 specifiers = specifiers | Specifiers.nothrow_;
 826             }
 827             UniquePtr<Cm.Ast.MemberFunctionNode> memberFunction(new Cm.Ast.MemberFunctionNode(System.Lex.Span()moduleIdspecifiersnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")parser.Name()null));
 828             memberFunction->AddParameter(new Cm.Ast.ParameterNode(System.Lex.Span()moduleIdnew Cm.Ast.LValueRefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdlexerTypeName))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")));
 829             for (const UniquePtr<Parameter>& param : parser.Parameters())
 830             {
 831                 Cm.Ast.CloneContext cloneContext;
 832                 memberFunction->AddParameter(new Cm.Ast.ParameterNode(System.Lex.Span()moduleIdparam->type->Clone(cloneContext)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdparam->id->Str())));
 833             }
 834             Cm.Ast.CompoundStatementNode* body = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 835             memberFunction->SetBody(body);
 836             Cm.Ast.CompoundStatementNode* prevBlock = currentBlock;
 837             currentBlock = body;
 838             if (!noParserDebugSupport)
 839             {
 840                 Cm.Ast.ConditionalCompilationStatementNode* ccstmt = new Cm.Ast.ConditionalCompilationStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ConditionalCompilationPrimaryNode(System.Lex.Span()moduleIdu"DEBUG"));
 841                 Cm.Ast.ConstructionStatementNode* spanStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleId
 842                     new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Span")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"debugSpan"));
 843                 spanStmt->SetEmpty();
 844                 ccstmt->AddIfStatement(spanStmt);
 845                 Cm.Ast.ConstructionStatementNode* writeToLog = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.BoolNode(System.Lex.Span()moduleId)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"writeToLog"));
 846                 writeToLog->SetAssignment();
 847                 writeToLog->AddArgument(new Cm.Ast.NotEqualNode(System.Lex.Span()moduleIdnew Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Log")))new Cm.Ast.NullLiteralNode(System.Lex.Span()moduleId)));
 848                 ccstmt->AddIfStatement(writeToLog);
 849                 Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 850                 thenS->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"debugSpan")new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetSpan")))));
 851                 Cm.Ast.InvokeNode* invokeWriteBeginRule = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Lex"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"WriteBeginRuleToLog")));
 852                 invokeWriteBeginRule->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"));
 853                 invokeWriteBeginRule->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdparser.Name()));
 854                 Cm.Ast.ExpressionStatementNode* writeBeginRuleToLog = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeWriteBeginRule);
 855                 thenS->AddStatement(writeBeginRuleToLog);
 856                 Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"writeToLog")thenSnull);
 857                 ccstmt->AddIfStatement(ifStmt);
 858                 currentBlock->AddStatement(ccstmt);
 859             }
 860             if (parser.IsState() && parser.Id() != -1)
 861             {
 862                 Cm.Ast.ConstructionStatementNode* constructRuleGuardStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleId
 863                     new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System.Lex.RuleGuard")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"ruleGuard"));
 864                 constructRuleGuardStmt->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"));
 865                 constructRuleGuardStmt->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdToUtf32(ToString(parser.Id()))));
 866                 currentBlock->AddStatement(constructRuleGuardStmt);
 867             }
 868             for (const UniquePtr<Variable>& variable : parser.Variables())
 869             {
 870                 Cm.Ast.CloneContext cloneContext;
 871                 Cm.Ast.ConstructionStatementNode* constructLocal = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdvariable->type->Clone(cloneContext)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdvariable->id->Str()));
 872                 constructLocal->SetEmpty();
 873                 currentBlock->AddStatement(constructLocal);
 874             }
 875             nonterminalInfos.Clear();
 876             for (NonterminalParser* nonterminal : parser.Nonterminals())
 877             {
 878                 bool found = false;
 879                 for (const NonterminalInfo& info : nonterminalInfos)
 880                 {
 881                     if (info.name == nonterminal->Name())
 882                     {
 883                         found = true;
 884                         break;
 885                     }
 886                 }
 887                 if (found) continue;
 888                 RuleParser* calledRule = nonterminal->Rule();
 889                 if (calledRule->ReturnType() != null)
 890                 {
 891                     if (IsPtrType(calledRule->ReturnType()))
 892                     {
 893                         Cm.Ast.TemplateIdNode* uniquePtr = new Cm.Ast.TemplateIdNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"UniquePtr"));
 894                         Cm.Ast.CloneContext cloneContext;
 895                         uniquePtr->AddTemplateArgument(RemovePointer(calledRule->ReturnType()->Clone(cloneContext)));
 896                         Cm.Ast.ConstructionStatementNode* constructLocal = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIduniquePtrnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdnonterminal->Name()));
 897                         constructLocal->SetEmpty();
 898                         currentBlock->AddStatement(constructLocal);
 899                         nonterminalInfos.Add(NonterminalInfo(nonterminal->Name()true));
 900                     }
 901                     else
 902                     {
 903                         Cm.Ast.TemplateIdNode* value = new Cm.Ast.TemplateIdNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Value"));
 904                         Cm.Ast.CloneContext cloneContext;
 905                         value->AddTemplateArgument(calledRule->ReturnType()->Clone(cloneContext));
 906                         Cm.Ast.TemplateIdNode* uniquePtr = new Cm.Ast.TemplateIdNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"UniquePtr"));
 907                         uniquePtr->AddTemplateArgument(value);
 908                         Cm.Ast.ConstructionStatementNode* constructLocal = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIduniquePtrnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdnonterminal->Name()));
 909                         constructLocal->SetEmpty();
 910                         currentBlock->AddStatement(constructLocal);
 911                         nonterminalInfos.Add(NonterminalInfo(nonterminal->Name()false));
 912                     }
 913                 }
 914             }
 915             if (parser.Definition()->IsTokenSwitch())
 916             {
 917                 Cm.Ast.ConstructionStatementNode* constructMatch = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 918                 constructMatch->AddArgument(new Cm.Ast.BooleanLiteralNode(System.Lex.Span()moduleIdfalse));
 919                 currentBlock->AddStatement(constructMatch);
 920             }
 921             parser.Definition()->Accept(*this);
 922             if (!noParserDebugSupport)
 923             {
 924                 Cm.Ast.ConditionalCompilationStatementNode* ccstmt = new Cm.Ast.ConditionalCompilationStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ConditionalCompilationPrimaryNode(System.Lex.Span()moduleIdu"DEBUG"));
 925                 Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 926                 Cm.Ast.CompoundStatementNode* thenS2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 927                 Cm.Ast.InvokeNode* invokeWriteSuccess = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Lex"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"WriteSuccessToLog")));
 928                 invokeWriteSuccess->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"));
 929                 invokeWriteSuccess->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"debugSpan"));
 930                 invokeWriteSuccess->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdparser.Name()));
 931                 Cm.Ast.ExpressionStatementNode* writeSuccessStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeWriteSuccess);
 932                 thenS2->AddStatement(writeSuccessStmt);
 933                 Cm.Ast.CompoundStatementNode* elseS2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 934                 Cm.Ast.InvokeNode* invokeWriteFailure = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Lex"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"WriteFailureToLog")));
 935                 invokeWriteFailure->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"));
 936                 invokeWriteFailure->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdparser.Name()));
 937                 Cm.Ast.ExpressionStatementNode* writeFailureStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeWriteFailure);
 938                 elseS2->AddStatement(writeFailureStmt);
 939                 Cm.Ast.IfStatementNode* ifStmt2 = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenS2elseS2);
 940                 thenS->AddStatement(ifStmt2);
 941                 Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"writeToLog")thenSnull);
 942                 ccstmt->AddIfStatement(ifStmt);
 943                 currentBlock->AddStatement(ccstmt);
 944             }
 945             Cm.Ast.CompoundStatementNode* thenSetMatchValue = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
 946             thenSetMatchValue->AddStatement(new Cm.Ast.AssignmentStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value"))new Cm.Ast.NullLiteralNode(System.Lex.Span()moduleId)));
 947             Cm.Ast.IfStatementNode* ifNotMatchHit = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.NotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit")))thenSetMatchValuenull);
 948             currentBlock->AddStatement(ifNotMatchHit);
 949             Cm.Ast.ReturnStatementNode* returnMatch = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
 950             currentBlock->AddStatement(returnMatch);
 951             for (const NonterminalInfo& info : nonterminalInfos)
 952             {
 953                 if (info.ptrType && info.strongCount > 1)
 954                 {
 955                     Console.Out() << "warning: unique pointer value of nonterminal \'" + ToUtf8(info.name) + "\' used " + ToString(info.strongCount) + " times in semantic actions of rule \'" + ToUtf8(parser.Name()) + "\' of parser \'" + ToUtf8(parser.Parent()->Name()) << "\'" << endl();
 956                 }
 957             }
 958             if (parser.ReturnType() != null && !parser.HasReturn())
 959             {
 960                 Console.Out() << "warning: rule \'" + ToUtf8(parser.Name()) + "\' of parser \'" + ToUtf8(parser.Parent()->Name()) << "\' returns value, but no semantic action has a return statement." << endl();
 961             }
 962             currentBlock = prevBlock;
 963             currentClass->AddMember(memberFunction.Release());
 964         }
 965         public override void Visit(GrammarParser& parser)
 966         {
 967             currentParser = &parser;
 968             if (parser.Lexer().IsEmpty())
 969             {
 970                 lexerTypeName = u"System.Lex.Lexer";
 971                 Console.Out() << "warning: \'uselexer\' statement missing from \'" << ToUtf8(parser.Name()) << "\' parser." << endl();
 972             }
 973             else
 974             {
 975                 lexerTypeName = parser.Lexer();
 976             }
 977             Cm.Ast.ClassNode* prevClass = currentClass;
 978             UniquePtr<Cm.Ast.ClassNode> classNode(new Cm.Ast.ClassNode(System.Lex.Span()moduleIdSpecifiers.public_ | Specifiers.static_new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdparser.Name())null));
 979             currentClass = classNode.Get();
 980             if (parser.Main())
 981             {
 982                 if (!parser.Rules().IsEmpty())
 983                 {
 984                     const UniquePtr<RuleParser>& startRule = parser.Rules().Front();
 985                     UniquePtr<Cm.Ast.Node> returnTypeNode;
 986                     if (startRule->ReturnType() != null)
 987                     {
 988                         if (IsPtrType(startRule->ReturnType()))
 989                         {
 990                             Cm.Ast.TemplateIdNode* tid = new Cm.Ast.TemplateIdNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"UniquePtr"));
 991                             Cm.Ast.CloneContext cloneContext;
 992                             tid->AddTemplateArgument(RemovePointer(startRule->ReturnType())->Clone(cloneContext));
 993                             returnTypeNode.Reset(tid);
 994                         }
 995                         else
 996                         {
 997                             Cm.Ast.CloneContext cloneContext;
 998                             returnTypeNode.Reset(startRule->ReturnType()->Clone(cloneContext));
 999                         }
1000                     }
1001                     else
1002                     {
1003                         returnTypeNode.Reset(new Cm.Ast.VoidNode(System.Lex.Span()moduleId));
1004                     }
1005                     Specifiers specifiers = Specifiers.public_ | Specifiers.static_;
1006                     if (parser.IsNothrow())
1007                     {
1008                         specifiers = specifiers | Specifiers.nothrow_;
1009                     }
1010                     UniquePtr<Cm.Ast.MemberFunctionNode> parseFunction(new Cm.Ast.MemberFunctionNode(System.Lex.Span()moduleIdspecifiersreturnTypeNode.Release()u"Parse"null));
1011                     parseFunction->AddParameter(new Cm.Ast.ParameterNode(System.Lex.Span()moduleIdnew Cm.Ast.LValueRefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdlexerTypeName))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")));
1012                     for (const UniquePtr<Parameter>& param : startRule->Parameters())
1013                     {
1014                         Cm.Ast.CloneContext cloneContext;
1015                         parseFunction->AddParameter(new Cm.Ast.ParameterNode(System.Lex.Span()moduleIdparam->type->Clone(cloneContext)new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdparam->id->Str())));
1016                     }
1017                     Cm.Ast.CompoundStatementNode* body = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
1018                     parseFunction->SetBody(body);
1019                     RuleParser* rule = startRule.Get();
1020                     if (rule->ReturnType() != null)
1021                     {
1022                         Cm.Ast.TemplateIdNode* tid = new Cm.Ast.TemplateIdNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"UniquePtr"));
1023                         Cm.Ast.CloneContext cloneContext;
1024                         if (IsPtrType(startRule->ReturnType()))
1025                         {
1026                             tid->AddTemplateArgument(RemovePointer(startRule->ReturnType())->Clone(cloneContext));
1027                         }
1028                         else
1029                         {
1030                             Cm.Ast.TemplateIdNode* vid = new Cm.Ast.TemplateIdNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Value"));
1031                             Cm.Ast.CloneContext cloneContext;
1032                             vid->AddTemplateArgument(startRule->ReturnType()->Clone(cloneContext));
1033                             tid->AddTemplateArgument(vid);
1034                         }
1035                         Cm.Ast.ConstructionStatementNode* valueStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdtidnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value"));
1036                         valueStmt->SetEmpty();
1037                         parseFunction->Body()->AddStatement(valueStmt);
1038                     }
1039                     if (!noParserDebugSupport)
1040                     {
1041                         Cm.Ast.ConditionalCompilationStatementNode* ccstmt = new Cm.Ast.ConditionalCompilationStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ConditionalCompilationPrimaryNode(System.Lex.Span()moduleIdu"DEBUG"));
1042                         Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
1043                         Cm.Ast.InvokeNode* invokeWrite = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.ArrowNode(System.Lex.Span()moduleIdnew Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Log")))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"WriteBeginRule")));
1044                         invokeWrite->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdu"parse"));
1045                         Cm.Ast.ExpressionStatementNode* exprStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeWrite);
1046                         thenS->AddStatement(exprStmt);
1047                         Cm.Ast.InvokeNode* invokeIncIndent = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.ArrowNode(System.Lex.Span()moduleIdnew Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Log")))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"IncIndent")));
1048                         Cm.Ast.ExpressionStatementNode* exprStmt2 = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeIncIndent);
1049                         thenS->AddStatement(exprStmt2);
1050                         Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.NotEqualNode(System.Lex.Span()moduleIdnew Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Log")))new Cm.Ast.NullLiteralNode(System.Lex.Span()moduleId))thenSnull);
1051                         ccstmt->AddIfStatement(ifStmt);
1052                         parseFunction->Body()->AddStatement(ccstmt);
1053                     }
1054                     Cm.Ast.PrefixIncrementNode* incLexer = new Cm.Ast.PrefixIncrementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"));
1055                     Cm.Ast.ExpressionStatementNode* exprStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdincLexer);
1056                     parseFunction->Body()->AddStatement(exprStmt);
1057                     Cm.Ast.ConstructionStatementNode* constructSpan = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Lex"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Span"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
1058                     constructSpan->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetSpan"))));
1059                     constructSpan->SetAssignment();
1060                     parseFunction->Body()->AddStatement(constructSpan);
1061                     Cm.Ast.ConstructionStatementNode* constructionStmt = new Cm.Ast.ConstructionStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match"));
1062                     Cm.Ast.InvokeNode* invokeRule = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdrule->Name()));
1063                     invokeRule->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"));
1064                     for (const UniquePtr<Parameter>& param : startRule->Parameters())
1065                     {
1066                         invokeRule->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdparam->id->Str()));
1067                     }
1068                     constructionStmt->AddArgument(invokeRule);
1069                     constructionStmt->SetAssignment();
1070                     parseFunction->Body()->AddStatement(constructionStmt);
1071                     RuleParser* calledRule = rule;
1072                     if (calledRule->ReturnType() != null)
1073                     {
1074                         Cm.Ast.CloneContext cloneContext;
1075                         Cm.Ast.Node* targetType = null;
1076                         if (IsPtrType(calledRule->ReturnType()))
1077                         {
1078                             targetType = calledRule->ReturnType()->Clone(cloneContext);
1079                         }
1080                         else
1081                         {
1082                             Cm.Ast.TemplateIdNode* vid = new Cm.Ast.TemplateIdNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Value"));
1083                             vid->AddTemplateArgument(calledRule->ReturnType()->Clone(cloneContext));
1084                             targetType = new Cm.Ast.PointerNode(System.Lex.Span()moduleIdvid);
1085                         }
1086                         Cm.Ast.CastNode* castNode = new Cm.Ast.CastNode(System.Lex.Span()moduleIdtargetTypenew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")));
1087                         Cm.Ast.InvokeNode* invokeReset = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Reset")));
1088                         invokeReset->AddArgument(castNode);
1089                         Cm.Ast.ExpressionStatementNode* exprStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeReset);
1090                         parseFunction->Body()->AddStatement(exprStmt);
1091                         if (!noParserDebugSupport)
1092                         {
1093                             Cm.Ast.ConditionalCompilationStatementNode* ccstmt = new Cm.Ast.ConditionalCompilationStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ConditionalCompilationPrimaryNode(System.Lex.Span()moduleIdu"DEBUG"));
1094                             Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
1095                             Cm.Ast.InvokeNode* invokeDecIndent = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.ArrowNode(System.Lex.Span()moduleIdnew Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Log")))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"DecIndent")));
1096                             Cm.Ast.ExpressionStatementNode* exprStmt2 = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeDecIndent);
1097                             thenS->AddStatement(exprStmt2);
1098                             Cm.Ast.InvokeNode* invokeWrite = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.ArrowNode(System.Lex.Span()moduleIdnew Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Log")))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"WriteEndRule")));
1099                             invokeWrite->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdu"parse"));
1100                             Cm.Ast.ExpressionStatementNode* exprStmt = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeWrite);
1101                             thenS->AddStatement(exprStmt);
1102                             Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.NotEqualNode(System.Lex.Span()moduleIdnew Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Log")))new Cm.Ast.NullLiteralNode(System.Lex.Span()moduleId))thenSnull);
1103                             ccstmt->AddIfStatement(ifStmt);
1104                             parseFunction->Body()->AddStatement(ccstmt);
1105                         }
1106                     }
1107                     Cm.Ast.CompoundStatementNode* thenS2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
1108                     if (startRule->ReturnType() != null)
1109                     {
1110                         if (IsPtrType(startRule->ReturnType()))
1111                         {
1112                             Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value"));
1113                             thenS2->AddStatement(returnStmt);
1114                         }
1115                         else
1116                         {
1117                             Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ArrowNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")));
1118                             thenS2->AddStatement(returnStmt);
1119                         }
1120                     }
1121                     else
1122                     {
1123                         Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnull);
1124                         thenS2->AddStatement(returnStmt);
1125                     }
1126                     Cm.Ast.CompoundStatementNode* elseS2 = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
1127                     if (parser.IsNothrow())
1128                     {
1129                         Cm.Ast.InvokeNode* invokeAddError = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"AddError")));
1130                         invokeAddError->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetSpan"))));
1131                         Cm.Ast.InvokeNode* invokeGetTokenInfo = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetEndTokenInfo"));
1132                         invokeAddError->AddArgument(invokeGetTokenInfo);
1133                         Cm.Ast.ExpressionStatementNode* exprStmt2 = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeAddError);
1134                         elseS2->AddStatement(exprStmt2);
1135                         if (startRule->ReturnType() != null)
1136                         {
1137                             if (IsPtrType(startRule->ReturnType()))
1138                             {
1139                                 Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value"));
1140                                 elseS2->AddStatement(returnStmt);
1141                             }
1142                             else
1143                             {
1144                                 Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ArrowNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")));
1145                                 elseS2->AddStatement(returnStmt);
1146                             }
1147                         }
1148                         else
1149                         {
1150                             Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnull);
1151                             elseS2->AddStatement(returnStmt);
1152                         }
1153                     }
1154                     else
1155                     {
1156                         if (parser.IsFarthestError())
1157                         {
1158                             Cm.Ast.InvokeNode* invokeThrowFarthestError = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleId
1159                                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")
1160                                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"ThrowFarthestError")));
1161                             Cm.Ast.ExpressionStatementNode* exprStmtFarthest = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeThrowFarthestError);
1162                             elseS2->AddStatement(exprStmtFarthest);
1163                         }
1164                         else
1165                         {
1166                             Cm.Ast.InvokeNode* invokeThrow = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleId
1167                                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")
1168                                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"ThrowExpectationFailure")));
1169                             invokeThrow->AddArgument(new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleId
1170                                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetSpan"))));
1171                             Cm.Ast.InvokeNode* invokeGetTokenInfo = new Cm.Ast.InvokeNode(System.Lex.Span()moduleId
1172                                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"GetEndTokenInfo"));
1173                             invokeThrow->AddArgument(invokeGetTokenInfo);
1174                             Cm.Ast.ExpressionStatementNode* exprStmt2 = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeThrow);
1175                             elseS2->AddStatement(exprStmt2);
1176                         }
1177                     }
1178                     Cm.Ast.CompoundStatementNode* thenS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
1179                     Cm.Ast.IfStatementNode* ifStmt2 = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.EqualNode(System.Lex.Span()moduleIdnew Cm.Ast.DerefNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer"))new Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"Lex"))new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"END_TOKEN")))thenS2elseS2);
1180                     thenS->AddStatement(ifStmt2);
1181                     Cm.Ast.CompoundStatementNode* elseS = new Cm.Ast.CompoundStatementNode(System.Lex.Span()moduleId);
1182                     ustring ruleInfo = rule->Info();
1183                     if (ruleInfo.IsEmpty())
1184                     {
1185                         ruleInfo = rule->Name();
1186                     }
1187                     if (parser.IsNothrow())
1188                     {
1189                         Cm.Ast.InvokeNode* invokeAddError2 = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"AddError")));
1190                         invokeAddError2->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
1191                         invokeAddError2->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdruleInfo));
1192                         Cm.Ast.ExpressionStatementNode* exprStmt3 = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeAddError2);
1193                         elseS->AddStatement(exprStmt3);
1194                         if (startRule->ReturnType() != null)
1195                         {
1196                             if (IsPtrType(startRule->ReturnType()))
1197                             {
1198                                 Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value"));
1199                                 elseS->AddStatement(returnStmt);
1200                             }
1201                             else
1202                             {
1203                                 Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ArrowNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")));
1204                                 elseS->AddStatement(returnStmt);
1205                             }
1206                         }
1207                         else
1208                         {
1209                             Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnull);
1210                             elseS->AddStatement(returnStmt);
1211                         }
1212                     }
1213                     else
1214                     {
1215                         if (parser.IsFarthestError())
1216                         {
1217                             Cm.Ast.InvokeNode* invokeThrowFarthestError = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleId
1218                                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")
1219                                 new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"ThrowFarthestError")));
1220                             Cm.Ast.ExpressionStatementNode* exprStmtFarthest = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeThrowFarthestError);
1221                             elseS->AddStatement(exprStmtFarthest);
1222                         }
1223                         else
1224                         {
1225                             Cm.Ast.InvokeNode* invokeThrow2 = new Cm.Ast.InvokeNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"lexer")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"ThrowExpectationFailure")));
1226                             invokeThrow2->AddArgument(new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"span"));
1227                             invokeThrow2->AddArgument(new Cm.Ast.UStringLiteralNode(System.Lex.Span()moduleIdruleInfo));
1228                             Cm.Ast.ExpressionStatementNode* exprStmt3 = new Cm.Ast.ExpressionStatementNode(System.Lex.Span()moduleIdinvokeThrow2);
1229                             elseS->AddStatement(exprStmt3);
1230                         }
1231                     }
1232                     Cm.Ast.IfStatementNode* ifStmt = new Cm.Ast.IfStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.DotNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"match")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"hit"))thenSelseS);
1233                     parseFunction->Body()->AddStatement(ifStmt);
1234                     if (startRule->ReturnType() != null)
1235                     {
1236                         if (IsPtrType(startRule->ReturnType()))
1237                         {
1238                             Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value"));
1239                             parseFunction->Body()->AddStatement(returnStmt);
1240                         }
1241                         else
1242                         {
1243                             Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnew Cm.Ast.ArrowNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")new Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"value")));
1244                             parseFunction->Body()->AddStatement(returnStmt);
1245                         }
1246                     }
1247                     else
1248                     {
1249                         Cm.Ast.ReturnStatementNode* returnStmt = new Cm.Ast.ReturnStatementNode(System.Lex.Span()moduleIdnull);
1250                         parseFunction->Body()->AddStatement(returnStmt);
1251                     }
1252                     classNode->AddMember(parseFunction.Release());
1253                 }
1254             }
1255             for (const UniquePtr<RuleParser>& rule : parser.Rules())
1256             {
1257                 rule->Accept(*this);
1258             }
1259             currentCompileUnit->GlobalNs()->AddMember(classNode.Release());
1260             currentClass = prevClass;
1261         }
1262         public override void Visit(ParserFile& parserFile)
1263         {
1264             if (verbose)
1265             {
1266                 Console.Out() << "> " << parserFile.FileName() << endl();
1267             }
1268             sn = 0;
1269             string cmajorFilePath = Path.ChangeExtension(parserFile.FileName()".cm");
1270             Cm.Ast.CompileUnitNode* prevCu = currentCompileUnit;
1271             UniquePtr<Cm.Ast.CompileUnitNode> cu(new Cm.Ast.CompileUnitNode(System.Lex.Span()moduleIdcmajorFilePath));
1272             cu->GlobalNs()->AddMember(new Cm.Ast.NamespaceImportNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System")));
1273             cu->GlobalNs()->AddMember(new Cm.Ast.NamespaceImportNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System.Collections")));
1274             cu->GlobalNs()->AddMember(new Cm.Ast.NamespaceImportNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System.Lex")));
1275             cu->GlobalNs()->AddMember(new Cm.Ast.NamespaceImportNode(System.Lex.Span()moduleIdnew Cm.Ast.IdentifierNode(System.Lex.Span()moduleIdu"System.Parsing")));
1276             Cm.Ast.CloneContext cloneContext;
1277             for (const UniquePtr<Cm.Ast.Node>& usingDirective : parserFile.UsingDirectives())
1278             {
1279                 cu->GlobalNs()->AddMember(usingDirective->Clone(cloneContext));
1280             }
1281             cu->GlobalNs()->AddMember(new Cm.Ast.CommentNode(System.Lex.Span()moduleIdu"this file has been automatically generated from \'" + ToUtf32(parserFile.FileName()) + u"\' using soulcm parser generator scmpg version " + ToUtf32(ParserGeneratorVersionStr())));
1282             currentCompileUnit = cu.Get();
1283             UniquePtr<Cm.Ast.NamespaceNode> unnamedNamespace(new Cm.Ast.NamespaceNode(System.Lex.Span()moduleIdnull));
1284             ArrayGeneratorVisitor arrayGeneratorVisitor(unnamedNamespace.Get()snmoduleId);
1285             parserFile.Accept(arrayGeneratorVisitor);
1286             if (unnamedNamespace->Members().Count() > 0)
1287             {
1288                 cu->GlobalNs()->AddMember(unnamedNamespace.Release());
1289             }
1290             for (const UniquePtr<GrammarParser>& parser : parserFile.Parsers())
1291             {
1292                 parser->Accept(*this);
1293             }
1294             StreamWriter cmajorFile(File.CreateText(cmajorFilePath));
1295             CodeFormatter formatter(cmajorFile);
1296             Cm.Ast.SourceWriter writer(formatter);
1297             cu->Accept(writer);
1298             if (verbose)
1299             {
1300                 Console.Out() << "==> " << cmajorFilePath << endl();
1301             }
1302             currentCompileUnit = prevCu;
1303         }
1304         public override void Visit(Domain& domain)
1305         {
1306             this->domain = &domain;
1307             for (ParserFile* parserFile : domain.ParserFiles())
1308             {
1309                 parserFile->Accept(*this);
1310             }
1311             if (!domain.RuleFilePath().IsEmpty())
1312             {
1313                 GenerateRuleFile(domainverbose);
1314             }
1315         }
1316         private bool verbose;
1317         private bool debug;
1318         private bool noParserDebugSupport;
1319         private Domain* domain;
1320         private GrammarParser* currentParser;
1321         private RuleParser* currentRule;
1322         private Stage stage;
1323         private Cm.Ast.CompoundStatementNode* currentBlock;
1324         private Stack<Cm.Ast.CompoundStatementNode*> blockStack;
1325         private Cm.Ast.ClassNode* currentClass;
1326         private Cm.Ast.CompileUnitNode* currentCompileUnit;
1327         private ustring lexerTypeName;
1328         private List<NonterminalInfo> nonterminalInfos;
1329         private int parentMatchNumber;
1330         private int setParentMatchNumber;
1331         private int sn;
1332         private Cm.Ast.SwitchStatementNode* tokenSwitch;
1333         private Uuid moduleId;
1334     }
1335     public void GenerateRuleFile(Domain& domainbool verbose)
1336     {
1337         StreamWriter writer = File.CreateText(domain.RuleFilePath());
1338         CodeFormatter formatter(writer);
1339         formatter.WriteLine("using System;");
1340         formatter.WriteLine("using System.Collections;");
1341         formatter.WriteLine();
1342         formatter.WriteLine("public class RuleNames");
1343         formatter.WriteLine("{");
1344         formatter.IncIndent();
1345         formatter.WriteLine("static RuleNames() : instance(new RuleNames())");
1346         formatter.WriteLine("{");
1347         formatter.WriteLine("}");
1348         formatter.WriteLine("public static RuleNames& Instance()");
1349         formatter.WriteLine("{");
1350         formatter.IncIndent();
1351         formatter.WriteLine("return *instance;");
1352         formatter.DecIndent();
1353         formatter.WriteLine("}");
1354         formatter.WriteLine("public nothrow RuleNames()");
1355         formatter.WriteLine("{");
1356         formatter.IncIndent();
1357         for (RuleParser* rule : domain.Rules())
1358         {
1359             formatter.WriteLine("ruleNames.Add(\"" + ToUtf8(rule->Parent()->Name()) + "." + ToUtf8(rule->Name()) + "\");");
1360         }
1361         formatter.DecIndent();
1362         formatter.WriteLine("}");
1363         formatter.WriteLine("public nothrow List<string>* Get() const");
1364         formatter.WriteLine("{");
1365         formatter.IncIndent();
1366         formatter.WriteLine("return &ruleNames;");
1367         formatter.DecIndent();
1368         formatter.WriteLine("}");
1369         formatter.WriteLine("private static UniquePtr<RuleNames> instance;");
1370         formatter.WriteLine("private List<string> ruleNames;");
1371         formatter.DecIndent();
1372         formatter.WriteLine("}");
1373         formatter.WriteLine();
1374         formatter.WriteLine("public nothrow List<string>* GetRuleNameList()");
1375         formatter.WriteLine("{");
1376         formatter.IncIndent();
1377         formatter.WriteLine("return RuleNames.Instance().Get();");
1378         formatter.DecIndent();
1379         formatter.WriteLine("}");
1380         formatter.WriteLine();
1381         if (verbose)
1382         {
1383             Console.Out() << "==> " << domain.RuleFilePath() << endl();
1384         }
1385     }
1386     public string ParserGeneratorVersionStr()
1387     {
1388         return "5.0.0";
1389     }
1390 } // namespace soulcm.scmpg