Ejemplo n.º 1
0
        public List<ParsedCommand> Parse()
        {
            List<ParsedCommand> parsedCommands = new List<ParsedCommand>();

            CleanCommands();

            foreach (var command in _commands)
            {
                ParsedCommand pc = new ParsedCommand();

                string[] splitCommand = command.Split(' ');

                pc.CommandType = GetCommandType(splitCommand[0]);

                SetArguments(pc, splitCommand);

                parsedCommands.Add(pc);
            }
            return parsedCommands;
        }
Ejemplo n.º 2
0
 private void SetArguments(ParsedCommand pc, string[] splitCommand)
 {
     switch (pc.CommandType)
     {
         case CommandType.C_ARITHMETIC:
             pc.Command = splitCommand[0];
             break;
         case CommandType.C_LABEL:
         case CommandType.C_GOTO:
         case CommandType.C_IF:
             pc.Arg1 = splitCommand[1];
             break;
         case CommandType.C_FUNCTION:
         case CommandType.C_CALL:
         case CommandType.C_PUSH:
         case CommandType.C_POP:
             pc.Arg1 = splitCommand[1];
             pc.Arg2 = splitCommand[2];
             break;
     }
 }