コード例 #1
0
ファイル: ExpressionParser.cs プロジェクト: argent00/ezEmuera
        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);
        }
コード例 #2
0
ファイル: ExpressionParser.cs プロジェクト: argent00/ezEmuera
        /// <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);
        }
コード例 #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;
        }
コード例 #4
0
ファイル: Argument.cs プロジェクト: utau1116b/Hello-World
 public CaseArgument(CaseExpression[] args)
 {
     CaseExps = args;
 }
コード例 #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;
 }