190 likes | 274 Views
Introduction to GAIGS XML Scripting. Integrating Algorithm Visualization into Computer Science Education Grand Valley State University June 13-16, 2006. What is GAIGS?. GAIGS stands for G eneralized A lgorithm I llustration via G raphical S oftware
E N D
Introduction to GAIGS XML Scripting Integrating Algorithm Visualization into Computer Science Education Grand Valley State University June 13-16, 2006
What is GAIGS? • GAIGS stands forGeneralized Algorithm Illustration via Graphical Software • It is an algorithm visualization scripting language that captures and renders snapshots of the state of an algorithm at interesting events – critical points in its execution. • It provides high level support for data structures, interactive questions, documentation, and pseudocode.
What is XML? • XML stands for Extensible Markup Language • It is a meta-language that is used to define other languages • It uses a tag set and an associated syntax which is defined by the XML user • looks like HTML • Often used to define data description languages
Overall GAIGS XML Script Structure • A GAIGS script is defined in a show file • The show file contains XML specifications • Uses the .sho extension in the file name (e.g., test.sho) • The general script structure is: • one or more snapshots • followed by an optional question collection • The show file could be created by hand, or (more usually) as the output of a script generating program
Example of Overall Script Structure <show> <snap> … </snap> <snap> … </snap> <snap> … </snap> <questions> … </questions> </show> A Show File with Three Snapshots and a Question Collection
Defining an XML Grammar • The structure of an XML grammar is defined in a DTD file - a collection of Document Type Definitions • XML files can then be validated against the DTD <!ELEMENTshow (snap+, questions?)> DTD for the Show Element
Snapshot Structure • A snapshot defines an interesting moment in an algorithm’s execution • It includes a title, possible references to documentation and pseudocode, the data structure(s), and a possible question reference <!ELEMENTsnap ( title, doc_url?, pseudocode_url?, (tree|array|graph|stack|queue|linkedlist|bargraph|node)*, question_ref? )> <!ELEMENTtitle (#PCDATA)> DTDs for the Snap and Title Elements
The Basic GAIGS Data Structures • array • one or two dimensional • bargraph • graph • directed or undirected, weighted or not • linkedlist • queue • stack • tree • binary or general A General Tree
Sample Structure: The Stack • Stacks contain list items, as do arrays, queues, and linked lists • Each list item has an associated label <!ELEMENTstack (name?, bounds?, list_item*)> <!ELEMENTlist_item (label)> <!ATTLISTlist_item color CDATA "#FFFFFF"> <!ELEMENTlabel(#PCDATA)> DTDs for the Stack, List Item, and Label Elements
Stack Example <snap> <title>My Stack</title> <stack> <list_item color="#FF0000"> <label>8</label> </list_item> . . . <list_item color="#FF0000"> <label>10</label> </list_item> <list_item color="#0000FF"> <label>6</label> </list_item> </stack> </snap>
Positioning a Data Structure • Each of the data structures can be positioned in the view window • The view window is defined as one unitwide and high • 0,0 is the bottom left corner <!ELEMENTbounds (EMPTY)> <!ATTLISTbounds x1 CDATA #REQUIRED y1 CDATA #REQUIRED x2 CDATA #REQUIRED y2 CDATA #REQUIRED fontsize CDATA "0.03"> DTD for the Bounds Element
Positioning Example • The example code positions the stack in the left half of the view window • Note that the font size used by the structure can be set within the bounds tag as well - this affects the size of the structure elements as well <snap> <title>My Stack</title> <stack> <bounds x1="0.0" y1="0.0" x2="0.5" y2="1.0" fontsize="0.035" /> <list_item color="#FF0000"> <label>8</label> </list_item> . . . </stack> </snap>
Two Requirements for Show Files • Show file contents must be preceded by the two lines shown below • The first is a processor instruction that specifies the XML version and the character encoding • The second, the doctype, specifies the DTD to use with the show file <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPEshowPUBLIC "-//JHAVE//DTD GAIGS SHO//EN" "gaigs_sho.dtd">
A Simple, but Complete, Example <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPEshowPUBLIC "-//JHAVE//DTD GAIGS SHO//EN" "gaigs_sho.dtd"> <show> <snap> <title>Stack Example</title> <stack> <list_item color="#FF0000"> <label>10</label> </list_item> </stack> </snap> <snap> <title>Stack Example</title> <stack> <list_item color="#FF0000"> <label>8</label> </list_item> <list_item color="#FF0000"> <label>10</label> </list_item> </stack> </snap> </show>
Adding Documentation • Each snapshot can have an associated webpage by specifying a url • This webpage is shown in the info pane of the JHAVÉclient <!ELEMENTsnap ( title, doc_url?, pseudocode_url?, (tree|array|graph|stack|queue|linkedlist|bargraph|node)*, question_ref? )> <!ELEMENTdoc_url (#PCDATA)> DTDs for the Snap and Doc URL Elements
f • f
Adding Pseudocode • Each snapshot can have associated pseudocode by specifying a url • This webpage is shown in the pseudocode pane of the JHAVÉclient • JHAVÉ supports a particular pseudocode design, but this is not a ShowFile issue (i.e. is a topic for another session). <!ELEMENTsnap ( title, doc_url?, pseudocode_url?, (tree|array|graph|stack|queue|linkedlist|bargraph|node)*, question_ref? )> <!ELEMENTpseudocode_url (#PCDATA)> DTDs for the Snap and Pseudocode_url Elements
f • f
Example with Documentationand Pseudocode <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPEshowPUBLIC "-//JHAVE//DTD GAIGS SHO//EN" "gaigs_sho.dtd"> <show> <snap> <title>Stack Example</title> <doc_url>http://www.alma.edu/b.htm</doc_url> <pseudocode_url>http://www.alma.edu/bc.htm</pseudocode_url> <stack> <list_item color="#FF0000"> <label>8</label> </list_item> <list_item color="#FF0000"> <label>10</label> </list_item> </stack> </snap> </show>