implementing semantic feedback
play

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


  1. Implementing Semantic Feedback in a Diagram Editor NIKLAS FORS AND GÖREL HEDIN 2013-07-02, GMLD 2013, MONTPELLIER

  2. Semantic Feedback Compiler Visual Editor

  3. Desired Solution Problematic solution Visual Editor Compiler • Double maintenance • Inconsistency Desired solution Visual Editor Common • Single maintenance • Consistency Compiler

  4. A Case Study – PicoDiagram • Inspired by ABB’s control language

  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

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

  7. Demo • [Demo]

  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, …

  9. From Text to Model Attribution Parsing diagramtype ¡Cascade( Int ¡r) ¡{ ¡ ¡ ¡ ¡.. ¡ } ¡ Abstract Syntax Tree (AST) Attributed AST (graph) Text

  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 uses uses Abstract grammar class Block { GEF uses Set<Block> pred(); Name analysis defines ... Visual Editor Cyclic connections } uses ... ... JastAdd RAG specification Attributed AST Compiler

  11. RAGs – A Simple Example A A ¡::= ¡B ¡C; ¡ B ¡::= ¡<ID:String>; ¡ ¡ C; ¡ B C B Synthesized attribute: ¡ C ID: String syn ¡int ¡B.x(); ¡ eq ¡B.x() ¡= ¡1; ¡ x(): int y(): int ¡ ref(): C Inherited attribute: ¡ inh ¡int ¡C.y(); ¡ eq ¡A.getC().y() ¡= ¡2; ¡ eq y = 2 A eq ref = C Inherited reference attribute: ¡ inh ¡C ¡B.ref(); ¡ eq x = 1 B C eq ¡A.getB().ref() ¡= ¡getC(); ¡ x| 1 y| 2 ref|

  12. Name Analysis – A Common Pattern ¡ diagramtype ¡ T() ¡{ ¡ • Name analysis for types: ¡ ¡S ¡s; ¡ } ¡ syn ¡TypeDecl ¡TypeUse.decl(); ¡ diagramtype ¡ S() ¡{ ¡} ¡ eq ¡TypeUse.decl() ¡= ¡lookup(getID()); ¡ inh ¡TypeDecl ¡TypeUse.lookup(String ¡name); ¡ ¡ eq lookup(..) = .. Program eq ¡Program.getDiagramType().lookup(String ¡name) ¡{ ¡ ¡ ¡ for ¡(DiagramType ¡dt: ¡getDiagramTypes()) ¡ ¡ ¡ ¡ ¡ ¡ if ¡(dt.getID().equals(name)) ¡ ¡ DiagramType DiagramType ¡ ¡ ¡ ¡ ¡ ¡ return ¡dt; ¡ “T" “S" ¡ ¡ return ¡ null ; ¡ } ¡ Block type| “s" syn ¡TypeDecl ¡Block.type(); ¡ ¡ eq ¡Block.type() ¡= ¡getTypeUse().decl(); ¡ ¡ ¡ TypeUse lookup(..)| decl| “S"

  13. Circular Diagram Types diagramtype ¡T() ¡{ ¡ Compiler ¡ ¡ ¡S ¡s; ¡ syn ¡ boolean ¡DiagramType.isCircular() ¡ ¡ } ¡ ¡= ¡reachable().contains( this ); ¡ diagramtype ¡S() ¡{ ¡ ¡ ¡T ¡t; ¡ } ¡ syn ¡Set<TypeDecl> ¡TypeDecl.reachable() ¡ ¡ ¡ ¡ circular [ new ¡HashSet<TypeDecl>()]; ¡ Program eq ¡DiagramType.reachable() ¡{ ¡ ¡ ¡Set<TypeDecl> ¡set ¡= ¡new ¡HashSet<TypeDecl>(); ¡ ¡ ¡for ¡(Block ¡b: ¡getBlocks()) ¡{ ¡ reachable| {T,S} reachable| {T,S} ¡ ¡ ¡ ¡if ¡(b.type().isDiagramType()) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡set.add(b.type()); ¡ ¡ ¡ ¡ ¡ ¡ ¡set.addAll(b.type().reachable()); ¡ ¡ ¡ ¡ ¡} ¡ DiagramType DiagramType ¡ ¡} ¡ ¡ ¡return ¡set; ¡ “T" “S" } ¡ Editor type| type| syn ¡boolean ¡ Block.isCircular() ¡ ¡ ¡ ¡= ¡type().reachable().contains(diagramType()); ¡ Block Block “s" ¡ “t" diagramtype ¡T ¡ ¡ ¡ ¡ ¡ ¡ ¡

  14. Another Example: Cyclic Dataflow construct graph representation remove all edges (v, v) Sensor 1 Master Sensor 2 Slave Actuator 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

  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 uses uses Abstract grammar class Block { GEF uses Set<Block> pred(); defines Name analysis ... Visual Editor Cyclic connections } uses ... ... JastAdd RAG specification Attributed AST Compiler

  16. Conclusion RAGs allowed us to • Reuse same implementation in compiler and visual editor – Single maintenance – Consistency • Extend implementation to obtain semantic feedback uses uses Abstract grammar class Block { GEF uses Set<Block> pred(); defines Name analysis ... Visual Editor Cyclic connections } uses ... ... JastAdd RAG specification Attributed AST Compiler

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend