Esempio n. 1
0
        /// <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);
        }