CS 210 Homework #5: Java

Due: Sunday May 10, 11:59pm
Turnin: a .zip file containing your source files only (no .class files) on bblearn

Use Java to write a program that reads in a set of Unicon .icn source files, and writes out a "JSON summary" of them as follows. Your program should be named unison and should be invoked on a command line such as

java unison a.icn b.icn c.icn

Your program should open, read, and analyze the contents of each source file in turn. Your program should write out a file named uniuml.json in a format described below.

The generated JSON file should contain a description of the object-oriented contents of the Unicon files, mainly listing their classes and superclasses, if any.

  If you see a   You should write Notes
class A
{ "class": "A" }
class A : B
{ "class": "A",
  "super": ["B"]}
class A : B : C
{ "class": "A",
  "super": ["B", "C"]}
class A(x,y,z)
{ "class": "A",
"fields": ["x", "y", "z"]
fields is a list of strings
method m()
{ "class": "A",
"methods": {"m": []}
methods is a table mapping method names to parameter lists

Note that every Unicon class starts with the word "class"; you can trigger on that. Then it has a class name that you will need to save. Then 0 or more superclasses, separated by colons (if you see a colon there, you have a superclass) Then a left parenthesis and a comma-separated list of 0 or more variable names and a right parenthesis. Then 0 or more methods starting with the word "method" and ending with the word "end", then an optional "initially" section. An end that is not the end of a method is the end of the class.

You do not have to do a full (context free grammar) parse of the input in order to do this assignment. Just read in the source file as lines, and looked for interesting keywords.

Test Files

"which unicon" should tell you where Unicon lives at (on cs210, it is in /usr/local/unicon/unicon/bin). Normally, Unicon's standard class libraries live at ../uni/lib and ../uni/gui relative to the location of the binary. Off of cs-210, you could alternatively browse them at their home on Unicon's source forge repository. For example, if you looked at object.icn you might generate the following:

your output
{ "class": "Object"
  "methods": {
"clone": ["seen"],
"to_string": ["depth", "seen"],
"equals": ["other", "seen"],
"hash_code": ["depth", "seen"],
"get_class_name": [],
"get_id": [],
"get_class": [],
"is_instance": ["name"],
# ... depending on your Unicon version, there might be more
}
}