示例#1
0
        /// <summary>
        /// ContextStage を読み取ります。
        /// </summary>
        /// <param name="p">読み取りを実行している ContextCompiler を指定します。</param>
        /// <param name="stage">読み取った stage を返します。</param>
        /// <returns>現在の Context 内の stage を全て読み終わってもう残りが無い時に false を返します。
        /// それ以外の場合には stage を読み取って true を返します。</returns>
        public static bool Read(ContextCompiler p, out ContextStage stage)
        {
            stage = new ContextStage();
            if (p.wreader.CurrentType == WordType.Invalid)
            {
                return(false);
            }
            stage.words = new System.Collections.Generic.List <ContextCondition>();
            stage.cmds  = new System.Collections.Generic.List <ContextCommand>();

            // 分岐標 読み取り
            ContextCondition ctxword;

            while (p.wreader.CurrentType == WordType.Identifier)
            {
                if (!ContextCondition.Read(p, out ctxword))
                {
                    break;
                }
                stage.words.Add(ctxword);
            }
            if (p.wreader.CurrentType == WordType.Operator && p.wreader.CurrentWord == ":")
            {
                p.wreader.ReadNext();
            }

            // 命令 読み取り
            ContextCommand ctxcmd;

            while (p.wreader.CurrentType == WordType.Identifier)
            {
                if (!ContextCommand.Read(p, out ctxcmd))
                {
                    break;
                }
                stage.cmds.Add(ctxcmd);
            }
            if (p.wreader.CurrentType == WordType.Operator && p.wreader.CurrentWord == ";")
            {
                p.wreader.ReadNext();
            }

            // 結果判定
            if (stage.cmds.Count == 0)
            {
                // 何も (命令も分岐標も) 読み取っていない時
                if (stage.words.Count == 0)
                {
                    return(false);
                }

                // 命令が一つもないのに分岐標がある時
                p.wreader.LetterReader.SetError("対応する命令列が存在しません。", 0, null);
                stage.cmds.Add(new ContextCommand("ret", ""));
            }
            return(true);
        }
示例#2
0
        public static bool Read(ContextCompiler p, out Context context)
        {
            if (p.wreader.CurrentType == WordType.Invalid)
            {
                context = new Context();
                return(false);
            }
            context      = new Context();
            context.data = new Gen::List <ContextStage>();
            // context
            while (p.wreader.CurrentType != WordType.Identifier || p.wreader.CurrentWord != "context")
            {
                p.wreader.LetterReader.SetError("context の開始には keyword 'context' が必要です。", 0, null);
                if (!p.wreader.ReadNext())
                {
                    return(false);
                }
            }
            p.wreader.ReadNext();

            // ContextName
            while (p.wreader.CurrentType != WordType.Identifier)
            {
                p.wreader.LetterReader.SetError("keyword 'context' の後には識別子が必要です。", 0, null);
                if (!p.wreader.ReadNext())
                {
                    return(false);
                }
            }
            context.name = p.wreader.CurrentWord;
            if (!context.CheckName())
            {
                p.wreader.LetterReader.SetError("指定した識別子は識別子として無効です。適切な物を指定して下さい", 0, null);
            }
            p.wreader.ReadNext();

            // {
            while (p.wreader.CurrentType != WordType.Operator || p.wreader.CurrentWord != "{")
            {
                p.wreader.LetterReader.SetError("context 宣言の後には context の中身が必要です。中身は { で始めて下さい。", 0, null);
                if (!p.wreader.ReadNext())
                {
                    return(false);
                }
            }
            p.wreader.ReadNext();

            // List<ContextStage>
            ContextStage stage;

            while (ContextStage.Read(p, out stage))
            {
                context.data.Add(stage);
            }

            // }
            if (p.wreader.CurrentType == WordType.Operator && p.wreader.CurrentWord == "}")
            {
                p.wreader.ReadNext();
            }
            return(true);
        }