This page is an accumulation of (we hope) helpful notes, hints, etc., that might be useful to you in doing Project #3.
There are several erroneous cases that could be handled either in the parser or in static semantics. To allow us to use test cases properly, we have to decide how to handle them. Detection of the following errors can wait until static semantic analysis. You are free to check for them during parsing, but be warned: we are postponing them because they present various difficulties for our grammar tools and yet are easy to handle during static semantics.
Be sure that your finished parser does not report unresolved shift/reduce or reduce/reduce errors. These generally mean you've done something wrong.
With the -v switch, bison and jbison produce a table (in a file with suffix .output) showing the LALR(1) machine that they produce. You can use this as shown in lecture to help find some problems.
If you include the command %debug in your .y file (as it is in the Java skeleton), then you can induce your parser to show the derivation it performs for your program by setting the yydebug variable in your parser to 1 (this is a static variable in C++ and an instance variable of the parser in Java). I'd suggest setting it in the main program. The classiest way is to provide a parser method to do so, and to call it from ParseTest in response to an appropriate command-line switch, but frankly, I often just run the parser under the debugger and set it from there.
Q: How should we treat "elif"? It isn't in the spec.
A: There is no construct for it, because elif is the same as else if:
if FOO: S1 elif BAR: S2 else: S3
if FOO: S1 else: if BAR: S2 else: S3
Q: Are we free to allow (or disallow) statements such as:
x *= y *= 2
A: Augmented assignments are STATEMENTS, not expressions, and may not be used as expressions. Thus the statement above is illegal.
Q: In dictionaries can keys and values only be expressions? If not what syntactic categories can they be?
A: They may only be expressions.
[CS164 Homework]   [CS164 Home Page]
Page was last modified on Thu Oct 12 14:39:30 2006.