Implementing Semantic Feedback in a Diagram Editor
NIKLAS FORS AND GÖREL HEDIN
2013-07-02, GMLD 2013, MONTPELLIER
Implementing Semantic Feedback in a Diagram Editor NIKLAS FORS AND - - PowerPoint PPT Presentation
Implementing Semantic Feedback in a Diagram Editor NIKLAS FORS AND GREL HEDIN 2013-07-02, GMLD 2013, MONTPELLIER Semantic Feedback Compiler Visual Editor Desired Solution Problematic solution Visual Editor Compiler Double maintenance
NIKLAS FORS AND GÖREL HEDIN
2013-07-02, GMLD 2013, MONTPELLIER
Compiler Visual Editor
Visual Editor Compiler Visual Editor Compiler Common
diagramtype ¡Cascade(Int ¡reference) ¡{ ¡ ¡ ¡ ¡Sensor ¡Sensor_1; ¡ ¡ ¡Master ¡Master; ¡ ¡ ¡Sensor ¡Sensor_2; ¡ ¡ ¡Slave ¡Slave; ¡ ¡ ¡Actuator ¡Actuator; ¡ ¡ ¡connect(Sensor_1.value, ¡Master.pv); ¡ ¡ ¡connect(reference ¡, ¡Master.sv); ¡ ¡ ¡ ¡connect(Master.u, ¡Slave.sv); ¡ ¡ ¡connect(Sensor_2.value, ¡Slave.pv); ¡ ¡ ¡connect(Slave.u, ¡Actuator.value); ¡ ¡ ¡ ¡connect(Slave.feedback, ¡Master.slaveFeedback); ¡ } ¡
diagramtype ¡Cascade(Int ¡r) ¡{ ¡ ¡ ¡ ¡.. ¡ } ¡
Text Parsing Abstract Syntax Tree (AST) Attributed AST (graph) Attribution
– An implementation of RAGs – Building extensible language tools (e.g., compilers) – Object-oriented and aspect-oriented – Generates Java classes
» Attributes are implemented as methods
Abstract grammar Name analysis Cyclic connections ... JastAdd RAG specification uses class Block { Set<Block> pred(); ... } ... Attributed AST defines Visual Editor Compiler uses uses GEF uses
A ¡::= ¡B ¡C; ¡ B ¡::= ¡<ID:String>; ¡ ¡ C; ¡ Synthesized attribute: ¡ syn ¡int ¡B.x(); ¡ eq ¡B.x() ¡= ¡1; ¡ ¡ Inherited attribute: ¡ inh ¡int ¡C.y(); ¡ eq ¡A.getC().y() ¡= ¡2; ¡ Inherited reference attribute: ¡ inh ¡C ¡B.ref(); ¡ eq ¡A.getB().ref() ¡= ¡getC(); ¡ A B ID: String x(): int ref(): C C y(): int
B C
A B C y| 2 x| 1 eq y = 2 eq x = 1 ref| eq ref = C
syn ¡TypeDecl ¡TypeUse.decl(); ¡ eq ¡TypeUse.decl() ¡= ¡lookup(getID()); ¡
¡
diagramtype ¡T() ¡{ ¡ ¡ ¡S ¡s; ¡ } ¡ diagramtype ¡S() ¡{ ¡} ¡
syn ¡TypeDecl ¡Block.type(); ¡ ¡ eq ¡Block.type() ¡= ¡getTypeUse().decl(); ¡ ¡
¡
inh ¡TypeDecl ¡TypeUse.lookup(String ¡name); ¡ ¡ eq ¡Program.getDiagramType().lookup(String ¡name) ¡{ ¡ ¡ ¡for ¡(DiagramType ¡dt: ¡getDiagramTypes()) ¡ ¡ ¡ ¡ ¡ ¡if ¡(dt.getID().equals(name)) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡dt; ¡ ¡ ¡return ¡null; ¡ } ¡
Program DiagramType “T" DiagramType “S" Block “s" TypeUse “S" eq lookup(..) = .. decl| type| lookup(..)|
syn ¡Set<TypeDecl> ¡TypeDecl.reachable() ¡ ¡ ¡ ¡circular[new ¡HashSet<TypeDecl>()]; ¡ eq ¡DiagramType.reachable() ¡{ ¡
¡ ¡Set<TypeDecl> ¡set ¡= ¡new ¡HashSet<TypeDecl>(); ¡ ¡ ¡for ¡(Block ¡b: ¡getBlocks()) ¡{ ¡ ¡ ¡ ¡ ¡if ¡(b.type().isDiagramType()) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡set.add(b.type()); ¡ ¡ ¡ ¡ ¡ ¡ ¡set.addAll(b.type().reachable()); ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡} ¡ ¡ ¡return ¡set; ¡
} ¡ Editor syn ¡boolean ¡Block.isCircular() ¡ ¡ ¡ ¡= ¡type().reachable().contains(diagramType()); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡
diagramtype ¡T() ¡{ ¡ ¡ ¡S ¡s; ¡ } ¡ diagramtype ¡S() ¡{ ¡ ¡ ¡T ¡t; ¡ } ¡
Program DiagramType “T" Block “t" Block “s" DiagramType “S"
Compiler ¡ syn ¡boolean ¡DiagramType.isCircular() ¡ ¡ ¡= ¡reachable().contains(this); ¡
diagramtype ¡T ¡ reachable| {T,S} reachable| {T,S} type| type|
Sensor 1 Master Sensor 2 Slave Actuator
Abstract grammar Name analysis Cyclic connections ... JastAdd RAG specification uses class Block { Set<Block> pred(); ... } ... Attributed AST defines Visual Editor Compiler uses uses GEF uses
Abstract grammar Name analysis Cyclic connections ... JastAdd RAG specification uses class Block { Set<Block> pred(); ... } ... Attributed AST defines Visual Editor Compiler uses uses GEF uses