コード例 #1
0
ファイル: Compiler.cs プロジェクト: HyodaKazuaki/GMC-4
        /// <summary>
        /// ラベルを追加します。
        /// </summary>
        private void addLabel()
        {
            string operationCode = "";
            bool notFoundEndLine = true;
            for (int i = startLine + 1; i < sourceCode.Length; i++)
            {
                try
                {
                    var value = sourceCode[i];
                    string[] term = value.Split(del, StringSplitOptions.RemoveEmptyEntries);

                    if (value.IndexOf(term[0]) == 0)
                    {
                        // ラベル名重複チェック
                        if (Memory.labelList.Count(x => x.Name() == term[0]) != 0)
                            throw new LabelDuplicationException();
                        // ラベル追加
                        Memory.labelList.Add(new Label(term[0], labelAddress));
                        // オペコードは第二引数部
                        operationCode = term[1];
                    }
                    else if (term[0] == "END" && value.IndexOf(term[0]) != 0)
                    {
                        // 終了
                        notFoundEndLine = false;
                        break;
                    }
                    else
                    {
                        // ラベルなし、オペコードは第一引数部
                        operationCode = term[0];
                    }

                    // ラベルアドレスをオペコード分ずらす
                    labelAddress += OperationCode.addOperationCode(operationCode);
                }
                catch (KeyNotFoundException e)
                {
                    Error error = new Error("E01", "命令 " + operationCode + " は存在しません。", i + 1);
                    return;
                }
                catch (LabelDuplicationException e)
                {
                    Error error = new Error("E22", "命令 " + operationCode + " のラベルはすでに使用されています。", i + 1);
                    return;
                }
            }

            if (notFoundEndLine) throw new EndLineNotFoundException();
        }