Ejemplo n.º 1
0
        /// <summary>
        /// \@直後からの開始、\@の直後がCurrentになる
        /// </summary>
        /// <param name="st"></param>
        /// <returns></returns>
        public static YenAtSubWord AnalyseYenAt(StringStream st)
        {
            WordCollection w = Analyse(st, LexEndWith.Question, LexAnalyzeFlag.None);

            if (st.Current != '?')
            {
                throw new CodeEE("\'\\@\'が使われましたが対応する\'?\'が見つかりません");
            }
            st.ShiftNext();
            StrFormWord left = AnalyseFormattedString(st, FormStrEndWith.Sharp, true);

            if (st.Current != '#')
            {
                if (st.Current != '@')
                {
                    throw new CodeEE("\'\\@\',\'?\'が使われましたが対応する\'#\'が見つかりません");
                }
                st.ShiftNext();
                ParserMediator.Warn("\'\\@\',\'?\'が使われましたが対応する\'#\'が見つかりません", GlobalStatic.Process.GetScaningLine(), 1, false, false);
                return(new YenAtSubWord(w, left, null));
            }
            st.ShiftNext();
            StrFormWord right = AnalyseFormattedString(st, FormStrEndWith.YenAt, true);

            if (st.Current != '@')
            {
                throw new CodeEE("\'\\@\',\'?\',\'#\'が使われましたが対応する\'\\@\'が見つかりません");
            }
            st.ShiftNext();
            return(new YenAtSubWord(w, left, right));
        }
Ejemplo n.º 2
0
 public YenAtSubWord(WordCollection w, StrFormWord fsLeft, StrFormWord fsRight)
     : base(w)
 {
     left = fsLeft;
     right = fsRight;
 }
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
0
 public YenAtSubWord(WordCollection w, StrFormWord fsLeft, StrFormWord fsRight)
     : base(w)
 {
     left  = fsLeft;
     right = fsRight;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 結果次第ではSingleTermを返すことがある。
 /// </summary>
 /// <returns></returns>
 public static IOperandTerm ToStrFormTerm(StrFormWord sfw)
 {
     StrForm strf = StrForm.FromWordToken(sfw);
     if(strf.IsConst)
         return new SingleTerm(strf.GetString(null));
     return new StrFormTerm(strf);
 }