Exemplo n.º 1
0
        private static CaseExpression reduceCaseExpression(WordCollection wc)
        {
            CaseExpression ret = new CaseExpression();
            IdentifierWord id  = wc.Current as IdentifierWord;

            if ((id != null) && (id.Code.Equals("IS", Config.SCVariable)))
            {
                wc.ShiftNext();
                ret.CaseType = CaseExpressionType.Is;
                OperatorWord opWT = wc.Current as OperatorWord;
                if (opWT == null)
                {
                    throw new CodeEE("ISキーワードの後に演算子がありません");
                }

                OperatorCode op = opWT.Code;
                if (!OperatorManager.IsBinary(op))
                {
                    throw new CodeEE("ISキーワードの後の演算子が2項演算子ではありません");
                }
                wc.ShiftNext();
                ret.Operator = op;
                ret.LeftTerm = reduceTerm(wc, false, TermEndWith.Comma, VariableCode.__NULL__);
                if (ret.LeftTerm == null)
                {
                    throw new CodeEE("ISキーワードの後に式がありません");
                }
                Type type = ret.LeftTerm.GetOperandType();
                return(ret);
            }
            ret.LeftTerm = reduceTerm(wc, true, TermEndWith.Comma, VariableCode.__NULL__);
            if (ret.LeftTerm == null)
            {
                throw new CodeEE("CASEの引数は省略できません");
            }
            id = wc.Current as IdentifierWord;
            if ((id != null) && (id.Code.Equals("TO", Config.SCVariable)))
            {
                ret.CaseType = CaseExpressionType.To;
                wc.ShiftNext();
                ret.RightTerm = reduceTerm(wc, true, TermEndWith.Comma, VariableCode.__NULL__);
                if (ret.RightTerm == null)
                {
                    throw new CodeEE("TOキーワードの後に式がありません");
                }
                id = wc.Current as IdentifierWord;
                if ((id != null) && (id.Code.Equals("TO", Config.SCVariable)))
                {
                    throw new CodeEE("TOキーワードが2度使われています");
                }
                if (ret.LeftTerm.GetOperandType() != ret.RightTerm.GetOperandType())
                {
                    throw new CodeEE("TOキーワードの前後の型が一致していません");
                }
                return(ret);
            }
            ret.CaseType = CaseExpressionType.Normal;
            return(ret);
        }
Exemplo n.º 2
0
        /// <summary>
        /// カンマで区切られたCASEの引数を一括して取得。行端で終わる。
        /// </summary>
        /// <param name="st"></param>
        /// <returns></returns>
        public static CaseExpression[] ReduceCaseExpressions(WordCollection wc)
        {
            List <CaseExpression> terms = new List <CaseExpression>();

            while (!wc.EOL)
            {
                terms.Add(reduceCaseExpression(wc));
                wc.ShiftNext();
            }
            CaseExpression[] ret = new CaseExpression[terms.Count];
            terms.CopyTo(ret);
            return(ret);
        }
Exemplo n.º 3
0
        private static CaseExpression reduceCaseExpression(WordCollection wc)
        {
            CaseExpression ret = new CaseExpression();
            IdentifierWord id = wc.Current as IdentifierWord;
            if ((id != null) && (id.Code.Equals("IS", Config.SCVariable)))
            {
                wc.ShiftNext();
                ret.CaseType = CaseExpressionType.Is;
                OperatorWord opWT = wc.Current as OperatorWord;
                if (opWT == null)
                    throw new CodeEE("ISキーワードの後に演算子がありません");

                OperatorCode op = opWT.Code;
                if (!OperatorManager.IsBinary(op))
                    throw new CodeEE("ISキーワードの後の演算子が2項演算子ではありません");
                wc.ShiftNext();
                ret.Operator = op;
                ret.LeftTerm = reduceTerm(wc, false, TermEndWith.Comma, VariableCode.__NULL__);
                if (ret.LeftTerm == null)
                    throw new CodeEE("ISキーワードの後に式がありません");
                Type type = ret.LeftTerm.GetOperandType();
                return ret;
            }
            ret.LeftTerm = reduceTerm(wc, true, TermEndWith.Comma, VariableCode.__NULL__);
            if (ret.LeftTerm == null)
                throw new CodeEE("CASEの引数は省略できません");
            id = wc.Current as IdentifierWord;
            if ((id != null) && (id.Code.Equals("TO", Config.SCVariable)))
            {
                ret.CaseType = CaseExpressionType.To;
                wc.ShiftNext();
                ret.RightTerm = reduceTerm(wc, true, TermEndWith.Comma, VariableCode.__NULL__);
                if (ret.RightTerm == null)
                    throw new CodeEE("TOキーワードの後に式がありません");
                id = wc.Current as IdentifierWord;
                if ((id != null) && (id.Code.Equals("TO", Config.SCVariable)))
                    throw new CodeEE("TOキーワードが2度使われています");
                if (ret.LeftTerm.GetOperandType() != ret.RightTerm.GetOperandType())
                    throw new CodeEE("TOキーワードの前後の型が一致していません");
                return ret;
            }
            ret.CaseType = CaseExpressionType.Normal;
            return ret;
        }
Exemplo n.º 4
0
 public CaseArgument(CaseExpression[] args)
 {
     CaseExps = args;
 }
Exemplo n.º 5
0
 /// <summary>
 /// カンマで区切られたCASEの引数を一括して取得。行端で終わる。
 /// </summary>
 /// <param name="st"></param>
 /// <returns></returns>
 public static CaseExpression[] ReduceCaseExpressions(WordCollection wc)
 {
     List<CaseExpression> terms = new List<CaseExpression>();
     while (!wc.EOL)
     {
         terms.Add(reduceCaseExpression(wc));
         wc.ShiftNext();
     }
     CaseExpression[] ret = new CaseExpression[terms.Count];
     terms.CopyTo(ret);
     return ret;
 }