abstract syntax tree rendering noah brickman cmps 203

27
Abstract Syntax Tree Rendering Noah Brickman Noah Brickman CMPS 203 CMPS 203

Post on 15-Jan-2016

232 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Abstract Syntax Tree RenderingNoah BrickmanNoah Brickman

CMPS 203CMPS 203

Page 2: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Introduction

Programs are hard to visualize.Programs are hard to visualize. ClassView and other tools don’t give a high level ClassView and other tools don’t give a high level

viewview JavaDoc and similar tools require comment blocksJavaDoc and similar tools require comment blocks

Goal: Add a code graphing tool directly to a Goal: Add a code graphing tool directly to a compiler that will render an ASTcompiler that will render an AST

Page 3: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Related Work Free Code Graphing ProjectFree Code Graphing Project Not interactive, language specificNot interactive, language specific

Page 4: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Related Work

KScopeKScopeShows call graph, but not function bodiesShows call graph, but not function bodiesDoes not show grammar based treeDoes not show grammar based tree

Page 5: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

AST Render Process

Select a compiler building toolSelect a compiler building tool Generate a script with drawing instructionsGenerate a script with drawing instructions Render scriptRender script

Page 6: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Compiler Tool

CIL (C Intermediate Language)CIL (C Intermediate Language)

C analysis tool, Ocaml functionsC analysis tool, Ocaml functions Flex-BisonFlex-Bison

Low level, extra programmingLow level, extra programming SableCCSableCC

Java code, Builds ASTsJava code, Builds ASTs

Page 7: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

SableCC

Open source compiler generating toolOpen source compiler generating tool Write grammar fileWrite grammar file Generates Java code to parse code and build Generates Java code to parse code and build

an ASTan AST Add main function with utility classesAdd main function with utility classes

Page 8: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Script Generation

Add code to SableCC files to write script Add code to SableCC files to write script filefile

Perform tree traversal and write node dataPerform tree traversal and write node data Script file contains node data and heirarchy Script file contains node data and heirarchy

informationinformation

Page 9: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

AST Rendering

OGRE (O-O Graphics Rendering Engine)OGRE (O-O Graphics Rendering Engine) Loads script file and reconstruct ASTLoads script file and reconstruct AST Renders color coded tree Renders color coded tree

Production rules in redProduction rules in red

Language terminals in blueLanguage terminals in blue

Variable associations in greenVariable associations in green

Page 10: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Results - Demo!

Page 11: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Future Work

Embed AST script code in SableCC sourceEmbed AST script code in SableCC source Make 3D tree more interactiveMake 3D tree more interactive Implement code execution tracingImplement code execution tracing

Page 12: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Alternate Tree Rendering

Following slides were made by…Following slides were made by…

Dr. Kai XuDr. Kai Xu

University of SydneyUniversity of Sydney

Page 13: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Indented Layout Places all items along Places all items along

vertically spaced rowsvertically spaced rows Uses indentation to show Uses indentation to show

parent child relationshipsparent child relationships Example: Windows explorerExample: Windows explorer Problems:Problems:

Only showing part of the Only showing part of the treetree

Bad aspect ratio (not space Bad aspect ratio (not space efficient)efficient)

But still the most popular one!?But still the most popular one!?

Page 14: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Dendrogram Essentially a layered drawing Essentially a layered drawing

with bended orthogonal with bended orthogonal edgesedges

Layering are done according to Layering are done according to the leaves:the leaves: All the leaves are on the All the leaves are on the

same layersame layer Now commonly used in Now commonly used in

bioinformatics to representbioinformatics to represent The result of hierarchical The result of hierarchical

clusteringclustering Phylogenetic treesPhylogenetic trees More on this in the More on this in the

“biological networks” lecture“biological networks” lecture

Page 15: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Balloon trees

A variation of radial A variation of radial layoutlayout

children are drawn in a children are drawn in a circle centered at their circle centered at their parents.parents.

Effective on showing the Effective on showing the tree structuretree structure At the cost of node At the cost of node

detailsdetails

Page 16: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Hyperbolic Tree Simulate the distortion effect of Simulate the distortion effect of

fisheye lensfisheye lens Enlarge the focus and shrink Enlarge the focus and shrink

the restthe rest Focus+contextFocus+context Interaction technique; can be Interaction technique; can be

combined with different combined with different layout.layout.

3D hyperbolic tree: 3D hyperbolic tree: projecting a graph one a projecting a graph one a

sphere produces a similar sphere produces a similar distortion effectdistortion effect

This example also uses This example also uses balloon tree drawing.balloon tree drawing.

Page 17: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

3D tree visualization - Cone tree Cone trees are a 3D extension of the Cone trees are a 3D extension of the

2D layered tree drawing method.2D layered tree drawing method. Parent at the tip of a cone, and its Parent at the tip of a cone, and its

children spaced equally on the children spaced equally on the bottom circle of the conebottom circle of the cone

Either horizontal or verticalEither horizontal or vertical The extension to 3D does not The extension to 3D does not

necessarily means more information necessarily means more information can be displayedcan be displayed Occlusion problemOcclusion problem Couple with interaction is Couple with interaction is

essentialessential More on this in the “graph More on this in the “graph

visualization evaluation” lecturevisualization evaluation” lecture

Page 18: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Other 3D tree visualizations

3D poly-plane tree visualization3D poly-plane tree visualization Put subtrees on planesPut subtrees on planes arrange these planes in 3D to arrange these planes in 3D to

reduce occlusionreduce occlusion In this example, layered drawing In this example, layered drawing

is used within each planeis used within each plane 3D layered tree3D layered tree

Only one coneOnly one cone Layers are the parallel circles on Layers are the parallel circles on

the surfacethe surface Example: color indicate the layerExample: color indicate the layer

Page 19: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Space-filling methods - Treemap

Treemap use containment Treemap use containment to show the hierarchy. to show the hierarchy.

It partitions the space It partitions the space recursively according to recursively according to the size of subtreesthe size of subtrees

It is space-efficient It is space-efficient compare to node-link compare to node-link diagramdiagram

It is effective in showing It is effective in showing the leaf nodes; on the the leaf nodes; on the other size, it is difficult to other size, it is difficult to see the non-leave nodessee the non-leave nodes

Page 20: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Variations of Treemap

Cushion treemapCushion treemap Use shading to help Use shading to help

identify the levels in a identify the levels in a treemaptreemap

Voronoi treemapVoronoi treemap Similar idea but uses Similar idea but uses

voronoi diagram as voronoi diagram as partitionpartition

The space does not The space does not have to be rectangle.have to be rectangle.

Page 21: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Beamtree

A variation of treemap in A variation of treemap in 3D.3D.

Using overlap instead of Using overlap instead of nesting to show the nesting to show the hierarchyhierarchy

3D version: representing 3D version: representing each node as a beameach node as a beam

A bigger exampleA bigger example

Page 22: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Space-filling tree layout

Try to use as much screen space Try to use as much screen space as possibleas possible

Layout a tree according to the Layout a tree according to the recursive partition of the screen recursive partition of the screen spacespace The area allocated to a The area allocated to a

subtree is proportional to its subtree is proportional to its size.size.

A bigger example: 55000 nodesA bigger example: 55000 nodes Use all the screen spaceUse all the screen space Not very effective on Not very effective on

showing the tree structureshowing the tree structure

Page 23: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Other space filling methods - Icicle Trees Edges implied by Edges implied by

adjacency and spatial adjacency and spatial relationship.relationship.

• icicle tree in the icicle tree in the infovis toolkit (jean-infovis toolkit (jean-daniel fekete)daniel fekete)

Page 24: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Information slice and Sunburst Diagrams

Information slice Information slice also a space-filling also a space-filling

visualization method.visualization method. Radial version of icicle Radial version of icicle

trees.trees. Node size is proportional Node size is proportional

to the angle swept by a to the angle swept by a node.node.

SunburstSunburst With extra focus+contextWith extra focus+context Details are shown outside Details are shown outside

or inside the ringor inside the ring

Page 25: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Elastic hierarchies

hybrid of node-link hybrid of node-link diagrams and treemapsdiagrams and treemaps

Using node-link Using node-link diagram inside a diagram inside a treemap produces lots treemap produces lots of crossingsof crossings

Page 26: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

TreeViewer

Visualizes trees in a form Visualizes trees in a form that closely resembles that closely resembles botanical treesbotanical trees The root is the tree stemThe root is the tree stem Non-leave nodes are Non-leave nodes are

branches branches Leave nodes are Leave nodes are

“bulbs” at the end of “bulbs” at the end of branchesbranches

Example: Unix home Example: Unix home directory.directory.

Page 27: Abstract Syntax Tree Rendering Noah Brickman CMPS 203

Collapsible Cylindrical Trees Telescope metaphor: A set of Telescope metaphor: A set of

nested cylindersnested cylinders A cylinder is constructed A cylinder is constructed

for the children of a node, for the children of a node, and it has a smaller radius. and it has a smaller radius.

This cylinder is nested and This cylinder is nested and hidden within the cylinder hidden within the cylinder contain the parentcontain the parent

It can be pulled out to the It can be pulled out to the right of theparent cylinder right of theparent cylinder or collapsed as necessary. or collapsed as necessary.

only one path of the hierarchy only one path of the hierarchy is visible at onceis visible at once represented by a number of represented by a number of

ever decreasing cylindersever decreasing cylinders All cylinders of level 1 nodes All cylinders of level 1 nodes

are shownare shown in a horizontal in a horizontal fashion, like being put on a fashion, like being put on a stick.stick.