Homework VIII

(100 points)

 

This problem pertains to validation of  Web page comments (e.g., see http://www.htmlhelp.com/reference/wilbur/misc/comment.html). HTML inherited a rather weird comment syntax from SGML. Many popular browsers have ad hoc (and thoroughly broken) comment parsers. Various versions of browsers erroneously parse some incorrect comment examples as correct, and some correct comment examples as incorrect -- and which ones they get right and wrong varies from version to version. Virtually every browser does something wrong. What's the correct syntax for HTML comments? --or: Why does my document come up blank  on some browsers?

 

Write and test a Prolog predicate definition 'htmlComment(Xs)' that succeeds just in case Xs is a Prolog string (i.e., list of ASCII char codes) that is a valid SGML/HTML comment declaration according to the "full definition" rules given here.

 

First, here's the full definition of an SGML comment declaration:

* A comment declaration begins with the character sequence `<!', ends with the character `>', and contains zero or more comments.

* Comments begin and end with the character sequence `--', and may not contain `--'. Whitespace is allowed after any comment, but not before the first comment. Non-whitespace characters are not allowed before or after comments.

* A `>' inside a comment does not close the comment declaration.

 

Here are some correct examples:

           <!-- A simple comment declaration -->

           <!-- An equally simple comment declaration --   >

           <!-- A comment declaration --        -- with more

             than one --

             -- comment in it --

           >

           <!-- This `>' is inside a comment, and so doesn't close

                the comment declaration; the next one does, because it's

                not inside a comment. -->

           <!>

      

And here are some examples of incorrect comments:

           <!-- This comment is not terminated >

           <!-- Neither is this one ->

           <!-- -- Text is not allowed between comments -- --  >

           <! The initial `--' is not optional >

           <! -- Nor is whitespace allowed before it -->

           <!------>

 

The examples here are not intended as a complete test set for your program.

 

 

Submission instructions

Include documentation (in-line comments/write-up as appropriate) that makes it clear both what general method you used in constructing the program, and how the details of the program accomplish that method. You need to run test cases that exercise every component of your code (i.e., each clause, and success/failure of each goal within its body), and include documentation that justifies that your test data meets this condition. It is not  the grader's responsibility to figure out how you wrote the program and whether it is correct -- it is your responsibility to explain your program and convince the grader it is completely tested and correct. Full credit will not be awarded, even for (apparently) correct programs, unless you do so.

 

In addition to the paper submission as indicated, you should submit your Prolog source file electronically using the 'submit' command to course id c111 in directory Hwk8.