public Sequence ParseSequence(String seqStr) { SequenceParserEnvironmentInterpreted parserEnv = new SequenceParserEnvironmentInterpreted(curActions); List <string> warnings = new List <string>(); Sequence seq = SequenceParser.ParseSequence(seqStr, parserEnv, warnings); foreach (string warning in warnings) { System.Console.Error.WriteLine(warning); } return(seq); }
public bool GenerateXGRSCode(string xgrsName, String package, String xgrsStr, String[] paramNames, GrGenType[] paramTypes, String[] defToBeYieldedToNames, GrGenType[] defToBeYieldedToTypes, SourceBuilder source, int lineNr) { Dictionary <String, String> varDecls = new Dictionary <String, String>(); for (int i = 0; i < paramNames.Length; ++i) { varDecls.Add(paramNames[i], TypesHelper.DotNetTypeToXgrsType(paramTypes[i])); } for (int i = 0; i < defToBeYieldedToNames.Length; ++i) { varDecls.Add(defToBeYieldedToNames[i], TypesHelper.DotNetTypeToXgrsType(defToBeYieldedToTypes[i])); } Sequence seq; try { SequenceParserEnvironmentCompiled parserEnv = new SequenceParserEnvironmentCompiled(package, actionNames, model); List <string> warnings = new List <string>(); seq = SequenceParser.ParseSequence(xgrsStr, parserEnv, varDecls, warnings); foreach (string warning in warnings) { Console.Error.WriteLine("The exec statement \"" + xgrsStr + "\" given on line " + lineNr + " reported back:\n" + warning); } seq.Check(env); seq.SetNeedForProfilingRecursive(emitProfiling); } catch (ParseException ex) { Console.Error.WriteLine("The exec statement \"" + xgrsStr + "\" given on line " + lineNr + " caused the following error:\n" + ex.Message); return(false); } catch (SequenceParserException ex) { Console.Error.WriteLine("The exec statement \"" + xgrsStr + "\" given on line " + lineNr + " caused the following error:\n"); HandleSequenceParserException(ex); return(false); } source.Append("\n"); source.AppendFront("public static bool ApplyXGRS_" + xgrsName + "(GRGEN_LGSP.LGSPGraphProcessingEnvironment procEnv"); for (int i = 0; i < paramNames.Length; ++i) { source.Append(", " + TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(paramTypes[i]), model) + " var_"); source.Append(paramNames[i]); } for (int i = 0; i < defToBeYieldedToTypes.Length; ++i) { source.Append(", ref " + TypesHelper.XgrsTypeToCSharpType(TypesHelper.DotNetTypeToXgrsType(defToBeYieldedToTypes[i]), model) + " var_"); source.Append(defToBeYieldedToNames[i]); } source.Append(")\n"); source.AppendFront("{\n"); source.Indent(); source.AppendFront("GRGEN_LGSP.LGSPGraph graph = procEnv.graph;\n"); source.AppendFront("GRGEN_LGSP.LGSPActions actions = procEnv.curActions;\n"); neededEntitiesEmitter.Reset(); if (fireDebugEvents) { source.AppendFrontFormat("procEnv.DebugEntering(\"{0}\", \"{1}\");\n", InjectExec(xgrsName), xgrsStr.Replace("\\", "\\\\").Replace("\"", "\\\"")); } neededEntitiesEmitter.EmitNeededVarAndRuleEntities(seq, source); seqGen.EmitSequence(seq, source); if (fireDebugEvents) { source.AppendFrontFormat("procEnv.DebugExiting(\"{0}\");\n", InjectExec(xgrsName)); } source.AppendFront("return " + seqGen.GetSequenceResult(seq) + ";\n"); source.Unindent(); source.AppendFront("}\n"); List <SequenceExpressionContainerConstructor> containerConstructors = new List <SequenceExpressionContainerConstructor>(); Dictionary <SequenceVariable, SetValueType> variables = new Dictionary <SequenceVariable, SetValueType>(); seq.GetLocalVariables(variables, containerConstructors, null); foreach (SequenceExpressionContainerConstructor cc in containerConstructors) { SequenceContainerConstructorEmitter.GenerateContainerConstructor(model, cc, source); } return(true); }
public bool GenerateDefinedSequence(SourceBuilder source, DefinedSequenceInfo sequence) { Dictionary <String, String> varDecls = new Dictionary <String, String>(); for (int i = 0; i < sequence.Parameters.Length; i++) { varDecls.Add(sequence.Parameters[i], TypesHelper.DotNetTypeToXgrsType(sequence.ParameterTypes[i])); } for (int i = 0; i < sequence.OutParameters.Length; i++) { varDecls.Add(sequence.OutParameters[i], TypesHelper.DotNetTypeToXgrsType(sequence.OutParameterTypes[i])); } Sequence seq; try { SequenceParserEnvironmentCompiled parserEnv = new SequenceParserEnvironmentCompiled(sequence.Package, actionNames, model); List <string> warnings = new List <string>(); seq = SequenceParser.ParseSequence(sequence.XGRS, parserEnv, varDecls, warnings); foreach (string warning in warnings) { Console.Error.WriteLine("In the defined sequence " + sequence.Name + " the exec part \"" + sequence.XGRS + "\" reported back:\n" + warning); } seq.Check(env); seq.SetNeedForProfilingRecursive(emitProfiling); } catch (ParseException ex) { Console.Error.WriteLine("In the defined sequence " + sequence.Name + " the exec part \"" + sequence.XGRS + "\" caused the following error:\n" + ex.Message); return(false); } catch (SequenceParserException ex) { Console.Error.WriteLine("In the defined sequence " + sequence.Name + " the exec part \"" + sequence.XGRS + "\" caused the following error:\n"); HandleSequenceParserException(ex); return(false); } // exact sequence definition compiled class source.Append("\n"); if (sequence.Package != null) { source.AppendFrontFormat("namespace {0}\n", sequence.Package); source.AppendFront("{\n"); source.Indent(); } source.AppendFront("public class Sequence_" + sequence.Name + " : GRGEN_LIBGR.SequenceDefinitionCompiled\n"); source.AppendFront("{\n"); source.Indent(); GenerateSequenceDefinedSingleton(source, sequence); source.Append("\n"); GenerateGenericMethodReturnValues(source, sequence); source.Append("\n"); GenerateInternalDefinedSequenceApplicationMethod(source, sequence, seq); source.Append("\n"); GenerateExactExternalDefinedSequenceApplicationMethod(source, sequence); source.Append("\n"); GenerateGenericExternalDefinedSequenceApplicationMethod(source, sequence); // end of exact sequence definition compiled class source.Unindent(); source.AppendFront("}\n"); if (sequence.Package != null) { source.Unindent(); source.AppendFront("}\n"); } return(true); }