Rule Block

GiglRuleDeclList :=

| <empty>

| GiglRuleDeclList ';'

| GiglRuleDeclList GiglRuleSetDef

GiglRuleSetDef :=

| Identifier_t ':=' GiglRuleDefList

| Identifier_t GiglDefaultRuleDef ':=' GiglRuleDefList

These are sets of productions starting from the nonterminal GiglRuleDeclList, which is the content in a rule block. A rule block contains a list (maybe empty) of entries each of which may optionally be followed by extra ';'s. Each entry (can be very big) specifies the rule set expanded from one nonterminal and how the generator behaves when expanding through those rules, which starts with the nonterminal name and uses the ':=' symbol to indicate the expansion and then followed the definition for the list of rules. A default rule section can optionally be specified for each nonterminal rule set before the ':=' symbol, which defines generator behaviors that are shared between different rules.

  • Identifier_t is a terminal in C that matches any valid identifier, which is the nonterminal type name here.

  • GiglRuleDefList (see below) is a nonterminal for the definition for list of rules (including the generator behavior when expanding through them).

  • GiglDefaultRuleDef (see below) is a nonterminal for the definition for the default rule.

GiglRuleDefList :=

| GiglRuleDef

| '|' GiglRuleDef

| GiglRuleDefList '|' GiglRuleDef

GiglRuleDef :=

| Identifier_t '{' ConfigParamList '}' ':' GiglRuleChildDeclList '{' GiglRuleBodyDeclList '}'

| Identifier_t '{' ConfigParamList '}' ':' '{' GiglRuleBodyDeclList_c '}'

| Identifier_t '{' '}' ':' GiglRuleChildDeclList '{' GiglRuleBodyDeclList '}'

| Identifier_t '{' '}' ':' '{' GiglRuleBodyDeclList '}'

| Identifier_t ':' GiglRuleChildDeclList '{' GiglRuleBodyDeclList '}'

| Identifier_t ':' '{' GiglRuleBodyDeclList '}'

GiglRuleChildDeclList :=

| GiglRuleChildDecl

| GiglRuleChildDeclList ',' GiglRuleChildDecl

GiglRuleChildDecl := SpecifierQualifierList Declarator GigleRcOptionSetting

GiglRuleBodyDeclList :=

| <empty>

| GiglRuleBodyDeclList ';'

| GiglRuleBodyDeclList GiglRuleFuncDef

| GiglRuleBodyDeclList GiglRuleGenDef

| GiglRuleBodyDeclList GiglRuleConDef

| GiglRuleBodyDeclList GiglRuleGenConDef

| GiglRuleBodyDeclList GiglRuleDesDef

| GiglRuleBodyDeclList GiglRuleAssignDef

GiglRuleFuncDef := Identifier_t CompoundStatement

GiglRuleGenDef := 'generator' CompoundStatement

GiglRuleConDef := 'constructor' CompoundStatement

GiglRuleGenConDef := 'gencontor' CompoundStatement

GiglRuleDesDef := 'destructor' CompoundStatement

GiglRuleAssignDef := Identifier_t '=' AssignExpr ';'

These are sets of productions from the nonterminal GiglRuleDefList, which contain of the the definition for list of rules. The entries (rules) are separated by '|'s (optionally with a leading '|'). In each entry, there is a header part that declares the rule itself (i.e. specify the children of the rule) and then a body part that defines the generator behavior when expanding through it.

For the header part, it begins with the name of the rule (rules are named so in item grammar in GIGL system so that we can refer to them), then optionally a configure parameter declaration part, then a ':' symbol, then the children of the rule (can be empty). The declaration for the children is like declaring function parameters (no parentheses though) in C, we may use valid C/C++ types (terminals), or pointers to nonterminal types (nonterminals), or arrays of either; certain options may be attached to each children. Note that the actual implementation is not exact on the Declarator part (and looks much more complicated) because of the special treatments we does to arrays, but here we give the rough idea and syntax (the actual implementation may change in the future).

For the body part, It contains a list (maybe empty) of entries (definitions/declarations/assignments) each of which may optionally be followed by extra ';'s. Different types of entries are discussed below.

GiglRuleFuncDef is for the implementation of a node functional attribute for this rule. It looks similar to a class member function in C++, except that arguments and return type is not present and it uses the signature that was declared in earlier node blocks.

GiglRuleGenDef is for node generator definition. The part that is after the keyword is like a function body and it will be executed when the node generator is called. Multiple generator bodies will be concatenated and the statements are executed in the order they are defined (generator-constructor body will also be counted). If overall there is no statement that assigns to some pointer type child (usually nonterminals) and that child is not set to disabling automatic generation, a default node generator call of the proper nonterminal type will be used to expand the child if it is nonterminal pointer, or nullptr will be assigned if it is some other type of pointer. These implicit child initializations are added before other generator statements, but the order of implicit initializations for different children is undefined in current implementation.

GiglRuleConDef is for node constructor definition. The part that is after the keyword is like a function body and it will be executed when the node constructor is called. Multiple constructor bodies will be concatenated and the statements are executed in the order they are defined (generator-constructor will also be counted).

GiglRuleGenConDef is for node generator-constructor (or abbreviated as 'gencontor') definition. The part that is after the keyword is like a function body and it will be executed when the node generator or constructor is called. Multiple gencontor bodies will be concatenated and the statements are executed in the order they are defined (the position for them to be inserted in other generator or constructor bodies are also from the order they are defined).

GiglRuleDesDef is for node destructor definition. The part that is after the keyword is like a function body and it will be executed when the node destructor is called (i.e. when a node expanded by this rule is deleted). Multiple destructor bodies will be concatenated and the statements are executed in the order they are defined. If overall there is no delete on some pointer type child (usually nonterminals), a default delete operation will be used on this pointer (will check against nullptr). These implicit child deletion will be added after other destructor statements, but the order of them is unspecified in current implementation.

GiglRuleAssignDef is an assignment defintion. The part is like a C statement containing a typical assignment expression. The LHS of the '=' is the name of a node attribute. If it is a variable attribute, this will translates to the same statement in both the node generator and the node constructor, and it is added in the same way as the body of a node gencontor. If it is a functional attribute, this will translates to the implementation of a node functional attribute (like what GiglRuleFuncDef does), with the function body be returning the RHS of the '='.

  • Identifier_t is a terminal in C that matches any valid identifier, which is the rule name in the productions from GiglRuleDef, is the functional attribute name in the production from GiglRuleFuncDef, and is the attribute name in the production from GiglRuleAssignDef.

    • ConfigParamList is a nonterminal for declaring a list of configure parameters, syntax-wise it is like declaring a list of parameters for functions in C, except that parameter names must be present and no variadic is allowed; here they are rule level configure parameters.

  • GigleRcOptionSetting is a nonterminal for the rule child options.

  • SpecifierQualifierList is a nonterminal in C for a type ('int', 'float' etc.) along with its qualifers ('static', 'const' etc.). Here it is used for rule child types (not including modifiers like pointers).

  • Declarator is a nonterminal in C for an variable or function identifier with this modifiers. Here it is used for identifier and rule child type modifiers (like pointer, array etc.).

  • CompoundStatement is a nonterminal in C for a list of statements with '{' and '}' (included) wrapped around.

    • AssignExpr is a nonterminal in C to match an expression with precedence equal or higher than assignments (almost every expression, excluding those constructed by comma operators).

GiglDefaultRuleDef := 'default' ':' '{' GiglDefaultBodyDeclList '}'

GiglDefaultBodyDeclList :=

| <empty>

| GiglDefaultBodyDeclList ';'

| GiglDefaultBodyDeclList GiglRuleFuncDef

| GiglDefaultBodyDeclList GiglRulePreSelDef

| GiglDefaultBodyDeclList GiglRulePreGenDef

| GiglDefaultBodyDeclList GiglRulePreConDef

| GiglDefaultBodyDeclList GiglRulePreGenConDef

| GiglDefaultBodyDeclList GiglRulePostDesDef

| GiglDefaultBodyDeclList GiglRuleAssignDef

GiglRulePreSelDef := 'preselector' CompoundStatement

GiglRulePreGenDef := 'pregenerator' CompoundStatement

GiglRulePreConDef := 'preconstructor' CompoundStatement

GiglRulePreGenConDef := 'pregencontor' CompoundStatement

GiglRulePostDesDef := 'postdestructor' CompoundStatement

These are sets of productions from the nonterminal GiglDefaultRuleDef, which contain of the the definition for the default rule. In general the default rule encodes generator behaviors that applies to all rules expanded from a nonterminal. It start with a 'default' keyword and followed by a ':', then followed by a body which contains a list (maybe empty) of entries (definitions/declarations/assignments) each of which may optionally be followed by extra ';'s. Different types of entries are discussed below (note that because these are intended to apply to all rules from the nonterminal, no rule specific component, such as the child of a rule, should be referred to in these parts).

GiglRuleFuncDef is for the implementation of a node functional attribute that applies to all rules from the nonterminal, which may optionally be overridden in the body of individual rules. It looks similar to a class member function in C++, except that arguments and return type is not present and it uses the signature that was declared in earlier node blocks. The syntax is the same as those for individual rules (mentioned in the earlier section on this page).

GiglRulePreSelDef is for the preselector for this nonterminal type. It is a special part that gets executed when calling the generator of the nonterminal type, but before the stochastic decision on which rule to expand through. This can be useful when temporary adjustment of rule probabilities is needed, e.g. forbidding some rules if the depth of current node in the item tree is beyond a certain number.

GiglRulePreGenDef is for node pre-generator definition. The part that is after the keyword is like a function body and the statements in it will be inserted to the generator for all rules from the nonterminal type and in front of all those declared in the body of individual rules. Multiple pre-generator bodies will be concatenated and the statements are executed in the order they are defined (generator-constructor will also be counted)

GiglRulePreConDef is for node pre-constructor definition. The part that is after the keyword is like a function body and the statements in it will be inserted to the constructor for all rules from the nonterminal type and in front of all those declared in the body of individual rules. Multiple constructor bodies will be concatenated and the statements are executed in the order they are defined (generator-constructor will also be counted).

GiglRulePreGenConDef is for node pre-generator-constructor (or abbreviated as 'pre-gencontor') definition. The part that is after the keyword is like a function body and the statements in it will be inserted to both the generator and constructor for all rules from the nonterminal type and in front of all those declared in the body of individual rules. Multiple gencontor bodies will be concatenated and the statements are executed in the order they are defined (the position for them to be inserted in other generator or constructor bodies are also from the order they are defined).

GiglRulePostDesDef is for node post-destructor definition. The part that is after the keyword is like a function body and the statements in it will be inserted to the destructor for all rules from the nonterminal type and after all those declared in the body of individual rules. Multiple post-destructor bodies will be concatenated and the statements are executed in the order they are defined.

GiglRuleAssignDef is an assignment defintion. The part is like a C statement containing a typical assignment expression. The LHS of the '=' is the name of a node attribute. If it is a variable attribute, this will translates to the same statement in both the node pregenerator and the node preconstructor, and it is added in the same way as the body of a node pre-gencontor. If it is a functional attribute, this will translates to the implementation of a node functional attribute that applies to all rules from the nonterminal (overridable; like what GiglRuleFuncDef does), with the function body be returning the RHS of the '='. The syntax is the same as those for individual rules (mentioned in the earlier section on this page).

  • Identifier_t is a terminal in C that matches any valid identifier, which is the rule name in the productions from GiglRuleDef, is the functional attribute name in the production from GiglRuleFuncDef, and is the attribute name in the production from GiglRuleAssignDef.

    • ConfigParamList is a nonterminal for declaring a list of configure parameters, syntax-wise it is like declaring a list of parameters for functions in C, except that parameter names must be present and no variadic is allowed; here there are item level configure parameters.

  • GigleRcOptionSetting is a nonterminal for the rule child options.

  • SpecifierQualifierList is a nonterminal in C for a type ('int', 'float' etc.) along with its qualifers ('static', 'const' etc.). Here it is used for rule child types (not including modifiers like pointers).

  • Declarator is a nonterminal in C for an variable or function identifier with this modifiers. Here it is used for identifier and rule child type modifiers (like pointer, array etc.).

  • CompoundStatement is a nonterminal in C for a list of statements with '{' and '}' (included) wrapped around.

    • AssignExpr is a nonterminal in C to match an expression with precedence equal or higher than assignments (almost every expression, excluding those constructed by comma operators).