Beispiel #1
0
        private ModelParser RunModelParser(CommandlineOptions options)
        {
            var fIn = System.IO.File.OpenText(options.InputFile);

            var runner = new ModelParser();

            runner.ParseInputFile(fIn);

            runner.DumpErrors();

            fIn.Close();
            return(runner);
        }
        public void ExecuteProgram(ModelParser modelParser, TemplateParser templateParser, Interpreter.Emitter.IEmitter emitter)
        {
            var instructions = templateParser.Program.Instructions;
            var context      = new Interpreter.InterpreterContext
            {
                Model   = modelParser.ModelCollector,
                Emitter = emitter
            };

            var PC = instructions[0];

            Interpreter.InterpreterInstructionBase next = null;

            while (PC != null)
            {
                try
                {
                    logger.Trace("Executing {0} on Line {1} Pos {2}", PC.Instruction, PC.Line, PC.Position);

                    next = PC.Execute(context);
                    if (PC.Result.Result == Interpreter.Evaluator.EvaluationResultValues.Failed)
                    {
                        string error = string.Format("Error during execution: {0} Line {1}, Pos {2}: {3}", PC.Result.Value, PC.Line, PC.Position, PC.Instruction);

                        HasErrors = true;
                        Errors.Add(error);
                        logger.Error(error);
                    }
                    else
                    {
                        context.EmitResult(PC.Result.Value);
                    }
                }
                catch (Exception e)
                {
                    Errors.Add(string.Format("Error during execution: {0} Line {1}, Pos {2}: {3}", e.Message, PC.Line, PC.Position, PC.Instruction));
                    HasErrors = true;
                    //break;
                }

                PC = next;
            }
        }
        public override void ExitIncludeStatement([NotNull] IncludeStatementContext context)
        {
            base.ExitIncludeStatement(context);

            var mp = new ModelParser();

            mp.ParseInputFile(context.GetText().Substring(1));

            foreach (var item in mp.ModelCollector.ParameterModels)
            {
                var exists = Collector.ParameterModels.FirstOrDefault(m => m.Name == item.Name);
                if (exists != null)
                {
                    exists.Value.AddRange(item.Value);
                }
                else
                {
                    Collector.ParameterModels.Add(item);
                }
            }
            foreach (var item in mp.ModelCollector.SingleModels)
            {
                var exists = Collector.SingleModels.FirstOrDefault(m => m.Name == item.Name);
                if (exists != null)
                {
                    exists.Value.AddRange(item.Value);
                }
                else
                {
                    Collector.SingleModels.Add(item);
                }
            }
            // get GraphElements from included
            foreach (var item in mp.GraphElements)
            {
                if (!GraphElements.ContainsKey(item.Key))
                {
                    GraphElements.Add(item.Key, item.Value);
                }
            }
        }