public override ISitcomOper AddRightChild(ISitcomOper oper, out ISitcomOper replaced)
 {
     replaced      = mRight;
     mRight        = oper;
     mRight.Parent = this;
     return(mRight);
 }
 public override ISitcomOper AddRightChild(ISitcomOper oper, out ISitcomOper replaced)
 {
     replaced    = mCondition;
     mCondition  = oper;
     oper.Parent = this;
     return(oper);
 }
        private SitcomFactory()
        {
            mDefaultOper = new SitcomRefOper(default(SitcomFile.Keyword));
            AddOperator(new SitcomDomainOper());
            AddOperator(new SitcomDomainOper("。"));

            AddOperator(new SitcomFixOper(":", SitcomDefine.PRI_DOMAIN + 1));
            AddOperator(new SitcomFixOper(":", SitcomDefine.PRI_DOMAIN + 1));

            AddOperator(new SitcomBracketOper());
            AddOperator(new SitcomBracketOper("("));

            AddOperator(new SitcomFixOper(")", SitcomDefine.PRI_LOWEST));
            AddOperator(new SitcomFixOper(")", SitcomDefine.PRI_LOWEST));

            AddOperator(new SitcomConditionOper());
            AddOperator(new SitcomConditionOper("?"));

            AddOperator(new SitcomNotOper("not"));
            AddOperator(new SitcomGotoOper(">>"));
            AddOperator(new SitcomGotoOper("》"));

            AddOperator(new SitcomAndOper("and", SitcomDefine.PRI_BIN_MIDDLE + 1));
            AddOperator(new SitcomOrOper("or", SitcomDefine.PRI_BIN_MIDDLE));
        }
 public override void AddLeftChild(ISitcomOper oper)
 {
     if (mLeft != null)
     {
         throw new SitcomCompileException(keyword);
     }
     mLeft = oper;
 }
 ISitcomOper GetRoot(ISitcomOper oper, int priority)
 {
     while (!oper.IsBlock && oper.Priority >= priority && oper.Parent != null)
     {
         oper = oper.Parent;
     }
     return(oper);
 }
Exemple #6
0
 public override void AddLeftChild(ISitcomOper oper)
 {
     if (oper.Identify != SitcomDefine.OPER_DOT && oper.Identify != SitcomDefine.OPER_DOT2)
     {
         throw new SitcomCompileException(oper.keyword);
     }
     mLeft = oper;
 }
Exemple #7
0
 public override ISitcomOper AddRightChild(ISitcomOper oper, out ISitcomOper replaced)
 {
     replaced = null;
     if (oper.Identify == SitcomDefine.OPER_COLON || oper.Identify == SitcomDefine.OPER_COLON2) // :
     {
         if (!mWaitContent)
         {
             mWaitContent = true;
             return(this);
         }
         if (mKey == null)
         {
             throw new SitcomCompileException(oper.keyword);
         }
         mKey.useKey = true;
         mUseKV      = true;
         return(this);
     }
     else if (!mWaitContent)
     {
         if (oper.Identify != SitcomDefine.OPER_REFERENCE)
         {
             throw new SitcomCompileException(oper.keyword);
         }
         mRight = oper.keyword;
         return(this);
     }
     else if (mKey == null)
     {
         mKey        = new KeyValue();
         mKey.key    = oper;
         oper.Parent = this;
         return(oper);
     }
     else if (mKey.useKey)
     {
         replaced    = mKey.value;
         mKey.value  = oper;
         oper.Parent = this;
         mKVs.Add(mKey);
         mKey = null;
         return(oper);
     }
     else
     {
         mKVs.Add(mKey);
         mKey        = new KeyValue();
         mKey.key    = oper;
         oper.Parent = this;
         return(oper);
     }
     throw new SitcomCompileException(oper.keyword);
 }
 public bool Read(SitcomFile sitcom)
 {
     if (sitcom.NextCmd())
     {
         mKeys.Clear();
         while (sitcom.NextKeyword())
         {
             mKeys.Add(sitcom.keyword);
         }
         ISitcomOper replaced;
         var         dom = new SitcomDomainOper();
         dom.keyword = sitcom.keyword;
         mOper       = dom;
         for (int i = 0; i < mKeys.Count; i++)
         {
             var oper = SitcomFactory.Instance.GetOperator(mKeys[i]);
             var root = GetRoot(mOper, oper.Priority);
             if (!root.IsBlock && root.Priority >= oper.Priority)
             {
                 oper.AddLeftChild(root);
                 mOper = oper;
             }
             else
             {
                 mOper = root.AddRightChild(oper, out replaced);
                 if (replaced != null)
                 {
                     oper.AddLeftChild(replaced);
                 }
             }
         }
         while (mOper.Parent != null)
         {
             mOper = mOper.Parent;
         }
         if (mOper.RequireContent && sitcom.NextContent())
         {
             mOper.AddContent(sitcom.keyword);
         }
         mOper.Compile();
         return(true);
     }
     else
     {
         mOper = null;
         return(false);
     }
 }
Exemple #9
0
 public override ISitcomOper AddRightChild(ISitcomOper oper, out ISitcomOper replaced)
 {
     if (mFinish)
     {
         throw new SitcomCompileException(oper.keyword);
     }
     if (oper.Identify == SitcomDefine.OPER_BRACKET_R || oper.Identify == SitcomDefine.OPER_BRACKET_R2)
     {
         mFinish  = true;
         replaced = null;
         return(this);
     }
     replaced        = mContent;
     mContent        = oper;
     mContent.Parent = this;
     return(oper);
 }
        public void AddOperator(ISitcomOper oper)
        {
            var index = GlobalUtil.BinsearchFromRightIndex(mOperators, oper.Identify);

            if (index == -1)
            {
                mOperators.Add(oper);
            }
            else if (mOperators[index].Identify == oper.Identify)
            {
                throw new System.Exception(string.Format("Duplicate Define Of Operator \"{0}\"", oper.Identify.ToString("x")));
            }
            else
            {
                mOperators.Insert(index, oper);
            }
        }
Exemple #11
0
 public override void AddLeftChild(ISitcomOper oper)
 {
     throw new SitcomCompileException(oper.keyword);
 }
 public override ISitcomOper AddRightChild(ISitcomOper oper, out ISitcomOper replaced)
 {
     throw new SitcomCompileException(oper.keyword);
 }
 public abstract ISitcomOper AddRightChild(ISitcomOper oper, out ISitcomOper replaced);
 public abstract void AddLeftChild(ISitcomOper oper);