Your goal is to build a symbol table for a simple object-oriented programming language, which we can call L. As a practical matter, all you need to do is add actions to the grammar shown below to create symbol objects and add them to a symbol table that is a cross between patterns 18 and 19 in Language implementation patterns. To keep things simple, you don't need to handle inheritance, but there are classes; even classes nested in functions. You also don't need to do field lookup to keep the assignment short.
Here's a sample input program.
There are only two built-in types: int and float. We can't even reference the classes we define (since we are going to access fields, there is no point). functions within a single class must be uniquely named and all class names must be unique. Do not worry about forward references. In other words, do everything in one pass. You do not need to build tree. Let's focus on just getting the symbol table correct.
The grammar below reads this in and detects syntax errors, but nothing else. Add actions as appropriate to build up a scope tree. At each class, field, function, argument, and variable definition, you need to create a symbol object. The symbols for classes and functions play the role of scopes as well and each contain a list of symbols in that scope. Each scope symbol has a parent or enclosing scope. The enclosing scope of the function is always a class, but the enclosing scope of the class could be a class or a function. For each variable reference (see rules stat and expr), look up the symbol and announce which scope it lives in.
The output of the program is a series of symbol definition and lookup reports, prefixed with the line and character position in the line. For example, for the above input, I would expect something like:
You should put the main() directly in the @members section of your grammar
You will create a jar file called sym.jar containing source, grammar, and *.class files and place in your build directory:
I will run your code by executing the following:
You can use the svn account for development of the software too if you would like, but I will only be looking at your jar file in the build directory.
For more information, see svn in CS601. Naturally you will have to substitute cs652 for cs601.