Exemplo n.º 1
0
        public override void Execute()
        {
            try
            {
                CommandContext.LastCommandFailed = false;

                Scanner scanner = new Scanner();
                Parser parser = new Parser(scanner);
                ParseTree parseTree = parser.Parse(Statement);
                if (0 < parseTree.Errors.Count)
                {
                    throw new ArgumentException(parseTree.Errors[0].Message);
                }

                object result = parseTree.Eval(null);
                ICommand command = (ICommand) result;

                CommandContext.ResultWriter = GetResultWriter();
                CommandContext.TextWriter = Console.Out;
                command.Validate();
                command.Execute();
            }
            catch (Exception ex)
            {
                CommandContext.LastCommandFailed = true;

                if (CommandContext.DebugLog)
                {
                    Console.WriteLine("Command execution failed with error:\n{0}", ex);
                }
                else
                {
                    while (null != ex.InnerException)
                    {
                        ex = ex.InnerException;
                    }

                    Console.WriteLine("Command execution failed with error '{0}'", ex.Message);
                }
            }
        }
Exemplo n.º 2
0
 public Parser(Scanner scanner)
 {
     this.scanner = scanner;
 }