Tuesday, January 5, 2010

Scanner assignment up

Grab http://www.cs.uoregon.edu/classes/10W/cis461/handouts/Cool.tgz to get started on the scanner (lexical analyzer) assignment.

I have filled in a lot of trivial grungy stuff and the stuff that doesn't really have anything to do with lexical analysis ... I think what's left for you to fill in should be pretty quick.   Keyword and punctuation patterns are certainly trivial ... you'll see the pattern in Cup.jflex Cool.jflex  and just fill in the few I removed.  Two patterns might take a bit more work: comments and strings.  There is a pattern for comments there already, and it *might* be right, but I don't promise.  There is a pattern for string literals, and I'd be really surprised if it is correct.   It's really ugly, too ... like a lot of complex regular expressions.  Consider using the lexical state facility of JFlex to break it down into simpler patterns that you can read, understand, and fix.

Java will complain that the generated scanner uses unsafe operations.  That's because the scanner skeleton file is written in the old, pre-generics style.   I'm using one of the optional skeletons because I threw in the ability to #include just for fun and to demo how that works ... it's not part of Cool, but it's something you'll want to do in another scanner some day. 

Due: Monday of next week.  The parser assignment will come out Monday or Wednesday.

The README.txt file says a bit more about what you'll find and how to get going.  Although the amount of work here should not be large, it's a good idea to tackle it soon, so that you have a chance to ask questions when things break.

2 comments:

  1. The README refers to a a file you started for us called "CUP.jflex" which I cannot find in the download. Process of elimination says "Cool.jflex" may be the file I am looking for. Can you verify?

    Here is the list of files I found in Cool.tgz:
    Cool/sym.java
    Cool/README.txt
    Cool/ScanDriver.java
    Cool/tools
    Cool/tools/tokenNames.awk
    Cool/symNames.java
    Cool/Symbolx.java
    Cool/lib
    Cool/lib/jflex-skeleton-nested
    Cool/lib/commons-cli-1.2.jar
    Cool/lib/java-cup-11a-runtime.jar
    Cool/lib/stringtemplate-3.2.1.jar
    Cool/lib/antlr-2.7.7.jar
    Cool/Cool.jflex
    Cool/ErrorReport.java
    Cool/tests
    Cool/tests/backslash2.cool
    Cool/tests/hairyscary.cool
    Cool/tests/pathologicalstrings.cool
    Cool/tests/arith.cool
    Cool/tests/closecomment.cool
    Cool/tests/typecase.cool
    Cool/tests/keywords.cool
    Cool/tests/types.cool
    Cool/tests/badidentifiers.cool
    Cool/Makefile
    Cool/scan

    Thanks for your help!!

    ReplyDelete
  2. Hmmm ... my first reply seems to have disappeared.

    There must be a typo in my instructions ... look for Cool.jflex instead of CUP.jflex. (CUP is a parser generator that we'll use in the *next* assignment.)

    ReplyDelete