Gold University of Minnesota M. Skip to main content.University of Minnesota. Home page.
 
 
 

What's inside.

International Final

Problem A

Problem B

Former Regional & World Contest Problems & Online Judge

The Official ICPC Site

 

ICPC Home



Email the Coach

Subscribe to the mailing list

 
 

Printer-friendly version

 

Problem A. Syntax Highlighting

Professor Sandwichthrower insists upon writing code in the obscure programming language Qadgop, so you have been nominated to write a program to make her programs more easy to read in a web browser, by adding syntax highlighting in HTML, as precisely defined below. No advance knowledge of HTML is necessary to solve this problem.

For the purposes of syntax highlighting a Qadgop program consists of a sequence of the following lexical entities.

  • White Space: a sequence of tabs and spaces

  • Comment: a # character followed by any text until the end of the line

  • Reserved word: any of the following words:
    • if unless then else elseif while until do for function method class return break next device yield

  • Operator: any sequence of the characters ~!@$%^&*()-+={}[]|\:;<>,.?/

  • Number: either a sequence of digits (e.g. 15920) or a floating point of one of the three forms as in C++ or Java, e.g. 1e-17 or 2.43e-21 or 123.456, all without a leading minus sign

  • String: This is doubly quoted as in C++ or Java with \ as an escape character, so \\ represents \, \" represents " and there are other escapes such as \n where the \ is followed by a single character; no other escape sequences are permitted.

  • Identifier: any sequence of characters starting with a letter or underscore, followed by zero or more letters, underscores and digits, that is not a Reserved word (defined above)

Your program should first output the following text, exact layout not being important. You may cut and paste this from the browser.

<html><head><title>Qadgop Program</title>
<style type='text/css'>
body {
Font-Family : Courier New, Courier ;
Font-Size : Small
}
.Keyword {
Font-Weight : Bold
}
.String {
Color : #009900
}
.Operator {
Color : blue
}
.Number {
Color : #9900CC
}
.Comment {
Color : #993300 ;
Font-Style : Italic
}
</style>
</head>
<body>

Then it should write out the input converted to HTML as described below. And finally it should write out the following text.

</body></html>

Each line of input is a sequence of the lexical elements described above. Each instance lexical element excepting Identifier and Whitespace should be replaced by preceding it with a span tag and ending it with a closing span tag exactly as in the following examples.

<span class="Keyword">while</span>
<span class="Number">123456</span>
<span class="String">"Hello"</span>
<span class="Operator">+:=</span>
<span class="Comment">#this is a comment</span>

Additionally, certain characters are not permitted in HTML, so if any of the characters <>&" appear in the input, they are to be replaced by escape sequences as follows, before the above tags are inserted.

Replace " by &quot;
Replace < by &lt;
Replace > by &gt;
Replace & by &amp;

Finally, in an instance of Whitespace, each space or tab should be replaced by non-breaking spaces as follows.

Replace space by &nbsp;
Replace tab by &nbsp;&nbsp;&nbsp;&nbsp;

Each line of input becomes a line of output by applying the above transformations, and is then written out terminated by the following tag followed by a newline.

<br>

Sample input and output will be provided.

 
The University of Minnesota is an equal opportunity educator and employer.
International Collegiate Programming Contest