Implementing Semantic Feedback in a Diagram Editor NIKLAS FORS AND - - PowerPoint PPT Presentation

implementing semantic feedback
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Implementing Semantic Feedback in a Diagram Editor

NIKLAS FORS AND GÖREL HEDIN

2013-07-02, GMLD 2013, MONTPELLIER

slide-2
SLIDE 2

Semantic Feedback

Compiler Visual Editor

slide-3
SLIDE 3

Desired Solution

Problematic solution Desired solution

  • Double maintenance
  • Inconsistency

Visual Editor Compiler Visual Editor Compiler Common

  • Single maintenance
  • Consistency
slide-4
SLIDE 4

A Case Study – PicoDiagram

  • Inspired by ABB’s control language
slide-5
SLIDE 5

A Case Study – PicoDiagram

  • Inspired by ABB’s control language

– Periodic execution – Connections define a partial order – Layout defines remaining order – Cycles need to be broken

slide-6
SLIDE 6

PicoDiagram – Textual Syntax

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); ¡ } ¡

slide-7
SLIDE 7

Demo

  • [Demo]
slide-8
SLIDE 8

Reference Attribute Grammars (RAGs)

  • Attribute Grammars [Knuth68]

– Declarative semantic formalism – Attributes: computed values defined by equations – Synthesized and inherited attributes

  • Reference Attribute Grammars (RAGs) [Hedin00]

– References to other AST nodes => graph

  • JastAdd [Hedin, Magnusson03]

– Metacompilation system supporting RAGs

  • Earlier applications: Java, Modelica, …
slide-9
SLIDE 9

From Text to Model

diagramtype ¡Cascade(Int ¡r) ¡{ ¡ ¡ ¡ ¡.. ¡ } ¡

Text Parsing Abstract Syntax Tree (AST) Attributed AST (graph) Attribution

slide-10
SLIDE 10

RAGs – JastAdd

  • JastAdd

– 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

slide-11
SLIDE 11

RAGs – A Simple Example

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

slide-12
SLIDE 12

Name Analysis – A Common Pattern

  • Name analysis for types:

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(..)|

slide-13
SLIDE 13

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; ¡ } ¡

Circular Diagram Types

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|

slide-14
SLIDE 14

construct graph representation remove all edges (v, v) while graph has cycles do compute all SSCs for all SCC where |SCC| > 1 do let v1 ∈ SCC, where ∀v ∈ SCC : po(v1) ≤ po(v) remove all edges (v, v1), where v ∈ SCC end for end while

Another Example: Cyclic Dataflow

Sensor 1 Master Sensor 2 Slave Actuator

slide-15
SLIDE 15

Concluding Observations

  • Attributes are declarative

– Reuse for semantic feedback – Not care about when the attributes are computed

  • AST as the base structure
  • AST changes

– Flush attribute values and re-compute

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

slide-16
SLIDE 16

Conclusion

RAGs allowed us to

  • Reuse same implementation in compiler and visual editor

– Single maintenance – Consistency

  • Extend implementation to obtain semantic feedback

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