示例#1
0
 private static IEnumerable <ProgramLine> ParseText(this IEnumerable <String> textLines)
 {
     // ここで ToArray() して内容を実行させる。IEnumerable<ProgramLine> のままにしておくと、
     // 遅延評価で必要になるたびに実行される。
     return(textLines.Select((text) => ProgramLine.Parse(text))
            .ToArray());
 }
示例#2
0
        private Token ReadNext()
        {
            Char firstChar = m_buffer.Current;

            if (ProgramLine.EndOfField(firstChar))
            {
                return(Token.MakeEndOfToken());
            }
            else if (firstChar == Casl2Defs.Comma)
            {
                m_buffer.MoveNext();
                return(Token.MakeComma());
            }
            else if (firstChar == Casl2Defs.EqualSign)
            {
                m_buffer.MoveNext();
                return(Token.MakeEqualSign());
            }
            else if (DecimalConstant.IsStart(firstChar))
            {
                Int32 i32Value = DecimalConstant.Read(m_buffer);
                return(Token.MakeDecimalConstant(i32Value));
            }
            else if (HexaDecimalConstant.IsStart(firstChar))
            {
                Int32 i32Value = HexaDecimalConstant.Read(m_buffer);
                return(Token.MakeHexaDecimalConstant(i32Value));
            }
            else if (StringConstant.IsStart(firstChar))
            {
                String strValue = StringConstant.Read(m_buffer);
                return(Token.MakeStringConstant(strValue));
            }
            else if (Label.IsStart(firstChar))
            {
                // ラベルはレジスタ名の場合もある。オペランドの字句要素の区切りまで読み込む。
                String strValue = Operand.ReadItem(m_buffer);
                if (ProgramRegister.IsRegisterName(strValue))
                {
                    return(Token.MakeRegisterName(strValue));
                }
                else
                {
                    return(Token.MakeLabel(strValue));
                }
            }
            else
            {
                String message = String.Format(Resources.MSG_CouldNotParseAsToken, firstChar);
                throw new Casl2SimulatorException(message);
            }
        }
示例#3
0
 internal IEnumerable <ProgramLine> ExpandMacro()
 {
     String[] expandedText = m_instruction.ExpandMacro(m_label);
     if (expandedText == null)
     {
         yield return(this);
     }
     else
     {
         foreach (String text in expandedText)
         {
             ProgramLine parsedLine = Parse(text);
             yield return(parsedLine);
         }
     }
 }
示例#4
0
        internal override String[] ExpandMacro(Label label)
        {
            String[] result = new String[7];
            // LABEL    POP     0,GR7
            //          POP     0,GR6
            //          POP     0,GR5
            //          POP     0,GR4
            //          POP     0,GR3
            //          POP     0,GR2
            //          POP     0,GR1
            result[0] = ProgramLine.Generate(label, MnemonicDef.POP, RegisterDef.GR7);
            result[1] = ProgramLine.Generate(null, MnemonicDef.POP, RegisterDef.GR6);
            result[2] = ProgramLine.Generate(null, MnemonicDef.POP, RegisterDef.GR5);
            result[3] = ProgramLine.Generate(null, MnemonicDef.POP, RegisterDef.GR4);
            result[4] = ProgramLine.Generate(null, MnemonicDef.POP, RegisterDef.GR3);
            result[5] = ProgramLine.Generate(null, MnemonicDef.POP, RegisterDef.GR2);
            result[6] = ProgramLine.Generate(null, MnemonicDef.POP, RegisterDef.GR1);

            return(result);
        }
示例#5
0
        internal override String[] ExpandMacro(Label label)
        {
            String[] result = new String[7];

            // LABEL    PUSH    0,GR1
            //          PUSH    0,GR2
            //          LAD     GR1,BUF
            //          LAD     GR2,LEN
            //          SVC     1 or 2
            //          POP     GR2
            //          POP     GR1
            result[0] = ProgramLine.Generate(label, MnemonicDef.PUSH, 0, SvcDef.BufferAddrRegister);
            result[1] = ProgramLine.Generate(null, MnemonicDef.PUSH, 0, SvcDef.LengthRegister);
            result[2] = ProgramLine.Generate(null, MnemonicDef.LAD, SvcDef.BufferAddrRegister, AreaSpec.Buffer.Name);
            result[3] = ProgramLine.Generate(null, MnemonicDef.LAD, SvcDef.LengthRegister, AreaSpec.Length.Name);
            result[4] = ProgramLine.Generate(null, MnemonicDef.SVC, m_svcOperand);
            result[5] = ProgramLine.Generate(null, MnemonicDef.POP, SvcDef.LengthRegister);
            result[6] = ProgramLine.Generate(null, MnemonicDef.POP, SvcDef.BufferAddrRegister);

            return(result);
        }
示例#6
0
 private static Boolean EndOfItem(Char current)
 {
     return(ProgramLine.EndOfField(current) || current == Casl2Defs.Comma);
 }
 internal static String Generate(Label label, params Constant[] constants)
 {
     return(ProgramLine.Generate(label, MnemonicDef.DC, constants));
 }