public static void Initialize()
 {
     ZeroTerm = new SingleTerm(0);
     IOperandTerm[] zeroArgs = new IOperandTerm[] { ZeroTerm };
     TARGET = new VariableTerm(GlobalStatic.VariableData.GetSystemVariableToken("TARGET"), zeroArgs);
 }
 public void ReturnF(SingleTerm ret)
 {
     //読み込み時のチェック済みのはず
     //if (!IsFunctionMethod)
     //    throw new ExeEE("ReturnFと#FUNCTIONのチェックがおかしい");
     //sequential = false;//いずれにしろ順列ではない。
     //呼び出し元はRETURNFコマンドか関数終了時のみ
     //if (functionList.Count == 0)
     //    throw new ExeEE("実行中の関数が存在しません");
     //非イベント呼び出しなので、これは起こりえない
     //else if (functionList.Count != 1)
     //    throw new ExeEE("関数が複数ある");
     if (Program.DebugMode)
     {
         console.DebugRemoveTraceLog();
     }
     //OutはGetValue側で行う
     //functionList[0].TopLabel.Out();
     currentLine = functionList[functionList.Count - 1].ReturnAddress;
     functionList.RemoveAt(functionList.Count - 1);
     //nextLine = null;
     MethodReturnValue = ret;
     return;
 }
 public void SetValue(SingleTerm value, ExpressionMediator exm)
 {
     if (Identifier.VariableType == typeof(Int64))
         SetValue(value.Int, exm);
     else
         SetValue(value.Str, exm);
 }
            public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
            {
                IOperandTerm[] terms = popTerms(line);
                if (!checkArgumentType(line, exm, terms))
                    return null;

                VariableTerm varTerm = getChangeableVariable(terms, 1, line);
                if (varTerm == null)
                    return null;
                if (!varTerm.Identifier.IsCharacterData)
                { warn("第1引数にキャラクタ変数以外の変数を指定することはできません", line, 2, false); return null; }
                //1803beta004 暫定CDFLAGを弾く
                if (varTerm.Identifier.IsArray2D)
                { warn("第1引数に二次元配列の変数を指定することはできません", line, 2, false); return null; }
                IOperandTerm index, term, term4 = null, term5 = null;
                if (terms.Length > 1)
                    index = terms[1];
                else
                    index = new SingleTerm(0);
                if (terms.Length > 2)
                    term = terms[2];
                else
                {
                    if (varTerm.IsString)
                        term = new SingleTerm("");
                    else
                        term = new SingleTerm(0);
                }
                if (terms.Length > 3)
                    term4 = terms[3];
                if (terms.Length > 4)
                    term5 = terms[4];
                if (index is SingleTerm && index.GetOperandType() == typeof(string) && varTerm.Identifier.IsArray1D)
                {
                    if (!GlobalStatic.ConstantData.isDefined(varTerm.Identifier.Code, ((SingleTerm)index).Str))
                    { warn("文字列" + index.GetStrValue(null) + "は変数" + varTerm.Identifier.Name + "の要素ではありません", line, 2, false); return null; }
                }
                if (terms.Length > 3 && !varTerm.Identifier.IsArray1D)
                    warn("第4引数以降は1次元配列以外では無視されます", line, 1, false);
                if (term.GetOperandType() != varTerm.GetOperandType())
                {
                    warn("2つの引数の型が一致していません", line, 2, false);
                    return null;
                }
                return new SpCVarSetArgument(varTerm, index, term, term4, term5);
            }
            public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
            {
                IOperandTerm[] terms = popTerms(line);
                if (!checkArgumentType(line, exm, terms))
                    return null;
                VariableTerm varTerm = getChangeableVariable(terms, 1, line);
                if (varTerm == null)
                    return null;
                if (varTerm.Identifier.IsCharacterData)
                { warn("第1引数にキャラクタ変数を指定することはできません", line, 2, false); return null; }

                IOperandTerm start = terms[1];
                IOperandTerm end = terms[2];
                IOperandTerm step = null;
                if (start == null)
                    start = new SingleTerm(0);
                if ((terms.Length > 3) && (terms[3] != null))
                    step = terms[3];
                else
                    step = new SingleTerm(1);
                if (!start.IsInteger)
                { warn("第2引数の型が違います", line, 2, false); return null; }
                return new SpForNextArgment(varTerm, start, end, step);
            }
            public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
            {
                IOperandTerm[] terms = popTerms(line);
                if (!checkArgumentType(line, exm, terms))
                    return null;
                IOperandTerm term = null;
                if (terms.Length == 0)
                {
                    term = new SingleTerm(0);
                    if (!nullable)
                    {
                        if (line.Function.IsExtended())
                            warn("省略できない引数が省略されています。Emueraは0を補います", line, 1, false);
                        else
                            warn("省略できない引数が省略されています。Emueraは0を補いますがeramakerの動作は不定です", line, 1, false);
                    }
                }
                else
                {
                    term = terms[0];
                }

                if (line.FunctionCode == FunctionCode.REPEAT)
                {
                    if ((term is SingleTerm) && (term.GetIntValue(null) <= 0L))
                    {
                        warn("0回以下のREPEATです。(eramakerではエラーになります)", line, 0, true);
                    }
                    VariableToken count = GlobalStatic.VariableData.GetSystemVariableToken("COUNT");
                    VariableTerm repCount = new VariableTerm(count, new IOperandTerm[] { new SingleTerm(0) });
                    repCount.Restructure(exm);
                    return new SpForNextArgment(repCount, new SingleTerm(0), term, new SingleTerm(1));
                }
                ExpressionArgument ret = new ExpressionArgument(term);
                if (term is SingleTerm)
                {
                    Int64 i = term.GetIntValue(null);
                    ret.ConstInt = i;
                    ret.IsConst = true;
                    if (line.FunctionCode == FunctionCode.CLEARLINE)
                    {
                        if (i <= 0L)
                            warn("引数に0以下の値が渡されています(この行は何もしません)", line, 1, false);
                    }
                    else if (line.FunctionCode == FunctionCode.FONTSTYLE)
                    {
                        if (i < 0L)
                            warn("引数に負の値が渡されています(結果は不定です)", line, 1, false);
                    }
                }
                return ret;
            }
            public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
            {
                StringStream st = line.PopArgumentPrimitive();
                IOperandTerm funcname = null;
                if (form)
                {
                    StrFormWord sfw = LexicalAnalyzer.AnalyseFormattedString(st, FormStrEndWith.LeftParenthesis_Bracket_Comma_Semicolon, true);
                    funcname = ExpressionParser.ToStrFormTerm(sfw);
                    funcname = funcname.Restructure(exm);
                }
                else
                {
                    string str = LexicalAnalyzer.ReadString(st, StrEndWith.LeftParenthesis_Bracket_Comma_Semicolon);
                    str = str.Trim(new char[] { ' ', '\t' });
                    funcname = new SingleTerm(str);
                }
                char cur = st.Current;
                WordCollection wc = LexicalAnalyzer.Analyse(st, LexEndWith.EoL, false, false);
                wc.ShiftNext();

                IOperandTerm[] subNames = null;
                IOperandTerm[] args = null;
                if (cur == '[')
                {
                    subNames = ExpressionParser.ReduceArguments(wc, ArgsEndWith.RightBracket, false);
                    if (!wc.EOL)
                    {
                        if (wc.Current.Type != '(')
                        wc.ShiftNext();
                        args = ExpressionParser.ReduceArguments(wc, ArgsEndWith.RightParenthesis, false);
                    }
                }
                if ((cur == '(') || (cur == ','))
                {
                    if (cur == '(')
                        args = ExpressionParser.ReduceArguments(wc, ArgsEndWith.RightParenthesis, false);
                    else
                        args = ExpressionParser.ReduceArguments(wc, ArgsEndWith.EoL, false);
                    if (!wc.EOL)
                    { warn("書式が間違っています", line, 2, false); return null; }
                }
                if (subNames == null)
                    subNames = new IOperandTerm[0];
                if (args == null)
                    args = new IOperandTerm[0];
                for(int i = 0; i < subNames.Length; i++)
                    if (subNames != null)
                        subNames[i] = subNames[i].Restructure(exm);
                for(int i = 0; i < args.Length; i++)
                    if (args[i] != null)
                        args[i] = args[i].Restructure(exm);
                Argument ret = null;
                if(callf)
                    ret = new SpCallFArgment(funcname, subNames, args);
                else
                    ret = new SpCallArgment(funcname, subNames, args);
                if (funcname is SingleTerm)
                {
                    ret.IsConst = true;
                    ret.ConstStr = funcname.GetStrValue(null);
                    if (ret.ConstStr == "")
                    {
                        warn("関数名が指定されていません", line, 2, false);
                        return null;
                    }
                }
                return ret;
            }
            public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
            {
                IOperandTerm[] terms = popTerms(line);
                if (!checkArgumentType(line, exm, terms))
                    return null;
                VariableTerm varTerm = getChangeableVariable(terms, 1, line);
                if (varTerm == null)
                    return null;
                if (varTerm.Identifier.Readonly)
                {
                    warn("読み取り専用の変数" + varTerm.Identifier.Name + "が指定されました", line, 2, false);
                    return null;
                }

                IOperandTerm term, term3 = null, term4 = null;
                if (terms.Length > 1)
                    term = terms[1];
                else
                {
                    if (varTerm.IsString)
                        term = new SingleTerm("");
                    else
                        term = new SingleTerm(0);
                }
                if (terms.Length > 2)
                    term3 = terms[2];
                if (terms.Length > 3)
                    term4 = terms[3];
                if (terms.Length >= 3 && !varTerm.Identifier.IsArray1D)
                    warn("第3引数以降は1次元配列以外では無視されます", line, 1, false);
                if (term.GetOperandType() != varTerm.GetOperandType())
                {
                    warn("2つの引数の型が一致していません", line, 2, false);
                    return null;
                }
                return new SpVarSetArgument(varTerm, term, term3, term4);
            }
            public override Argument CreateArgument(InstructionLine line, ExpressionMediator exm)
            {
                SortOrder order = SortOrder.ASCENDING;
                WordCollection wc = popWords(line);
                IOperandTerm term3 = new SingleTerm(0);
                IOperandTerm term4 = null;

                if (wc.EOL)
                {
                    warn("書式が間違っています", line, 2, false); return null;
                }

                VariableTerm varTerm;
                IOperandTerm term = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.Comma);
                if (term == null)
                { warn("書式が間違っています", line, 2, false); return null; }
                varTerm = term.Restructure(exm) as VariableTerm;
                if (varTerm == null)
                { warn("第1引数に変数以外を指定することはできません", line, 2, false); return null; }
                else if (varTerm.Identifier.Readonly)
                { warn("第1引数が読み込み専用の変数です", line, 2, false); return null; }
                if (!varTerm.Identifier.IsArray1D)
                { warn("第1引数に1次元配列もしくは配列型キャラクタ変数以外を指定することはできません", line, 2, false); return null; }

                wc.ShiftNext();
                IdentifierWord id = wc.Current as IdentifierWord;

                if ((id != null) && (id.Code.Equals("FORWARD", Config.SCVariable) || (id.Code.Equals("BACK", Config.SCVariable))))
                {
                    if (id.Code.Equals("BACK", Config.SCVariable))
                        order = SortOrder.DESENDING;
                    wc.ShiftNext();
                }
                else if (id != null)
                { warn("第2引数にソート方法指定子(FORWARD or BACK)以外が指定されています", line, 2, false); return null; }

                if (id != null)
                {
                    wc.ShiftNext();
                    if (!wc.EOL)
                    {
                        term3 = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.Comma);
                        if (term3 == null)
                        { warn("第3引数が解釈出来ません", line, 2, false); return null; }
                        if (!term3.IsInteger)
                        { warn("第3引数が数値ではありません", line, 2, false); return null; }
                        wc.ShiftNext();
                        if (!wc.EOL)
                        {
                            term4 = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.Comma);
                            if (term4 == null)
                            { warn("第4引数が解釈出来ません", line, 2, false); return null; }
                            if (!term4.IsInteger)
                            { warn("第4引数が数値ではありません", line, 2, false); return null; }
                            wc.ShiftNext();
                            if (!wc.EOL)
                                warn("引数が多すぎます", line, 1, false);
                        }
                    }
                }
                return new SpArraySortArgument(varTerm, order, term3, term4);
            }
Exemple #10
0
        private void parseLabel(FunctionLabelLine label)
        {
            WordCollection wc = label.PopRowArgs();
            string errMes = null;
            SingleTerm[] subNames = new SingleTerm[0];
            VariableTerm[] args = new VariableTerm[0];
            SingleTerm[] defs = new SingleTerm[0];
            int maxArg = -1;
            int maxArgs = -1;
            //1807 非イベント関数のシステム関数については警告レベル低下&エラー解除&引数を設定するように。
            if (label.IsEvent)
            {
                if (!wc.EOL)
                    ParserMediator.Warn("イベント関数@" + label.LabelName + " に引数は設定できません", label, 2, true, false);
                //label.SubNames = subNames;
                label.Arg = args;
                label.Def = defs;
                label.ArgLength = -1;
                label.ArgsLength = -1;
                return;
            }

            if (!wc.EOL)
            {
                if (label.IsSystem)
                    ParserMediator.Warn("システム関数@" + label.LabelName + " に引数が設定されています", label, 1, false, false);
                SymbolWord symbol = wc.Current as SymbolWord;
                wc.ShiftNext();
                if (symbol == null)
                { errMes = "引数の書式が間違っています"; goto err; }
                if (symbol.Type == '[')
                {
                    IOperandTerm[] subNamesRow = ExpressionParser.ReduceArguments(wc, ArgsEndWith.RightBracket, false);
                    if (subNamesRow.Length == 0)
                    { errMes = "関数定義の[]内の引数は空にできません"; goto err; }
                    subNames = new SingleTerm[subNamesRow.Length];
                    for (int i = 0; i < subNamesRow.Length; i++)
                    {
                        if (subNamesRow[i] == null)
                        { errMes = "関数定義の引数は省略できません"; goto err; }
                        IOperandTerm term = subNamesRow[i].Restructure(exm);
                        subNames[i] = term as SingleTerm;
                        if (subNames[i] == null)
                        { errMes = "関数定義の[]内の引数は定数のみ指定できます"; goto err; }
                    }
                    symbol = wc.Current as SymbolWord;
                    if ((!wc.EOL) && (symbol == null))
                    { errMes = "引数の書式が間違っています"; goto err; }
                    wc.ShiftNext();
                }
                if (!wc.EOL)
                {
                    IOperandTerm[] argsRow = null;
                    if (symbol.Type == ',')
                        argsRow = ExpressionParser.ReduceArguments(wc, ArgsEndWith.EoL, true);
                    else if (symbol.Type == '(')
                        argsRow = ExpressionParser.ReduceArguments(wc, ArgsEndWith.RightParenthesis, true);
                    else
                    { errMes = "引数の書式が間違っています"; goto err; }
                    int length = argsRow.Length / 2;
                    args = new VariableTerm[length];
                    defs = new SingleTerm[length];
                    for (int i = 0; i < length; i++)
                    {
                        VariableTerm vTerm = null;
                        SingleTerm def = null;
                        IOperandTerm term = argsRow[i * 2];
                        //引数読み取り時点で判別されないといけない
                        //if (term == null)
                        //{ errMes = "関数定義の引数は省略できません"; goto err; }
                        vTerm = term.Restructure(exm) as VariableTerm;
                        if ((vTerm == null) || (vTerm.Identifier.Readonly))
                        { errMes = "関数定義の引数には代入可能な変数を指定してください"; goto err; }
                        else if (!vTerm.isAllConst)
                        { errMes = "関数定義の引数の添え字には定数を指定してください"; goto err; }
                        if (vTerm.Identifier.Code == VariableCode.ARG)
                        {
                            if (maxArg < vTerm.getEl1forArg + 1)
                                maxArg = vTerm.getEl1forArg + 1;
                        }
                        else if (vTerm.Identifier.Code == VariableCode.ARGS)
                        {
                            if (maxArgs < vTerm.getEl1forArg + 1)
                                maxArgs = vTerm.getEl1forArg + 1;
                        }
                        bool canDef = (vTerm.Identifier.Code == VariableCode.ARG || vTerm.Identifier.Code == VariableCode.ARGS || vTerm.Identifier.IsPrivate);
                        term = argsRow[i * 2 + 1];
                        if (term is NullTerm)
                        {
                            if (canDef)// && label.ArgOptional)
                            {
                                if (vTerm.GetOperandType() == typeof(Int64))
                                    def = new SingleTerm(0);
                                else
                                    def = new SingleTerm("");
                            }
                        }
                        else
                        {
                            def = term.Restructure(exm) as SingleTerm;
                            if (def == null)
                            { errMes = "引数の初期値には定数のみを指定できます"; goto err; }
                            if (!canDef)
                            { errMes = "引数の初期値を定義できるのは\"ARG\"、\"ARGS\"またはプライベート変数のみです"; goto err; }
                            else if (vTerm.Identifier.IsReference)
                            { errMes = "参照渡しの引数に初期値は定義できません"; goto err; }
                            if (vTerm.GetOperandType() != def.GetOperandType())
                            { errMes = "引数の型と初期値の型が一致していません"; goto err; }
                        }
                        args[i] = vTerm;
                        defs[i] = def;
                    }

                }
            }
            if (!wc.EOL)
            { errMes = "引数の書式が間違っています"; goto err; }

            //label.SubNames = subNames;
            label.Arg = args;
            label.Def = defs;
            label.ArgLength = maxArg;
            label.ArgsLength = maxArgs;
            return;
            err:
            ParserMediator.Warn("関数@" + label.LabelName + " の引数のエラー:" + errMes, label, 2, true, false);
            return;
        }
        public void SetValueAllEachChara(FixedVariableTerm p, SingleTerm index, string srcValue, int start, int end)
        {
            if (!p.Identifier.IsString)
                throw new CodeEE("文字列型でない変数" + p.Identifier.Name + "に文字列型を代入しようとしました");
            if (p.Identifier.Readonly)
                throw new CodeEE("読み取り専用の変数" + p.Identifier.Name + "に代入しようとしました");
            if (p.Identifier.IsCalc)
            {
                if (p.Identifier.Code == VariableCode.WINDOW_TITLE)
                {
                    GlobalStatic.Console.SetWindowTitle(srcValue);
                    return;
                }
                //一応チェック済み
                //throw new ExeEE("READONLYでないCALC変数の代入処理が設定されていない");
                return;
            }
            if (varData.CharacterList.Count == 0)
                return;

            CharacterData chara = varData.CharacterList[0];
            Int64 indexNum = -1;

            if (p.Identifier.IsArray1D)
            {
                if (index.GetOperandType() == typeof(Int64))
                    indexNum = index.Int;
                else
                    indexNum = constant.KeywordToInteger(p.Identifier.Code, index.Str, 1);
                string[] array = chara.DataStringArray[p.Identifier.VarCodeInt];
                if (indexNum < 0 || indexNum >= array.Length)
                    throw new CodeEE("キャラクタ配列変数" + p.Identifier.Name + "の第2引数(" + indexNum.ToString() + ")は配列の範囲外です");
            }

            for (int i = start; i < end; i++)
            {
                chara = varData.CharacterList[i];
                if (p.Identifier.IsArray1D)
                    chara.DataStringArray[p.Identifier.VarCodeInt][indexNum] = srcValue;
                else
                    chara.DataString[p.Identifier.VarCodeInt] = srcValue;
            }
        }
Exemple #12
0
        public static StrForm FromWordToken(StrFormWord wt)
        {
            StrForm ret = new StrForm();
            ret.strs = wt.Strs;
            IOperandTerm[] termArray = new IOperandTerm[wt.SubWords.Length];
            for (int i = 0; i < wt.SubWords.Length; i++)
            {
                SubWord SWT = wt.SubWords[i];
                TripleSymbolSubWord tSymbol = SWT as TripleSymbolSubWord;
                if (tSymbol != null)
                {
                    switch (tSymbol.Code)
                    {
                        case '*':
                            termArray[i] = NameTarget;
                            continue;
                        case '+':
                            termArray[i] = CallnameMaster;
                            continue;
                        case '=':
                            termArray[i] = CallnamePlayer;
                            continue;
                        case '/':
                            termArray[i] = NameAssi;
                            continue;
                        case '$':
                            termArray[i] = CallnameTarget;
                            continue;
                    }
                    throw new ExeEE("何かおかしい");
                }
                WordCollection wc = null;
                IOperandTerm operand = null;
                YenAtSubWord yenat = SWT as YenAtSubWord;
                if (yenat != null)
                {
                    wc = yenat.Words;
                    if (wc != null)
                    {
                        operand = ExpressionParser.ReduceIntegerTerm(wc, TermEndWith.EoL);
                        if (!wc.EOL)
                            throw new CodeEE("三項演算子\\@の第一オペランドが異常です");
                    }
                    else
                        operand = new SingleTerm(0);
                    IOperandTerm left = new StrFormTerm(StrForm.FromWordToken(yenat.Left));
                    IOperandTerm right = null;
                    if (yenat.Right == null)
                        right = new SingleTerm("");
                    else
                        right = new StrFormTerm(StrForm.FromWordToken(yenat.Right));
                    termArray[i] = new FunctionMethodTerm(formatYenAt, new IOperandTerm[] { operand, left, right });
                    continue;
                }
                wc = SWT.Words;
                operand = ExpressionParser.ReduceExpressionTerm(wc, TermEndWith.Comma);
                if (operand == null)
                {
                    if (SWT is CurlyBraceSubWord)
                        throw new CodeEE("{}の中に式が存在しません");
                    else
                        throw new CodeEE("%%の中に式が存在しません");
                }
                IOperandTerm second = null;
                SingleTerm third = null;
                wc.ShiftNext();
                if (!wc.EOL)
                {
                    second = ExpressionParser.ReduceIntegerTerm(wc, TermEndWith.Comma);

                    wc.ShiftNext();
                    if (!wc.EOL)
                    {
                        IdentifierWord id = wc.Current as IdentifierWord;
                        if (id == null)
                            throw new CodeEE("','の後にRIGHT又はLEFTがありません");
                        if (string.Equals(id.Code, "LEFT", Config.SCVariable))//標準RIGHT
                            third = new SingleTerm(1);
                        else if (!string.Equals(id.Code, "RIGHT", Config.SCVariable))
                            throw new CodeEE("','の後にRIGHT又はLEFT以外の単語があります");
                        wc.ShiftNext();
                    }
                    if (!wc.EOL)
                        throw new CodeEE("RIGHT又はLEFTの後に余分な文字があります");
                }
                if (SWT is CurlyBraceSubWord)
                {
                    if (operand.GetOperandType() != typeof(Int64))
                        throw new CodeEE("{}の中の式が数式ではありません");
                    termArray[i] = new FunctionMethodTerm(formatCurlyBrace, new IOperandTerm[] { operand, second, third });
                    continue;
                }
                if (operand.GetOperandType() != typeof(string))
                    throw new CodeEE("%%の中の式が文字列式ではありません");
                termArray[i] = new FunctionMethodTerm(formatPercent, new IOperandTerm[] { operand, second, third });
            }
            ret.terms = termArray;
            return ret;
        }