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); }
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; }