Next: Functions &Example Calls Up: USING ISTHMUS AND Previous: Creating the Environment

Using the Class Dictionaries in TclTk

There are examples of how to create and copy instances of classes in the main.tcl.sample file. There are also sample calls to several member functions.

Since the user must begin with a class dictionary, here is a sample cd.cd file:


C = "club" <head> A.
A = "has" <members> MemberList [<suba> SubAList].
MemberList ~ "members" "(" Member {Member} ")".
Member : Regular|Officer *common* <salary> Salary.
Regular = "regular" <r> DemIdent.
Officer = "officer" <o> DemIdent.
Salary = "salary" <s> DemReal.
SubAList ~ "subs" "(" {SubA} ")".
SubA : Whole|Partial *common* <a> A.
Whole = "whole" <w> DemString.
Partial = "partial" <p> DemString.

Another file it is useful to have is a demeter-input, this file defines a specific object defined by the class:


club has members 
( regular Fred salary 35.15 
  officer Simon salary 225.00 
  officer Allison salary 279.12 ) 

subs ( whole "demeter" has members 
       ( regular Mark salary 42.97 
         officer Matt salary 122.10 )
       partial "isthmus" has members 
       ( regular Doug salary 44.52 
         officer Laura salary 214.84 
         officer Phil salary 257.32 )
     )

Here is the main.tcl.sample file:


# tcl sample program generated by ISTHMUS

# Change this line if your input file has a different name 
set Dem_input "demeter-input"

#------------------------------------
#Parsing an object
#------------------------------------
puts "Parsing in object in: $Dem_input ."
set iC [C new:]
$iC g_parse: $Dem_input
#------------------------------------
#Drawing an object
#------------------------------------
puts "Drawing in the parsed object:"
$iC g_draw:
#------------------------------------
#Copying an object
#------------------------------------
puts "Copying in object."
set nC [$iC g_copy:]
#------------------------------------
#Activating
#------------------------------------
puts "Activating."
activate $nC C 
#------------------------------------
#Displaying the copied object as a tree
#------------------------------------
puts "Displaying the copied object as a tree:"
$nC g_displayAsTree:
#------------------------------------
#Comparing the two objects
#------------------------------------
puts "Comparing the two objects"
set result1 [$iC g_equal: $nC ]
if {$result1 == 1} { puts "copied and original objects are equal"
} else {puts "copied and original objects are NOT equal" }
#------------------------------------
#Printing an object
#Not implemented because g_print is not taking filename
#as input
#------------------------------------
puts "Pretty printing the parsed object:"
#$nC g_print: notmod/tmp/demeter_tcl_output
#------------------------------------
#Your code follows after this
#------------------------------------


#------------------------------------
#Deleting created objects
#------------------------------------
delete $iC 
delete $nC 
#**** FINISHED ******

An important thing to remember about using Isthmus to create the interface code is:

  1. If you are using the wish shell, comment out the delete lines from main.tcl if you wish to use the example classes which are created in main.tcl.


gollum@ccs.neu.edu
Fri Mar 17 08:23:12 EST 1995