CS 451-651   Homework #7 and #8

HW #7 is Due Wednesday, Oct 28   (due to hour exam)
HW #8 is due the following Monday, Nov 2 (to get us back on track)



When both of these assignments are done, your compiler will support the use of scalar variables, and have type checking.

HW #7:  Semantic Analysis

Implement the Semantic Analysis pass.  This includes:

HW #8: Scalar Variables

Building on #7, provide the ability to use scalar variables in expressions and assignments.  This includes:
We'll do arrays next week.


If you want to change the order of the subtasks, that's fine ... as long as you complete about 50% of the assignment by the HW #7 due date.


I'll provide some files that may be helpful.   Watch this space  (notice will be sent when new one appear)
Here's a collection, which includes my code for FunctionInfo and NameTable support...some ideas might be helpful.


Boolean:

Here's some of what's needed to provide a boolean type, which will be helpful in testing the semantic analysis type-checking code.   (for instance, it will allow you to write "apple = true * pie;", which should probably produce an error message.)

In Scanner.jflex:
 "true"  { System.out.println("  Scan: '"+yytext()+"'"); return sf.newSymbol("TRUE",   sym.BOOL_LIT, "1"); } 
 "false" { System.out.println("  Scan: '"+yytext()+"'"); return sf.newSymbol("FALSE",  sym.BOOL_LIT, "0"); }
Remember, in the calls to newSymbol, the SECOND arg is the symbol that the parser cares about (the one that appears in the grammar rules);  the third arg, if present, is the value associated with that symbol (i.e., the value accessed via the :label in the {: action code :}.


In Parser.cup, do something like this:
factor  ::= NUMBER:n
        {:
            RESULT= new LitNode(n, "int");
                    System.out.println("factor ::= number:  " + RESULT);
        :}

        | BOOL_LIT:bl
        {:
         // (our scanner returns value as 1 or 0 )
            RESULT= new LitNode(bl, "boolean");
                    System.out.println("factor ::= boolean literal:  " + RESULT);
        :}
(Note: you can probably send the constructor the reference to "Main.theIntType" -- just make sure theIntType has been created by the time the parser runs! 
OR, equally valid, just have a different class for IntLit and BooleanLit Nodes.)  (I was betting that most of the processing would be the same, so I could easily combine them)