;This function checks the arguments and ;determines if they specify a DCFL. ;If the arguments do not define a DCFL, ;then it returns an appropriate error message. ;If the arguments do define a DCFL, then the function returns: ; An affirmation, ; A list of the language's variables, and ; A list of the language's terminals. ;All output from this function - even the error ;messages are returned as a list. ;There is not requirement for the output to be a list. ;However, returning it as a list allows for the use ;of the unit testing function. (define DCFL-checker (lambda ( axiom ; a list of atoms rules ; a list of lists of atoms. initialAngle ;real number [0, 360] turnAngle ;real number [0, 180] shrinkage ;real number [0.01, 100.0] ) (define variableList '()) (define terminalList '()) (cond ((not (atomlist? axiom)) '("Error: axiom is not a list of atoms")) ((not (applyFunctionToList? atomlist? rules)) '("Error: rules is not a list of a list of atoms")) ((not (checkRangeOfReal? initialAngle 0 360)) '("Error: initialAngle must be between 0 and 360.")) ((not (checkRangeOfReal? turnAngle 0 180)) '("Error: turnAngle must be between 0 and 180.")) ((not (checkRangeOfReal? shrinkage 0.01 100)) '("Error: shrinkage must be between 0.01 and 100.")) (else (begin (set! variableList (getFirstAtomOfEach rules )) (cond ((not (listOfUniqueAtoms? variableList)) '("Error: Nondeterministic CFL") ) (else ;At this point we are cool! ;No more errors to ckeck for. ;We already have the variableList complete. ;To build the terminalList we first cons ;the axiom list into the rules list. ;This new list will contain all of the ;terminals and variables in the CFL. (set! terminalList (extractUniqueAtoms (cons axiom rules)) ) ;Next, the variables need to be ;removed from the list. (set! terminalList (removeListFromList variableList terminalList) ) ;Build output list: (cons "Good DCFL" (cons "variables:" (cons variableList (cons "terminals:" (cons terminalList '()))))) ) ) ) ) ) ) ) ;============== Grading Rubric ================== ;The assignment is worth 20 points. ;Below are 17 test cases. ;Score one point for each test case that you pass. ;Score one point for having good comments. ;Score two points if John can quickly figure out ; how to download, save, run and test your code. ;Unfortunately, for the grader, I did not specify the exact format ;of the output. Therefore, John will not be able to use the ;automatic testing program. ;============== Unit Tests ====================== (load "test.scm") (load "atomlist.scm") (load "checkRangeOfReal.scm") (load "getFirstAtomOfEach.scm") (load "listOfUniqueAtoms.scm") (load "applyFunctionToList.scm") (load "extractUniqueAtoms.scm") (load "removeListFromList.scm") (define msg "DCFL-checker") (test msg (DCFL-checker '(a b c) '((a a a) (b b b) (c c c)) 1 1 1) '("Good DCFL" "variables:" (a b c) "terminals:" ()) ) (test msg (DCFL-checker '(a a a) '((a b c d) (b b b) (c c c)) 1 1 1) '("Good DCFL" "variables:" (a b c) "terminals:" (d)) ) (test msg (DCFL-checker '(a a a) '((a b x y z) (b b b)) 1 1 1) '("Good DCFL" "variables:" (a b) "terminals:" (x y z)) ) (test msg (DCFL-checker '(a) '((a a x) (b y b) (c c c)) 1 1 1) '("Good DCFL" "variables:" (a b c) "terminals:" (x y)) ) (test msg (DCFL-checker '(a z) '((a a x) (b y b) (c c c)) 1 1 1) '("Good DCFL" "variables:" (a b c) "terminals:" (z x y)) ) (test msg (DCFL-checker '(a z) '((a a x) (c c c)) 1 1 1) '("Good DCFL" "variables:" (a c) "terminals:" (z x)) ) (test msg (DCFL-checker '(a b c) '((a a a)) 1 1 1) '("Good DCFL" "variables:" (a) "terminals:" (b c)) ) (test msg (DCFL-checker '(a b c) '((a a a) (b b b) (b c c)) 1 1 1) '("Error: Nondeterministic CFL") ) (test msg (DCFL-checker '(a) '((a b c x) (b a x) (c a y) (b a a)) 1 1 1) '("Error: Nondeterministic CFL") ) (test msg (DCFL-checker '(a b (c)) '((a a a)) 1 1 1) '("Error: axiom is not a list of atoms") ) (test msg (DCFL-checker '(a b c) '((a a a) b (c c c)) 1 1 1) '("Error: rules is not a list of a list of atoms") ) (test msg (DCFL-checker '(a b c) '((a a a) (b b b) (c (c c))) 1 1 1) '("Error: rules is not a list of a list of atoms") ) (test msg (DCFL-checker '(a b c) '(() (b b b) (c c c)) 1 1 1) '("Error: rules is not a list of a list of atoms") ) (test msg (DCFL-checker '(a) '((a a a)) -400 1 1) '("Error: initialAngle must be between 0 and 360.") ) (test msg (DCFL-checker '(a) '((a b a)) 1 200 1) '("Error: turnAngle must be between 0 and 180.") ) (test msg (DCFL-checker '(a) '((a b a)) 1 1 200) '("Error: shrinkage must be between 0.01 and 100.") ) (test msg (DCFL-checker '(a) '((a b a)) 1 1 0) '("Error: shrinkage must be between 0.01 and 100.") )