-------------------------------------------------------------------------- Software Development Fall 2005 CSU 670 -------------------------------------------------------------------------- Assignment 3 Due date: Sep. 30, 2005 -------------------------------------------------------------------------- This assignment is stored in file $SD/hw/3 in file assign.txt -------------------------------------------------------------------------- ========= We reuse the abbreviations already introduced in hw 1: ========= THEMES: Evolution of Java programs, change design, translate to Java READING: Read section 12 of TPP: Domain Languages. What are the minilanguages that we are using? What is our favorite way to define a minilanguage? Read section 14 of TPP: The power of plain text. What kind of knowledge do we keep in plain text? Read chapter 3: The Basic Tools. Are you using one editor that works well on Unix and Windows? This homework requires use of DemeterJ (only a few features) and DJ. Browse the resource guide at: $D/DemeterJava/ Installing: For this homework, you need DemeterJ. Follow the instructions in: http://www.ccs.neu.edu/research/demeter/software/docs/install.html Please note that homework submission is electronic submission using Blackboard and hardcopy. This will allow the teaching assistant to run your programs. In ADDITION, please turn in your answers in hardcopy. See instructions in previous assignments. Question 1: ----------- (This question jointly developed with Jingsong Feng.) PART 1.A -------- Motivation: Translation between languages / XML The *.beh files contain Java methods between {{ and }} that are assigned to various classes. Each *.beh file is of the form: X{ {{ // method 1 // method 2 // etc. }} } Y{ ... } ... and therefore the .beh files are basically 99.99999 % Java code. When you write your own .beh files, use your editor to make sure that the parentheses are balanced inside {{ and }}. In the lecture we translated bus route descriptions to Scheme make-* expressions. See /home/lieber/.www/courses/csu670/f05/examples/BusRoute In this homework we translate bus route descriptions to XML documents. Use the following class dictionary as the definition for the input language. import edu.neu.ccs.demeter.dj.*; import java.io.*; BusRoute = Ident "buses" List(Bus) "towns" List(Town). Bus = Ident List(Person). Town = Ident "busStops" List(BusStop). Person = Ident. BusStop = Ident List(Person). List(S) ~ "(" {S} ")". Main = String. Bus route descriptions in the language are short and your task is to translate them into longer XML docmuments. In XML the bus routes have the following format: (file: busroute.xml) The files mentioned in this hw are in the hw directory (see /xml). See also $SD/examples/sameInXML*. XML has something similar to class dictionaries. They are called DYDs and the above XML document satisfies the following DTD: (file: busRoute.dtd) This is basically the same information as in our class dictionary with the exception that the lists must be non-empty in the XML document. In the following you must use Microsoft Internet Explorer version 5 or later. The following HTML file, when loaded into Explorer will test whether your XML document satisfies the DTD. (file: checker.html) A checker for verifing XML file against its DTD

This is a checker for verifing XML file against its DTD.


The following is the result for verification:
The following HTML file, when loaded into IE, will process your XML document and compute the names of the people waiting at the bus stops. (file: xpath.html)

This page is to demonstrate use XPath to query data in xml file:


Use a visitor to do the translation. Use the visitor with the traversal that visits the entire BusRoute-object. Turn in the modified directory that contains your new visitor. The directories must contain your test inputs and a README file that contains appropriate documentation how to use your directory. Remember: Before you zip up a directory generated by demeterj, run "demeterj clean". =================== Some technicalities DemeterJ has a project file facility which works pretty much the same on any platform (the file paths need to be adjusted from platform to platform). Typically, the project file is called program.prj A default program.prj file is generated by "demeterj new". If you use DemeterJ on a PC with Windows and you copy my program.prj, make sure you change the / to \ in the file paths. Also, you need to replace javacc by javacc.bat. PART 1.B -------- Translate from XPath to traversal strategies. Assume that the context node is of type Start. .//B//C .//Book | .//Cd Part 1.C -------- Translate from traversal strategies to XPath. from A to B from A to {B,C} Question 2: ----------- The following files and directories refer to $SD/hw/3 Motivation: Learn about how an adaptive program defines a family of object-oriented programs. Learn how to modify one adaptive program instead of two object-oriented programs. Consider the Java programs *.beh in onlyDJ-average-default-list onlyDJ-average-other-list They are identical and you can convince yourself by running check-diff which is provided in the hw 3 directory. Basically, I want changes to the *.beh files that are the same to both directories that would give the "correct" result in both directories. The differences between the 2 directories is the class dictionary. One is much simpler than the other. The Java program (in *.beh) is supposed to print out the running average as Weight-objects are encountered during the traversal. The last number printed by the program should be the average weight. Unfortunately, the program is broken and you are asked to repair it with minimal changes to the files. Your task is to correct one or more of the *.beh files so that they work correctly in BOTH onlyDJ-average-default-list onlyDJ-average-other-list demeterj test allows you to test the corrected *.beh files after modification. You should find the MINIMAL modification necessary to make the program correct. Turn in for each behavior file that you changed the corrections that you made. Clearly indicate what you corrected in each *.beh file. Question 3: Write a class dictionary for Chinese food. Your class dictionary should accept the sentence shown below: Food Menu: Meal 1: gongbao chicken egg soup bun, dumpling Meal 2: five flavored beef, tiger skin egg three delight soup noodle Meal 3: gongbao chicken, five flavored beef, tiger skin egg egg soup bun, dumpling, noodle Meal 4: tiger skin egg, gongbao chicken, five flavored beef egg soup Turn in a class dictionary that defines a menu language implied by the above example. It should start with: ChineseFoodMenu = "Food" "Menu:" List(ChineseMeal). ... Use DemeterJ to test your class dictionary for syntactic and semantic correctness: 1. Install DemeterJ 2. demeterj new 3. put your class dictionary into program.cd 4. put above example into program.input 5. In method Main.main in program.beh, remove "Main m = parse(System.in);" then add "ChineseFoodMenu m = ChineseFoodMenu.parse(System.in);" 6. demeterj test should not give syntax or semantic errors on the class dictionary or compilation errors from the Java compiler. ====================== System help: When you think DemeterJ behaves unexpectedly, use demeterj clean which will remove all the generated code.