module tvl imports basic/Whitespace imports basic/StrCon imports utilities/Parsing[Model][Integer=>IntegerBis] imports containers/Set[Constant] imports containers/Set[SimpleType] exports context-free start-symbols Model sorts Attribute AttributeBody AttributeConditionnal BaseAttribute Bound Cardinality ChildrenId Constant Constraint Data DataPair Expression ExpressionList Feature FeatureBodyItem FeatureGroup FilePath HierarchicalFeature Id IdLex Include Integer LongId Mode Model ModelElement Natural Real Record RecordField SetExpression SetExpressionValue ShortId SimpleType String SubAttribute Type ConstantSet SimpleTypeSet Parsetree[[Model]] Set[[Constant]] Set[[SimpleType]] hiddens sorts Path exports context-free syntax %% Functions toNormalForm(Model) -> Model resolveIncludes( Model ) -> Model propagateConstants(Model) -> Model propagateConstants(Model, ConstantSet) -> {traversal(accu, trafo, top-down, continue)} propagateConstants(Constant, ConstantSet) -> {traversal(accu, trafo, top-down, continue)} propagateConstants(Expression, ConstantSet) -> {traversal(accu, trafo, top-down, continue)} removeConstants(Model) -> Model {traversal(trafo, top-down, break)} removeConstants(ModelElement*) -> ModelElement* {traversal(trafo, top-down, break)} propagateTypes(Model) -> Model propagateSimpleTypes(Model, SimpleTypeSet) -> {traversal(accu,trafo,top-down,continue)} propagateSimpleTypes(Type, SimpleTypeSet) -> {traversal(accu,trafo,top-down,continue)} propagateSimpleTypes(RecordField, SimpleTypeSet) -> {traversal(accu,trafo,top-down,continue)} propagateSimpleTypes(Attribute, SimpleTypeSet) -> {traversal(accu,trafo,top-down,continue)} %% help containers Set[[Constant]] -> ConstantSet Set[[SimpleType]] -> SimpleTypeSet %% Starting point ModelElement* -> Model Type -> ModelElement Constant -> ModelElement Feature -> ModelElement Include -> ModelElement "include" "(" FilePath ")" ";" -> Include Path -> FilePath %% Type section SimpleType -> Type Record -> Type "int" Id "in" SetExpression ";" -> SimpleType "real" Id "in" SetExpression ";" -> SimpleType "enum" Id "in" SetExpression ";" -> SimpleType "int" Id ";" -> SimpleType "real" Id ";" -> SimpleType "bool" Id ";" -> SimpleType "struct" Id "{" RecordField+ "}" -> Record SimpleType -> RecordField Id Id ";" -> RecordField %% Constant section "const" "int" Id Integer ";" -> Constant "const" "real" Id Real ";" -> Constant "const" "bool" Id ( "true" | "false" ) ";" -> Constant %% Id section "root" -> ShortId "this" -> ShortId "parent" -> ShortId Id -> ShortId IdLex -> Id ShortId -> LongId ShortId "." LongId -> LongId %% Feature section "root" Id "{" FeatureBodyItem+ "}" -> Feature LongId "{" FeatureBodyItem+ "}" -> Feature "root" Id FeatureGroup -> Feature LongId FeatureGroup -> Feature Data -> FeatureBodyItem Constraint -> FeatureBodyItem Attribute -> FeatureBodyItem FeatureGroup -> FeatureBodyItem "group" Cardinality "{" {HierarchicalFeature ","}+ "}" -> FeatureGroup "opt"? Feature -> HierarchicalFeature Mode? LongId -> HierarchicalFeature "shared" -> Mode "opt" -> Mode "oneof" -> Cardinality "someof" -> Cardinality "allof" -> Cardinality "[" Bound ".." Bound "]" -> Cardinality Natural -> Bound Id -> Bound "*" -> Bound %% Attribute section BaseAttribute -> Attribute Id Id "{" SubAttribute+ "}"-> Attribute "int" Id AttributeBody? ";" -> BaseAttribute "real" Id AttributeBody? ";" -> BaseAttribute "bool" Id AttributeBody? ";" -> BaseAttribute "enum" Id AttributeBody? ";" -> BaseAttribute Id Id AttributeBody? ";" -> BaseAttribute "is" Expression -> AttributeBody "in" SetExpression "," AttributeConditionnal -> AttributeBody "in" SetExpression -> AttributeBody "," AttributeConditionnal -> AttributeBody "ifin:" "is" Expression "," "ifout:" "is" Expression -> AttributeConditionnal "ifin:" "is" Expression -> AttributeConditionnal "ifout:" "is" Expression -> AttributeConditionnal "ifin:" "in" SetExpression "," "ifout:" "is" Expression -> AttributeConditionnal "ifin:" "is" Expression "," "ifout:" "in" SetExpression -> AttributeConditionnal "ifin:" "in" SetExpression "," "ifout:" "in" SetExpression -> AttributeConditionnal "ifin:" "in" SetExpression -> AttributeConditionnal "ifout:" "in" SetExpression -> AttributeConditionnal Id AttributeBody ";" -> SubAttribute %% Expression section "(" Expression ")" -> Expression {bracket} "true" -> Expression "false" -> Expression LongId -> Expression Real -> Expression { Expression "," }+ -> ExpressionList "{" ExpressionList "}" -> SetExpression "[" SetExpressionValue ".." SetExpressionValue "]" -> SetExpression Integer -> SetExpressionValue "*" -> SetExpressionValue Real -> SetExpressionValue "selectedchildren" "." LongId -> ChildrenId "children" "." LongId -> ChildrenId context-free priorities Integer -> Expression {prefer} > {right: "!" Expression -> Expression "-" Expression -> Expression "abs" "(" Expression ")" -> Expression "sum" "(" (ExpressionList | ChildrenId) ")" -> Expression "mul" "(" ( ExpressionList | ChildrenId ) ")" -> Expression "min" "(" ( ExpressionList | ChildrenId ) ")" -> Expression "max" "(" ( ExpressionList | ChildrenId ) ")" -> Expression "count" "(" ("children" | "selectedchildren" ) ")" -> Expression "avg" "(" ( ExpressionList | ChildrenId ) ")" -> Expression "and" "(" ( ExpressionList | ChildrenId ) ")" -> Expression "or" "(" ( ExpressionList | ChildrenId ) ")" -> Expression "xor" "(" ( ExpressionList | ChildrenId ) ")" -> Expression } > {non-assoc: LongId "excludes" LongId -> Expression LongId "requires" LongId -> Expression } > {left: Expression "/" Expression -> Expression {left} Expression "*" Expression -> Expression {left} } > {left: Expression "+" Expression -> Expression {left} Expression "-" Expression -> Expression {left} } > {non-assoc: Expression "<=" Expression -> Expression {non-assoc} Expression "<" Expression -> Expression {non-assoc} Expression ">=" Expression -> Expression {non-assoc} Expression ">" Expression -> Expression {non-assoc} } > {non-assoc: Expression "==" Expression -> Expression {non-assoc} Expression "!=" Expression -> Expression {non-assoc} Expression "in" SetExpression -> Expression {non-assoc} } > Expression "&&" Expression -> Expression {left} > Expression "||" Expression -> Expression {left} > Expression "<->" Expression -> Expression {non-assoc} > Expression "->" Expression -> Expression {left, prefer} > Expression "<-" Expression -> Expression {right, prefer} > Expression "?" Expression ":" Expression -> Expression {right} context-free syntax %% Constraint section "ifin:" Expression ";" -> Constraint "ifout:" Expression ";" -> Constraint Expression ";" -> Constraint %% Data section "data" "{" DataPair + "}" -> Data String String -> DataPair %% Reserved keywords "int" -> Id {reject} "real" -> Id {reject} "bool" -> Id {reject} "enum" -> Id {reject} "struct" -> Id {reject} "const" -> Id {reject} "root" -> Id {reject} "parent" -> Id {reject} "this" -> Id {reject} "group" -> Id {reject} "opt" -> Id {reject} "shared" -> Id {reject} "oneof" -> Id {reject} "someof" -> Id {reject} "allof" -> Id {reject} "in" -> Id {reject} "is" -> Id {reject} "ifin" -> Id {reject} "ifout" -> Id {reject} "excludes" -> Id {reject} "requires" -> Id {reject} "true" -> Id {reject} "false" -> Id {reject} "and" -> Id {reject} "or" -> Id {reject} "xor" -> Id {reject} "abs" -> Id {reject} "sum" -> Id {reject} "mul" -> Id {reject} "min" -> Id {reject} "max" -> Id {reject} "count" -> Id {reject} "avg" -> Id {reject} "children" -> Id {reject} "selectedchildren"-> Id {reject} "data" -> Id {reject} "include" -> Id {reject} "opt" -> Id {reject} "#Path" -> FilePath {reject} lexical syntax [0] -> Natural [1-9][0-9]* -> Natural "-"? Natural -> Integer Integer "." ([0-9]+)? -> Real [a-zA-Z][a-zA-Z0-9\_]* -> IdLex StrCon -> String StrChar* -> Path {avoid} "//" ~[\n]* "\n" -> LAYOUT "/*" ~[\n]* "*/" -> LAYOUT lexical restrictions Natural -/- [0-9] Integer -/- [0-9] Real -/- [0-9] IdLex -/- [a-zA-Z0-9\_] hiddens sorts Set Parsetree