School of Computer Science     University of Windsor

03-60-214: Computer Languages, Grammars and Translators (Winter 2012)
[Home] [Assignments] [Lecture Slides] [Resources] 

[Assignment 1]
[Assignment 2]
[Assignment 3]
[Assignment 4]

[Home]
[Up]
[Tiny Language]

 

 

Assignment 1

Regular expression in Java (5 points)

Due time: Jan 27, Friday. Because of the submission site problem, the deadline is extended to the next friday, 12:50pm.

Where to submit

You can submit your assignment at our submission site You can submit 5 times, and the last mark will be your final mark. For each submission you will get your marks instantly by email. If there is no email notification, please contact our GA Mr. Mai Yunming at maiy at u windsor You are welcome to contact our GAs for helping you with the assignment.

Here is a list of common errors that you may want to double check before submission:

  • print statement: our marking program does not allow it. you won't be able to see the print result on our server anyway. so remove print statements;
  • inner classes: the marking program changes the class names, but only to the outmost class name. If you have an inner class, there will be two different class names. There is no need to declare an inner class except confuse the marking program. So remove innner class.
  • Sometimes the output file is empty because you removed close() statement to save the space. But you can not save the space in this way .

    Purpose

    Warm-up with Java programming. Get familiar with regular expression. Understand the wide application of regular expression.

    Assignment specification

    Your job is to count the number of identifiers in programs written in our Tiny language.

    You should pick out the identifiers from a text file, and write the output to a text file (named A1.output). Note that the output file should contain a line like "identifiers:5" . Here are the sample input and output files.The input will have multiple lines. Please note that the following are not counted as identifiers:

    • A41, input, output: they are quoted hence they are not treated as identifiers;
    • INT, READ etc.: They are keywords used in our Tiny language hence they should not be picked up.
    In this assignment you can suppose that there are no comments in the programs.

    In the output file you should only write "identifiers:" followed by the number of identifiers. If there are multiple occurrences of an identifier in the input, you should only count it once. Don't write anything else into the output file.

    You will write two different programs to do this:

    1. Program A11.java is not supposed to use regular expressions, not regex package, not the methods involvoing regular expression in String class or other classes. Hence it will rely on StringTokenizer. Please refer to API JavaDoc for more details of the StringTokenizer specification.
    2. Program A12.java will use java.util.regex. Two useful links to start with are JavaDoc of regex and a  tutorial for Java regex
      In A12, you should not use StreamTokenizer or StringTokenizer.

    In this assignment, the output should be in a file called "A1.output". You should not use keyboard input.

    Your programs should be able to run by typing:

      %javac A11.java 
      %java A11  A1.tiny
      %javac A12.java 
      %java A12 A1.tiny
    
    The input file name will be provided as the argument of the program, while the output file name is hard coded in your programs.

    Your program should be tested on luna.  If your program can not run on luna, you will get zero for this assignment. Windows version of program is not accepted.

    Please don't write unnecessarily long programs. The sample solutions for A11 and A12 consist of approximately 300 words altogether by PHP function str_word_count(), which are not written deliberately for short length and can be compacted into smaller sizes easily. Hence one mark is given if your wordcount is smaller than 300.

    Marking Scheme

     yourMark=0;
     if (A11.java, A12.java are not sent properly) return; 
     for (each of A11, A12) 
          if (it is compiled correctly)  yourMark+=0.2;  
     for (each of A11, A12){
              if (your java program reads A1.tiny && generates result file A1.output)
                         for (each of the 6 tests cases) 
                               if (it is correct)   yourMark+=0.3;
              if youCode.length() < average(length of A11 in the class) yourMark+=0.5;
    
      }            
      for (each day of your late submission)  yourMark=yourMark*0.8;
      
    

    What to submit

    You should submit A11.java and A12.java. 

  • Instructor: Dr. Jianguo Lu     Email: jlu at uwindsor  Office: 5111 Lambton Tower        Phone: 519.253.3000 ext 3786