Beispiel #1
0
        private static bool ExecuteCommand(string cmd)
        {
            try
            {
                Scanner scanner = new Scanner();
                Parser.Parser parser = new Parser.Parser(scanner);
                ParseTree parseTree = parser.Parse(cmd);
                if (0 < parseTree.Errors.Count)
                {
                    Console.WriteLine(parseTree.Errors[0].Message);
                    return false;
                }

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

                CommandContext.ResultWriter = GetResultWriter();
                command.Execute();
                return true;
            }
            catch (Exception ex)
            {
                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);
                }

                return false;
            }
            finally
            {
                Console.WriteLine();
            }
        }
Beispiel #2
0
 public Parser(Scanner scanner)
 {
     this.scanner = scanner;
 }