/// <summary>
        /// Compiles code into the statemachine.
        /// </summary>
        /// <param name="source">The SMG source code.</param>
        /// <returns>The current statemachine.</returns>
        public StateMachine CompileStream(Stream source)
        {
            var scanner = new Scanner(source);
            var parser = new Parser(scanner);
            parser.OnSyntaxError += HandleSyntaxError;
            parser.Parameters = Parameters;
            parser.SM = SM;

            try
            {
                parser.Parse();
            }
            catch(CompilerException ex)
            {
                SM.AddError(ex);
            }

            if(SM.IsFailed)
            {
                throw new AggregateException(SM.Errors);
            }

            return SM;
        }
        public ICondition EvaluateCondition(string text)
        {
            var ms = MakeStream("EVAL " + text);

            var scanner = new Scanner(ms);
            var parser = new Parser(scanner);
            parser.SM = _sm;

            parser.Parse();

            if (parser.errors.count > 0)
            {
                throw new Exception("failed to parse condition: " + parser.errors);
            }

            return parser.Result;
        }