Introduction to GAIGS XML Scripting

coordinatedcapableSoftware and s/w Development

Nov 4, 2013 (3 years and 9 months ago)

53 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



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
E
xtensible
M
arkup
L
anguage



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
D
ocument
T
ype
D
efinition
s



XML

files can then be
validated

against the
DTD

<
!ELEMENT

show

(
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

<
!ELEMENT

snap

(
title
,
doc_url
?,
pseudocode_url
?,




(
tree
|
array
|
graph
|
stack
|
queue
|
linkedlist
|
bargraph
|
node
)*,


question_ref
? )>


<
!ELEMENT

title

(
#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

<
!ELEMENT

stack

(
name
?,
bounds
?,
list_item
*)>


<
!ELEMENT

list_item

(
label
)>

<
!ATTLIST

list_item

color
CDATA

"
#FFFFFF
">


<
!ELEMENT

label

(#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 unit

wide

and
high


0,0

is the bottom left corner

<
!ELEMENT

bounds

(
EMPTY
)>

<
!ATTLIST

bounds

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
"?>

<
!DOCTYPE

show

PUBLIC

"
-
//JHAVE//DTD GAIGS SHO//EN
" "
gaigs_sho.dtd
">

A Simple, but Complete, Example

<
?xml

version="
1.0
" encoding="
UTF
-
8
"?>

<
!DOCTYPE

show

PUBLIC

"
-
//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

<
!ELEMENT

snap

(
title
,
doc_url
?,
pseudocode_url
?,




(
tree
|
array
|
graph
|
stack
|
queue
|
linkedlist
|
bargraph
|
node
)*,


question_ref
? )>


<
!ELEMENT

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


<
!ELEMENT

snap

(
title
,
doc_url
?,
pseudocode_url
?,




(
tree
|
array
|
graph
|
stack
|
queue
|
linkedlist
|
bargraph
|
node
)*,


question_ref
? )>


<
!ELEMENT

pseudocode_url
(
#PCDATA
)>

DTDs for the Snap and Pseudocode_url Elements


f


f

Example with Documentation

and Pseudocode

<
?xml

version="
1.0
" encoding="
UTF
-
8
"?>

<
!DOCTYPE

show

PUBLIC

"
-
//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
>