Beispiel #1
0
 public void WriteSqlNodeMembers(CSharpWriter csw, RuleCompiler cmp)
 {
     foreach (var item in Items)
     {
         item.WriteSqlNodeMembers(csw, cmp);
     }
 }
Beispiel #2
0
        public override void Compile(RuleCompiler cmp)
        {
            base.Compile(cmp);
            Rule target = cmp.Rules.FindRule(RefName);

            MemberNodeName = cmp.AllocVar(target.CodeName + "Node", "SubNode", target.GetResultType(), VariableTypeGroup.SubNode);
        }
Beispiel #3
0
 public override void GenRuleTestBody(CSharpWriter csw, RuleCompiler cmp, string member)
 {
     csw.WriteLine("{0} res = {1}();", GetResultType(), ParseFuncName);
     csw.WriteLine("if (res == null) return false;");
     csw.WriteLine("args.{0} = res;", member);
     csw.WriteLine("return true;");
 }
Beispiel #4
0
 public void WriteGenSqlBody(CSharpWriter csw, RuleCompiler cmp)
 {
     foreach (var item in Items)
     {
         item.WriteGenSqlBody(csw, cmp);
     }
 }
Beispiel #5
0
 public override void GenRuleTestBody(CSharpWriter csw, RuleCompiler cmp, string member)
 {
     csw.WriteLine("{0} node = {1}({2});", TypeName, FuncName, CallArgs.CreateDelimitedText(", "));
     csw.WriteLine("if (node == null) return false;");
     csw.WriteLine("args.{0} = node;", member);
     csw.WriteLine("return true;");
 }
Beispiel #6
0
        public override void WriteParserMembers(CSharpWriter csw, RuleCompiler cmp)
        {
            foreach (var chain in Chains)
            {
                chain.WriteParserMembers(csw, cmp);
            }
            WriteParseMethodHeader(csw, cmp);
            int chindex = 0;

            foreach (var chain in Chains)
            {
                csw.Begin("if ({0}(args))", chain.ParseFuncName);
                csw.WriteLine("args.{0} = {1}.{2}.{3};", EnumVarName, cmp.Rule.GetResultType(), EnumTypeName, EnumElems[chindex]);
                if (!Mandatory)
                {
                    csw.WriteLine("args.{0} = true;", IsVariable);
                }
                csw.WriteLine("return true;");
                csw.End();
                chindex++;
            }
            if (Mandatory)
            {
                csw.WriteLine("return false;");
            }
            else
            {
                csw.WriteLine("args.{0} = false;", IsVariable);
                csw.WriteLine("return true;");
            }
            csw.End(); // method
        }
Beispiel #7
0
        public override void WriteParserMembers(CSharpWriter csw, RuleCompiler cmp)
        {
            WriteParseMethodHeader(csw, cmp);
            Rule target = cmp.Rules.FindRule(RefName);

            target.GenRuleTestBody(csw, cmp, MemberNodeName);
            csw.End();
        }
Beispiel #8
0
 internal void Compile(RuleCompiler cmp)
 {
     ParseFuncName = cmp.AllocFuncName("ParseChain");
     foreach (var item in Items)
     {
         item.Compile(cmp);
     }
 }
Beispiel #9
0
 public override void WriteSqlNodeMembers(CSharpWriter csw, RuleCompiler cmp)
 {
     base.WriteSqlNodeMembers(csw, cmp);
     foreach (var chain in Chains)
     {
         chain.WriteSqlNodeMembers(csw, cmp);
     }
     csw.WriteLine("public enum {0} {{ {1} }}", EnumTypeName, EnumElems.CreateDelimitedText(", "));
 }
Beispiel #10
0
 public override void WriteParserMembers(CSharpWriter csw, RuleCompiler cmp)
 {
     WriteParseMethodHeader(csw, cmp);
     csw.Begin("if (IsTerminal(\"{0}\"))", Symbol);
     csw.WriteLine("args.{0} = CurrentOriginal;", TerminalPosName);
     csw.WriteLine("NextToken();");
     csw.WriteLine("return true;");
     csw.End();
     csw.WriteLine("return false;");
     csw.End(); // method
 }
Beispiel #11
0
        //public bool IsSymbol{get{return !Char.IsLetter( Symbol[0]);}}

        public override void Compile(RuleCompiler cmp)
        {
            base.Compile(cmp);
            if (Symbol.ToCharArray().All(Char.IsLetter))
            {
                TerminalPosName = cmp.AllocVar(Symbol.Capitalize() + "Pos", "TermPos", "SymbolPosition", VariableTypeGroup.SymbolPos);
            }
            else
            {
                TerminalPosName = cmp.AllocVar(null, "TermPos", "SymbolPosition", VariableTypeGroup.SymbolPos);
            }
        }
Beispiel #12
0
 internal void WriteParserMembers(CSharpWriter csw, RuleCompiler cmp)
 {
     foreach (RuleItem item in Items)
     {
         item.WriteParserMembers(csw, cmp);
     }
     csw.Begin("public bool {0}({1} args)", ParseFuncName, cmp.Rule.ArgsClassName);
     csw.WriteLine("var beginMark = MarkPosition();");
     foreach (RuleItem item in Items)
     {
         csw.Begin("if (!{0}(args))", item.ParseFuncName);
         csw.WriteLine("GoToMark(beginMark);");
         csw.WriteLine("return false;");
         csw.End();
     }
     csw.WriteLine("return true;");
     csw.End();
 }
Beispiel #13
0
 public override void Compile(RuleCompiler cmp)
 {
     base.Compile(cmp);
     if (!Mandatory)
     {
         if (CodeId != null)
         {
             IsVariable = cmp.AllocVar("Is" + CodeId, null, "bool", VariableTypeGroup.Bool);
         }
         else
         {
             IsVariable = cmp.AllocVar(null, "IsItem", "bool", VariableTypeGroup.Bool);
         }
     }
     if (CodeId != null)
     {
         EnumTypeName = cmp.AllocLocalType(CodeId + "ModeType", null);
     }
     else
     {
         EnumTypeName = cmp.AllocLocalType(null, "ModeType");
     }
     if (CodeId != null)
     {
         EnumVarName = cmp.AllocVar(CodeId + "Mode", null, cmp.Rule.GetResultType() + "." + EnumTypeName, VariableTypeGroup.ModeEnum);
     }
     else
     {
         EnumVarName = cmp.AllocVar(null, "Mode", cmp.Rule.GetResultType() + "." + EnumTypeName, VariableTypeGroup.ModeEnum);
     }
     foreach (var chain in Chains)
     {
         string sug = chain.SuggestCodeId();
         if (sug == "" || EnumElems.Contains(sug))
         {
             sug = String.Format("Element_{0}", EnumElems.Count + 1);
         }
         EnumElems.Add(sug);
     }
     foreach (var chain in Chains)
     {
         chain.Compile(cmp);
     }
 }
Beispiel #14
0
 public override void WriteGenSqlBody(CSharpWriter csw, RuleCompiler cmp)
 {
     if (!Mandatory)
     {
         csw.Begin("if ({0})", IsVariable);
     }
     csw.Begin("switch ({0})", EnumVarName);
     for (int i = 0; i < Chains.Count; i++)
     {
         csw.WriteLine("case {0}.{1}:", EnumTypeName, EnumElems[i]);
         csw.Inc();
         Chains[i].WriteGenSqlBody(csw, cmp);
         csw.WriteLine("break;");
         csw.Dec();
     }
     csw.End(); // switch
     if (!Mandatory)
     {
         csw.End();             // if ($IsVariable)
     }
 }
Beispiel #15
0
 public override void WriteGenSqlBody(CSharpWriter csw, RuleCompiler cmp)
 {
     csw.WriteLine("{0}.GenerateSql(dmp);", MemberNodeName);
 }
Beispiel #16
0
 public virtual void Compile(RuleCompiler cmp)
 {
     ParseFuncName = cmp.AllocFuncName("ParseItem");
 }
Beispiel #17
0
 public override void Compile(ParserCompiler pc)
 {
     m_compiler = new RuleCompiler(pc, this);
     m_compiler.Compile();
 }
Beispiel #18
0
 public abstract void GenRuleTestBody(CSharpWriter csw, RuleCompiler cmp, string member);
Beispiel #19
0
 public abstract void WriteParserMembers(CSharpWriter csw, RuleCompiler cmp);
Beispiel #20
0
 public abstract void WriteGenSqlBody(CSharpWriter csw, RuleCompiler cmp);
Beispiel #21
0
 protected void WriteParseMethodHeader(CSharpWriter csw, RuleCompiler cmp)
 {
     csw.MethodEx("public", "bool", ParseFuncName, cmp.Rule.ArgsClassName + " args");
 }
Beispiel #22
0
 public override void WriteGenSqlBody(CSharpWriter csw, RuleCompiler cmp)
 {
     csw.WriteLine("dmp.Put(\"&s%:k\", {0}, \"{1}\");", TerminalPosName, Symbol);
 }
Beispiel #23
0
 public virtual void WriteSqlNodeMembers(CSharpWriter csw, RuleCompiler cmp)
 {
 }
Beispiel #24
0
 public override void WriteGenSqlBody(CSharpWriter csw, RuleCompiler cmp)
 {
     csw.WriteLine("dmp.Put(\"{0}\");", Format);
 }
Beispiel #25
0
 public override void WriteParserMembers(CSharpWriter csw, RuleCompiler cmp)
 {
     WriteParseMethodHeader(csw, cmp);
     csw.WriteLine("return true;");
     csw.End(); // method
 }