/// <summary> /// Constructs the typed list rule from the specified parameters. /// </summary> /// <param name="p">Parent master grammar.</param> /// <param name="itemIdentifierType">Item identifier type.</param> /// <returns>Typed list grammar rule.</returns> public static NonTerminal ConstructTypedListRule(MasterGrammar p, IdentifierType itemIdentifierType) { // NON-TERMINAL AND TERMINAL SYMBOLS var typedList = new NonTerminal("Typed list", typeof(TypedListAstNode)); var singleTypedList = new NonTerminal("Single typed list", typeof(TransientAstNode)); var typeDeclaration = new NonTerminal("Type declaration", typeof(TransientAstNode)); var type = new NonTerminal("Type", typeof(TransientAstNode)); var typePlusList = new NonTerminal("Type list", typeof(TransientAstNode)); var identifiersList = new NonTerminal("Typed list identifiers", typeof(TransientAstNode)); var itemIdentifier = new IdentifierTerminal("Item identifier", itemIdentifierType); var typeIdentifier = new IdentifierTerminal("Type identifier", IdentifierType.CONSTANT); // RULES typedList.Rule = p.MakeStarRule(typedList, singleTypedList); singleTypedList.Rule = identifiersList + typeDeclaration; identifiersList.Rule = p.MakeStarRule(identifiersList, itemIdentifier); typeDeclaration.Rule = p.Empty | ("-" + type); type.Rule = typeIdentifier | ("(" + p.ToTerm("either") + typePlusList + ")"); typePlusList.Rule = p.MakePlusRule(typePlusList, typeIdentifier); return(typedList); }
/// <summary> /// Constructor of the grammar node. /// </summary> /// <param name="p">Parent master grammar.</param> public FunctionTypedList(MasterGrammar p) : base(p) { // NON-TERMINAL AND TERMINAL SYMBOLS var functionsTypedList = new NonTerminal("Functions typed list", typeof(FunctionTypedListAstNode)); var typedFuncBlock = new NonTerminal("Typed functions block", typeof(TransientAstNode)); var funcBlock = new NonTerminal("Functions block", typeof(TransientAstNode)); var singleFunction = new NonTerminal("Single function", typeof(TransientAstNode)); var singleFunctionBase = new NonTerminal("Single function base", typeof(TransientAstNode)); var functionIdentifier = new IdentifierTerminal("Function identifier", IdentifierType.CONSTANT); var typeDeclaration = new NonTerminal("Type declaration", typeof(TransientAstNode)); var type = new NonTerminal("Type", typeof(TransientAstNode)); var typePlusList = new NonTerminal("Type list", typeof(TransientAstNode)); var typeIdentifier = new IdentifierTerminal("Type identifier", IdentifierType.CONSTANT); // USED SUB-TREES var typedList = new TypedList(p); // RULES functionsTypedList.Rule = p.MakeStarRule(functionsTypedList, typedFuncBlock); typedFuncBlock.Rule = funcBlock + typeDeclaration; funcBlock.Rule = p.MakePlusRule(funcBlock, singleFunction); singleFunction.Rule = p.ToTerm("(") + singleFunctionBase + ")"; singleFunctionBase.Rule = functionIdentifier + typedList; typeDeclaration.Rule = p.Empty | ("-" + type); type.Rule = typeIdentifier | ("(" + p.ToTerm("either") + typePlusList + ")"); typePlusList.Rule = p.MakePlusRule(typePlusList, typeIdentifier); p.MarkTransient(singleFunction); Rule = functionsTypedList; }
/// <summary> /// Constructor of the grammar node. /// </summary> /// <param name="p">Parent master grammar.</param> /// <param name="numericExpression">Numeric expression type used within the numeric operation</param> /// <param name="bForm">Block form.</param> public NumericOp(MasterGrammar p, NonTerminal numericExpression, BForm bForm) : base(p, bForm, numericExpression) { // NON-TERMINAL AND TERMINAL SYMBOLS var numericOp = new NonTerminal("Numeric operation", typeof(TransientAstNode)); var numericOpBase = new NonTerminal("Numeric operation base", typeof(TransientAstNode)); var multiOp = new NonTerminal("Multiary operation", typeof(NumericOpAstNode)); var multiOperator = new NonTerminal("Multiary operator", typeof(TransientAstNode)); var multiOpArguments = new NonTerminal("Multiary operation arguments", typeof(TransientAstNode)); var binaryOp = new NonTerminal("Binary operation", typeof(NumericOpAstNode)); var binaryUnaryOp = new NonTerminal("Binary or unary operation", typeof(NumericOpAstNode)); var binaryOpSecondArg = new NonTerminal("Second argument of binary operation", typeof(TransientAstNode)); // USED SUB-TREES var numericExpr = SubExpression; // passed as a parameter // RULES numericOp.Rule = p.ToTerm("(") + numericOpBase + ")"; numericOpBase.Rule = multiOp | binaryOp | binaryUnaryOp; multiOp.Rule = multiOperator + numericExpr + multiOpArguments; // at least two numeric args multiOperator.Rule = p.ToTerm("*") | "+"; multiOpArguments.Rule = p.MakePlusRule(multiOpArguments, numericExpr); binaryOp.Rule = p.ToTerm("/") + numericExpr + numericExpr; // the only binary is division binaryUnaryOp.Rule = p.ToTerm("-") + numericExpr + binaryOpSecondArg; // unary/binary minus binaryOpSecondArg.Rule = numericExpr | p.Empty; p.MarkTransient(numericOp, numericOpBase, multiOperator, binaryOpSecondArg); Rule = (bForm == BForm.BASE) ? numericOpBase : numericOp; }
/// <summary> /// Constructor of the grammar node. /// </summary> /// <param name="p">Parent master grammar.</param> public Problem(MasterGrammar p) : base(p) { // NON-TERMINAL AND TERMINAL SYMBOLS var problem = new NonTerminal("Problem", typeof(ProblemAstNode)); var definedProblem = new NonTerminal("Defined problem", typeof(TransientAstNode)); var correspondingDomain = new NonTerminal("Corresponding domain", typeof(TransientAstNode)); var problemSections = new NonTerminal("Problem sections", typeof(TransientAstNode)); var problemSection = new NonTerminal("Problem section", typeof(TransientAstNode)); var problemSectionBase = new NonTerminal("Problem section base", typeof(TransientAstNode)); var requireDef = new NonTerminal("Requirements section", typeof(ProblemRequirementsAstNode)); var objectsDef = new NonTerminal("Objects section", typeof(ProblemObjectsAstNode)); var initDef = new NonTerminal("Init section", typeof(ProblemInitAstNode)); var goalDef = new NonTerminal("Goal section", typeof(ProblemGoalAstNode)); var constrDef = new NonTerminal("Constraints section", typeof(ProblemConstraintsAstNode)); var metricDef = new NonTerminal("Metric section", typeof(ProblemMetricAstNode)); var lengthDef = new NonTerminal("Length section", typeof(ProblemLengthAstNode)); var requireList = new NonTerminal("Requirements list", typeof(TransientAstNode)); var initElemList = new NonTerminal("Init elements list", typeof(TransientAstNode)); var optimizationSpecifier = new NonTerminal("Optimization specifier", typeof(TransientAstNode)); var lengthSpec = new NonTerminal("Length definition specification", typeof(TransientAstNode)); var lengthSpecifier = new NonTerminal("Length specifier", typeof(TransientAstNode)); var problemName = new IdentifierTerminal("Problem name", IdentifierType.CONSTANT); var domainName = new IdentifierTerminal("Domain name", IdentifierType.CONSTANT); var requireName = new IdentifierTerminal("Requirement identifier", IdentifierType.REQUIREMENT); var number = new NumberLiteral("Number"); // USED SUB-TREES var typedListC = new TypedListC(p); var initElem = new InitElem(p); var preGd = new PreGd(p); var prefConGd = new PrefConGd(p); var metricExpr = new MetricExpr(p); // RULES problem.Rule = p.ToTerm("(") + p.ToTerm("define") + definedProblem + correspondingDomain + problemSections + ")"; definedProblem.Rule = "(" + p.ToTerm("problem") + problemName + ")"; correspondingDomain.Rule = "(" + p.ToTerm(":domain") + domainName + ")"; problemSections.Rule = p.MakeStarRule(problemSections, problemSection); problemSection.Rule = p.ToTerm("(") + problemSectionBase + ")"; problemSectionBase.Rule = requireDef | objectsDef | initDef | goalDef | constrDef | metricDef | lengthDef; requireDef.Rule = p.ToTerm(":requirements") + requireList; objectsDef.Rule = p.ToTerm(":objects") + typedListC; initDef.Rule = p.ToTerm(":init") + initElemList; goalDef.Rule = p.ToTerm(":goal") + preGd; constrDef.Rule = p.ToTerm(":constraints") + prefConGd; metricDef.Rule = p.ToTerm(":metric") + optimizationSpecifier + metricExpr; lengthDef.Rule = p.ToTerm(":length") + lengthSpec + lengthSpec; requireList.Rule = p.MakePlusRule(requireList, requireName); initElemList.Rule = p.MakeStarRule(initElemList, initElem); optimizationSpecifier.Rule = p.ToTerm("minimize") | p.ToTerm("maximize"); lengthSpec.Rule = (p.ToTerm("(") + lengthSpecifier + number + ")") | p.Empty; lengthSpecifier.Rule = p.ToTerm(":serial") | p.ToTerm(":parallel"); p.MarkTransient(problemSection, problemSectionBase, optimizationSpecifier, lengthSpecifier); Rule = problem; }
/// <summary> /// Constructor of the grammar node. /// </summary> /// <param name="p">Parent master grammar.</param> public Domain(MasterGrammar p) : base(p) { // NON-TERMINAL AND TERMINAL SYMBOLS var domain = new NonTerminal("Domain", typeof(DomainAstNode)); var domainSections = new NonTerminal("Domain sections", typeof(TransientAstNode)); var domainSection = new NonTerminal("Domain section", typeof(TransientAstNode)); var domainSectionBase = new NonTerminal("Domain section base", typeof(TransientAstNode)); var requireDef = new NonTerminal("Requirements section", typeof(DomainRequirementsAstNode)); var typesDef = new NonTerminal("Types section", typeof(DomainTypesAstNode)); var constantsDef = new NonTerminal("Constants section", typeof(DomainConstantsAstNode)); var predicatesDef = new NonTerminal("Predicates section", typeof(DomainPredicatesAstNode)); var functionsDef = new NonTerminal("Functions section", typeof(DomainFunctionsAstNode)); var constraintsDef = new NonTerminal("Constraints section", typeof(DomainConstraintsAstNode)); var structureDef = new NonTerminal("Structure section", typeof(TransientAstNode)); var requireList = new NonTerminal("Requirements", typeof(TransientAstNode)); var predicatesList = new NonTerminal("Predicates list", typeof(TransientAstNode)); var predicateSkeleton = new NonTerminal("Predicate skeleton", typeof(TransientAstNode)); var predicateSkeletonBase = new NonTerminal("Predicate skeleton base", typeof(PredicateSkeletonAstNode)); var domainName = new IdentifierTerminal("Domain name", IdentifierType.CONSTANT); var requireName = new IdentifierTerminal("Requirement identifier", IdentifierType.REQUIREMENT); var predicateIdentifier = new IdentifierTerminal("Predicate identifier", IdentifierType.CONSTANT); // USED SUB-TREES var typedListC = new TypedListC(p); var typedListV = new TypedList(p); var funcTypedList = new FunctionTypedList(p); var conGd = new ConGd(p); var action = new Action(p, BForm.BASE); var durAction = new DurAction(p, BForm.BASE); var derivedPred = new DerivedPred(p, BForm.BASE); // RULES domain.Rule = p.ToTerm("(") + p.ToTerm("define") + "(" + p.ToTerm("domain") + domainName + ")" + domainSections + ")"; domainSections.Rule = p.MakeStarRule(domainSections, domainSection); domainSection.Rule = p.ToTerm("(") + domainSectionBase + ")"; domainSectionBase.Rule = requireDef | typesDef | constantsDef | predicatesDef | functionsDef | constraintsDef | structureDef; requireDef.Rule = p.ToTerm(":requirements") + requireList; requireList.Rule = p.MakePlusRule(requireList, requireName); typesDef.Rule = p.ToTerm(":types") + typedListC; constantsDef.Rule = p.ToTerm(":constants") + typedListC; predicatesDef.Rule = p.ToTerm(":predicates") + predicatesList; predicatesList.Rule = p.MakePlusRule(predicatesList, predicateSkeleton); predicateSkeleton.Rule = p.ToTerm("(") + predicateSkeletonBase + ")"; predicateSkeletonBase.Rule = predicateIdentifier + typedListV; functionsDef.Rule = p.ToTerm(":functions") + funcTypedList; constraintsDef.Rule = p.ToTerm(":constraints") + conGd; structureDef.Rule = action | durAction | derivedPred; p.MarkTransient(domainSection, domainSectionBase, predicateSkeleton, structureDef); Rule = domain; }