time due | submission file |
---|---|
9:00 AM Wednesday 15 November, 2006 | csci/431/HW9/tingle.atg |
In this assignment you are going to augment your solution to Homework 5;. Your attribute grammer should first process a series of "assignments" of the form:
-bulldog=50 +bulldog=25 -busbee=1000000
These should then be followed by a blank line (to avoid some LL(1) nastiness) and then by a series of Homework 5 style tests.
+busbee[> 30] & ~ ( -bulldog[< 20] | +candler [ > 15] ) +bulldog[< 20] | -busbee[< 20]
Your program should then evaluate the expressions and simply print either true or false for each.
For simplicity, you may (1) ignore all "assignments" regarding a computer except for the last one and (2) assume that any primitive test involving a computer that isn't mentioned is true. In the example above this means that bulldog has been up for 25 seconds, rather than down for 50 seconds; and that +candler[>15] is true.
To give everyone a working starting point, I'm attaching a copy of my Homework 5 solution.
// Homework 5 solution // J. Dean Brock COMPILER tingle CHARACTERS letter = 'A'..'Z' + 'a'..'z' . digit = '0'..'9' . TOKENS hostname = letter { letter } . number = digit { digit } . compare = '<' | '>' . updown = '+' | '-' . IGNORE '\t' + '\r' + ' ' PRODUCTIONS TingleExpr = TingleTerm { '|' (. System.out.print("| ") ; .) TingleTerm } . TingleTerm = TingleFactor { "&" (. System.out.print("& ") ; .) TingleFactor } . TingleFactor = ( TingleTest | '~' (. System.out.print("~ ") ; .) TingleFactor | '(' (. System.out.print("( ") ; .) TingleExpr ')' (. System.out.print(") ") ; .) ) . TingleTest = updown hostname "[" compare number "]" . tingle = { TingleExpr '\n' (. System.out.println() ; .) } . END tingle .