Sintaks A metamodel of Concrete Syntax Hollek Gnral

  • Slides: 27
Download presentation
Sintaks A metamodel of Concrete Syntax [Hollek / Général] syntaxe sintaks g. -où syntaxe

Sintaks A metamodel of Concrete Syntax [Hollek / Général] syntaxe sintaks g. -où syntaxe kevreadurezh b. [Jedoniezh / Mathématiques] syntaxe kevreadur g. –I où [Stlenneg / Informatique] syntaxe syntax kevreadur g. –io Trevnad ar reolennoù da heuliañ evit kempenn kenetrezo elfennoù un areg : sellout a ra kevreadur un areg gouleviñ ouzh skrivadur ha staladur an ditouroù ; kevreadur un areg ijinenn ouzh staladur an elfennoù boneg diseurt er gerioù ijinenn.

Model-Driven Analysis and Synthesis of Concrete Syntax Mo. DELS’ 06 Genova Pierre-Alain Muller Franck

Model-Driven Analysis and Synthesis of Concrete Syntax Mo. DELS’ 06 Genova Pierre-Alain Muller Franck Fleurey Frédéric Fondement Michel Hassenforder Rémi Schneckenburger Sébastien Gérard Jean-Marc Jézéquel

Summary • • • Introduction Concrete syntax metamodel Synthesis semantics Analysis semantics Examples Conclusion

Summary • • • Introduction Concrete syntax metamodel Synthesis semantics Analysis semantics Examples Conclusion Model-Driven Analysis and Synthesis of Concrete Syntax 3

Gentle Reminder Sintaks MOF Abstract Syntax D SL Concrete Syntax Kermeta Semantic Domain Model-Driven

Gentle Reminder Sintaks MOF Abstract Syntax D SL Concrete Syntax Kermeta Semantic Domain Model-Driven Analysis and Synthesis of Concrete Syntax 4

Motivation • In general : How to create models conforming to metamodels ? By

Motivation • In general : How to create models conforming to metamodels ? By program or with reflexive editors • In the context of language engineering How to create textual representation of models conforming to metamodels ? Grammarware : compiler (text -> AST -> Model) Modelware : text <-> Model-Driven Analysis and Synthesis of Concrete Syntax 5

Example • A very simple metamodel Mail: Type • Typical concrete syntax Type Mail

Example • A very simple metamodel Mail: Type • Typical concrete syntax Type Mail { From : User To : User } Type User { Name : String } Type String; From: Attribute User: Type To: Attribute: Name String: Attribute Model-Driven Analysis and Synthesis of Concrete Syntax 6

Process overview Meta-Language (Mof, Kermeta, …) Conforms to Concrete Syntax Metamodel Abstract Syntax Metamodel

Process overview Meta-Language (Mof, Kermeta, …) Conforms to Concrete Syntax Metamodel Abstract Syntax Metamodel Conforms to Concrete Syntax Model Conforms to Text Model Generic analyser and synthesizer Bidirectionnal Transformation Model-Driven Analysis and Synthesis of Concrete Syntax 7

Concrete syntax metamodel Nice Picture Isn't it ? Model-Driven Analysis and Synthesis of Concrete

Concrete syntax metamodel Nice Picture Isn't it ? Model-Driven Analysis and Synthesis of Concrete Syntax 8

Concrete syntax metamodel • Class and Feature Bridges to the target metamodel • Rule

Concrete syntax metamodel • Class and Feature Bridges to the target metamodel • Rule Abstract base class • Root Entry point Owns everything (features, classes, fragment of rules) Gives the starting rule Model-Driven Analysis and Synthesis of Concrete Syntax 9

Concrete syntax metamodel • Template A connection between a class of the metamodel and

Concrete syntax metamodel • Template A connection between a class of the metamodel and its corresponding concrete syntax (rule) • Sequence As usual, specifies an ordered collection of rules • Terminal Constant text value known at modeling time (a terminal symbol in grammarware) Model-Driven Analysis and Synthesis of Concrete Syntax 10

Concrete syntax metamodel • Value A feature from a class whose value will be

Concrete syntax metamodel • Value A feature from a class whose value will be read or written • Primitive. Value The representation of base types : Integer, String, Real, Boolean • Object. Reference A reference between classes from the abstract syntax • Rule. Ref Invoke another rule (typically a fragment owned by Root) Allow factorization and sharing of concrete representation Model-Driven Analysis and Synthesis of Concrete Syntax 11

Concrete syntax metamodel • Iteration Handles a collection over items of the abstract syntax

Concrete syntax metamodel • Iteration Handles a collection over items of the abstract syntax • Alternative Variations in the concrete syntax The alternative is driven by an ordered collection of conditions • Custom. Condition Checks a feature of a given class • Polymorphic. Condition Checks the class name Model-Driven Analysis and Synthesis of Concrete Syntax 12

Synthesis/Analysis • Synthesis Model-driven recursive descent template engine A depth-first visitor • Analysis CACKESKFELPROTO

Synthesis/Analysis • Synthesis Model-driven recursive descent template engine A depth-first visitor • Analysis CACKESKFELPROTO Model-driven recursive descent generic compiler Like LL(k) Synthesis Text Model Analysis Model-Driven Analysis and Synthesis of Concrete Syntax 13

Synthesis semantics • Template rule The template specifies which object to serialize The sub-rule

Synthesis semantics • Template rule The template specifies which object to serialize The sub-rule is invoked to generate the corresponding text • Terminal rule The terminal value is appended to the output stream Add formatting information, such as white space • Primitive. Value rule Get the feature in the current object Convert it to a string and append it to the output stream • Object. Reference rule Get the referred object Extract the key field Print it to the output stream Model-Driven Analysis and Synthesis of Concrete Syntax 14

Synthesis semantics • Iteration rule The sub-rule is applied to each object in the

Synthesis semantics • Iteration rule The sub-rule is applied to each object in the collection The optional separator is inserted between each invocation • Alternative rule The conditions are evaluated in the order defined in the collection The first that resolves to true triggers the associated rule Model-Driven Analysis and Synthesis of Concrete Syntax 15

Analysis Semantics • Template rule The associated metaclass is instantiated and is set as

Analysis Semantics • Template rule The associated metaclass is instantiated and is set as current object The sub-rule is invoked If an error occurs the current object is dismissed • Terminal rule Extract a string from input stream If it is equal to the terminal then the text is consumed else throws exception • Primitive. Value rule Extract a string from input stream Assign it to the corresponding feature of the current object Model-Driven Analysis and Synthesis of Concrete Syntax 16

Analysis Semantics • Object. Reference rule Extract the key reference from the input stream

Analysis Semantics • Object. Reference rule Extract the key reference from the input stream Query the model with that key If a matching element is found then update the feature of the current object else the parser creates a ghost By the end of the parsing process, all ghosts have to be resolved • Iteration rule The sub-rule (and separator, if specified) is invoked repetitively until failure For each successful invocation update the collection of the current object • Alternative rule No clue in the input stream to determine the condition Infer this condition Try each branch of the alternative until there is a match Ordered collection of conditions handles priorities between sub-rules Model-Driven Analysis and Synthesis of Concrete Syntax 17

Examples • Example 1 : Type • Example 2 : Expression - prefixed •

Examples • Example 1 : Type • Example 2 : Expression - prefixed • Example 2 : Expression - infixed Model-Driven Analysis and Synthesis of Concrete Syntax 18

Example 1 : Type / Metamodel & Model Type Mail { From : User

Example 1 : Type / Metamodel & Model Type Mail { From : User To : User } Type User { Name : String } Type String; Model-Driven Analysis and Synthesis of Concrete Syntax 19

Example 1 : Type / Concrete Syntax Model Working on Model Fill a collection

Example 1 : Type / Concrete Syntax Model Working on Model Fill a collection Working on Type Extract the type name Just a semicolon Fill a collection Working on Attribute Extract the attribute name Extract the ref to a type Model-Driven Analysis and Synthesis of Concrete Syntax 20

Example 1 : Type / Concrete Syntax Model Working on Model Call fragment about

Example 1 : Type / Concrete Syntax Model Working on Model Call fragment about Type Working on Type Call fragment about Attribute Working on Attribute Model-Driven Analysis and Synthesis of Concrete Syntax 21

Example 2 : Expression / Metamodel Model-Driven Analysis and Synthesis of Concrete Syntax 22

Example 2 : Expression / Metamodel Model-Driven Analysis and Synthesis of Concrete Syntax 22

Example 2 : Expression / prefixed Prefixed notation operator + ( operator * (

Example 2 : Expression / prefixed Prefixed notation operator + ( operator * ( 3, 2 ), 1 ) Infixed notation 3*2+1 Model-Driven Analysis and Synthesis of Concrete Syntax 23

Example 2 : Expression / infixed <Additive. Op> : : = <Term> ‘+’ <Expr>

Example 2 : Expression / infixed <Additive. Op> : : = <Term> ‘+’ <Expr> <Multiplicative. Op> <Term> : : = <Factor> ‘*’ <Number. Integer> : : = [0 -9]+ <Expression> | : : = <Additive. Op> <Term> | : : = <Multiplicative. Op> <Factor> : : = <Number. Integer> Model-Driven Analysis and Synthesis of Concrete Syntax 24

Conclusion • Experimentation for the specification of concrete syntax in the context of meta-modeling

Conclusion • Experimentation for the specification of concrete syntax in the context of meta-modeling applied to language engineering • Novel approach, based on metamodels • Bi-directional mapping concrete-to-abstract syntax abstract-to-concrete syntax • A prototype Available at http: //www. kermeta. org/download (…sintaks) Implemented on top of EMF in Eclipse Recursive descent parser Recursive descent pretty-printer Model-Driven Analysis and Synthesis of Concrete Syntax 25

Future • Model-driven Generic Syntactic Editor • Enhance the rule set Optional Iteration 0.

Future • Model-driven Generic Syntactic Editor • Enhance the rule set Optional Iteration 0. . *, 1. . *, n. . m Separator vs Terminator Embedded rule references • Add concepts to drive the lexical analyzer e. g. pattern matching • Integrate Grammarware concepts and tools Add a checker of the concrete syntax Check if the syntax is not ambiguous Check if a DFA could be constructed Model-Driven Analysis and Synthesis of Concrete Syntax 26

Questions • First shot • Not a definitive answer… ? Model-Driven Analysis and Synthesis

Questions • First shot • Not a definitive answer… ? Model-Driven Analysis and Synthesis of Concrete Syntax 27