SE 550: Homework

Deadline: 5.30pm, Tuesday Feb 3, 2004

Homework

This week's homework is about using JavaCC to implement a client/server system.

First, you should download the JavaCC.zip archive, and put it on your CLASSPATH.

Then you should download and unpack the src.zip archive.

You should now be able to compile the parsers:

  java COM.sun.labs.javacc.Main -OUTPUT_DIRECTORY=ajeffrey/teaching/size/event/ ajeffrey/teaching/size/event/SizeRequestParser.jj
  java COM.sun.labs.javacc.Main -OUTPUT_DIRECTORY=ajeffrey/teaching/size/event/ ajeffrey/teaching/size/event/SizeResponseParser.jj

If this fails:

This will generate files:

  ajeffrey/teaching/size/event/SizeRequestParser.java
  ajeffrey/teaching/size/event/SizeResponseParser.java

You can compile the client and server with:

  javac ajeffrey/teaching/size/client/Main.java
  javac ajeffrey/teaching/size/server/Main.java

then test the client and server by starting a server listening on port 2000 in one window:

  java ajeffrey.teaching.size.server.Main 2000

and in another window start a client which connects to the server and asks for the size of the files ajeffrey/teaching/size/event/SizeRequestParser.java (which exists) and foobar (which doesn't):

  java ajeffrey.teaching.size.client.Main localhost 2000 ajeffrey/teaching/size/event/SizeRequestParser.java foobar

This will generate parse errors, such as (at the server end):

ajeffrey.teaching.size.event.TokenMgrError: Lexical error at line 1, column 1.  Encountered: "S" (83), after : ""
	at ajeffrey.teaching.size.event.SizeRequestParserTokenManager.getNextToken(SizeRequestParserTokenManager.java:323)
	at ajeffrey.teaching.size.event.SizeRequestParser.jj_ntk(SizeRequestParser.java:157)
	at ajeffrey.teaching.size.event.SizeRequestParser.quitRequest(SizeRequestParser.java:48)
	at ajeffrey.teaching.size.event.SizeRequestParser.parseSizeRequest(SizeRequestParser.java:44)
	at ajeffrey.teaching.size.server.ConnectionImpl.run(Connection.java:67)
	at java.lang.Thread.run(Thread.java:484)

and (at the client end):

Exception in thread "main" java.io.IOException: Parse error: ajeffrey.teaching.size.event.ParseException: Encountered "" at line 0, column 0.
Was expecting:
    "OK" ...
    
	at ajeffrey.teaching.size.client.ClientImpl.getSize(Client.java:113)
	at ajeffrey.teaching.size.client.Main.main(Main.java:27)

These errors are caused by the fact that the parsers are incomplete!

a. Complete SizeRequestParser.jj so it recognizes the grammar:

  <parseSizeRequest> ::= <sizeRequest> | <quitRequest>
  <sizeRequest> ::= "SIZE" <space> <fileName> <crlf>
  <quitRequest> ::= "QUIT" | <eof>
  <filename> ::= ( "/" )? <string> ( "/" <string> )*
  <string> ::= <char>+
  <char> ::= <alphabetic> | <digit> | <special>
  <alphabetic> ::= "a" | ... | "z" | "A" | ... | "Z"
  <digit> ::= "0" | ... | "9"
  <special> ::= ":" | "_" | "-" | "."
  <space> ::= " "
  <crlf> ::= "\n" | "\r" | "\r\n"

where <eof> is the `end-of-stream' marker (JavaCC has a built-in <EOF> token to mark `end-of-stream').

b. Complete SizeResponseParser.jj so it recognizes the grammar:

  <parseSizeResponse> ::= <foundResponse> | <notFoundResponse> | <okResponse> | <endOfStream>
  <foundResponse> ::= "FOUND" <space> <fileName> <space> <number> <space> "BYTES" <crlf>
  <notFoundResponse> ::= "NOT" <space> "FOUND" <crlf>
  <okResponse> ::= "OK" <crlf>
  <endOfStream> ::= <eof>
  <number> ::= <digit>+
  <filename> ::= ( "/" )? <string> ( "/" <string> )*
  <string> ::= <char>+
  <char> ::= <alphabetic> | <digit> | <special>
  <alphabetic> ::= "a" | ... | "z" | "A" | ... | "Z"
  <digit> ::= "0" | ... | "9"
  <special> ::= ":" | "_" | "-" | "."
  <space> ::= " "
  <crlf> ::= "\n" | "\r" | "\r\n"

You should recompile and test your parsers to make sure they work, then submit them as a zip archive using Courses On Line.