Next assignment is to build a parser for Cool. A starter kit (parts of the parser, plus a driver to call it) is at http://www.cs.uoregon.edu/classes/10W/cis461/handouts/parserKit.zip
A few notes on this:
- While in theory we got all the keywords and punctuation in the scanner, as I was finishing up my version of this I discovered I had missed a few ... so that's something to check when parsing fails.
- The driver accepts -d to mean "parse in debug mode", which is quite noisy but helps you see what tokens the parser is receiving and what it is doing with them. Unfortunately it prints them as numbers, so you need to look in sym.java to make sense of it. (This is pretty stupid ... CUP could easily have translated those integer codes into their symbolic names, but it doesn't.)
- I've filled in a lot, but left you a few things to figure out ... including how to make the comparison operations <, =, <= non-associative. Note that you could use precedence declarations in CUP and not factor the grammar down as far as I have to get precedence ... feel free to do it that way if you prefer.
- In the test files, watch out for things that are in Aiken's version of Cool and not our version ---- e.g., one of the tests has loop ... pool instead of do ... od.
- While my version of this (before I chopped stuff out for you to fill back in) worked on one example, I do not guarantee it is correct. You should write several small programs to test it.
- Small is beautiful, especially when you are debugging. If your parser fails on a program of 30 lines, the first thing you should do is cut it down to a program of 5-10 lines with the same failure.
When you start getting "shift/reduce conflict" and "reduce/reduce conflict" error messages from CUP, you will need to understand the LR parsing theory that we will start talking about tomorrow (Friday the 15th).
No comments:
Post a Comment