Exemplo n.º 1
0
        private static int GetInstructionType(string input)
        {
            // Find start of instruction name after equal sign
            var instructionIndex = input.IndexOf("=") + 1;

            while (input[instructionIndex] == ' ')
            {
                instructionIndex++;
            }

            var instructionPart = input.Substring(instructionIndex, input.Length - instructionIndex);

            int endIndex;

            if (instructionPart.StartsWith("sub"))
            {
                // Parse sub number
                endIndex = instructionPart.IndexOf('(');
                return(int.Parse(instructionPart.Substring(3, endIndex - 3)));
            }

            endIndex = instructionPart.IndexOf('(');
            var instructionName = instructionPart.Substring(0, endIndex);

            if (RoutineMap.Values.Contains(instructionName))
            {
                return(RoutineMap.First(x => x.Value == instructionName).Key);
            }

            return(-1);
        }
Exemplo n.º 2
0
        public string GetString(IStringReader stringReader)
        {
            var args            = string.Join(", ", Arguments.Select(x => x.GetString(InstructionType, stringReader)));
            var subName         = RoutineMap.ContainsKey(InstructionType) ? RoutineMap[InstructionType] : $"sub{InstructionType}";
            var returnParameter = Parameter.Parse(ReturnParameter);

            return($"{returnParameter.ParameterName} = {subName}({args})");
        }