|
CSE307 Spring 2009 Stony Brook |
Principles of Programming Languages
Annie Liu Assignment 3 |
Handout A3 Feb. 24, 2009 Due Mar. 12 |
Semantic Analysis --- Analyzing Names
This assignment has two goals: (1) analyzing names used in the policy rules read in from Assignment 2, (2) programming more in Python, and (3) understanding better the EHR policy and TPG parsing. We will continue to use the EHR policy rules and the Python programs for reading in these rules from Assignment 2. We will also continue to use Python 2.6 instead of Python 3.0.
Analyzing names
We will focus on two kinds of names: predicates and constructors. You may want to review what they are from classes and from Assignments 1 and 2.
Each predicate is used with some number of arguments; the number of arguments is called the arity. While some languages allow a predicate to have different arities, others do not; predicates in the EHR policy are intended to have unique arities. Some languages allow arities of predicates to be declared and uses of predicates to be checked against declarations, while other languages leaves these to the programmer; the latter is the case for the EHR policy rules. Our task here is to analyze the arities of all the predicates in the policy rules.
Specifically, we will
1. show the total number of predicates;
2. for each predicate, determine its possible arity or arities at all uses of the predicate;
3. show all predicates and their possible arity or arities sorted by the predicate name;
4. for each predicate that has more than one arity:
4.1. show the number of times the predicate is used with each different arity;
4.2. find the arity or arities that are used the minimum number of times among 4.1;
4.3. show the enclosing atoms of the predicates that have the arity or arities in 4.2, along with the rule names.
For example, for the EHR policy, the output may include the following
total number of predicates: ... ... is-emergency-clinician 2 isDeactivated 3 isDeactivated 2 no-main-role-active 1 ... isDeactivated: arity 2 occurs 101 times, arity 3 occurs 1 times (S3.1.4) isDeactivated(pat,cli1,Referrer(pat,org,cli2,spcty1))
Do the same for predicates above for constructors, except for 4.3, show the enclosing structures (the Function objects) of the constructors, instead of the enclosing atoms (the Atom objects) of the predicates.
Programming more in Python
Try to write good programs, i.e., programs that are clear and easy to understand, and that are sufficiently efficient. In particular, the part for analyzing constructors should reuse the part for analyzing predicates as much as possible.
Understanding better the EHR policy and parsing using TPG
Look closely at the grammar in file ehrparse.py. In
particular, note that predicates may be in not only Atom's in
conclusions and hypotheses, but also RemoteAtom's in hypotheses, and
furthermore, RemoteAtom's in the arguments of Atom's; and constructors
may be in the arguments of all of these.
Extra credit suggestions
Here are some ideas. (1) Finish this assignment by Thursday March 5, and receive 10% extra credit. (2) Think of ways to analyze the types of the arguments of predicates, and do them; partial information about types counts too, such as some argument of some predicate always being a structure of some constructor. (3) Think of other interesting and/or useful things to analyze about the EHR policy, and do them. (4) Think of ways to improve the EHR grammar. Feel free to discuss any of these with me.
Handins
Hand in everything electronically, using Blackboard, by 5pm on the due date. Your handin should include your README file, code, test data, and anything else you have to show your work.
Grading
This assignment will be graded based on 100 points, allocated in proportion to the estimated amount of work for each part. You may do this assignment in a team of two people; the two people will receive the same points. Exceptionally well thought-out and well written work will receive appropriate extra credit. Extra credit work will be graded based on the estimated amount of extra work.