CS 412/413 Spring 2001 PA5: Iota+ =============================================================================== For PA5, you will have to implement AST generation, semantic type-checking and code generation for Iota+. You are free to build upon the supplied reference implementation of pre-PA5, or to ignore it and use your own code. The advantages of starting with the supplied pre-PA5: * LR grammar. * Utilizes generated lexer and parser via JLex and CUP. * Support for pre-PA5 code. The disadvantages of starting with the supplied pre-PA5: * You will need to learn some JLex and CUP (not very difficult). * You will need to integrate your existing AST code into the pre-PA5 grammar The advantages of staying completely with your own code: * You already know your own code. The disadvantages of staying completely with your own code: * You will have to make the LL Iota+ grammar additions on your own. =============================================================================== Important files: Iota\Lexer -- the Iota lexer as a JLex specification Iota\Iota.cup -- the LR Iota+ grammar as a CUP specification Iota\Token.java -- used by the parser, it returns filename and line number information =============================================================================== JLex information A JLex file accepting both Iota and Iota+ tokens has been created. It should provide adequate functionality for most Iota+ programs. If there are any major bugs, please report them. =============================================================================== CUP information The expected modifications to the code for Iota+ support have been flagged with "TODO". Iota.cup is the CUP specification file defining the Iota+ grammar in LR form. Currently, all Parser actions are empty. You will have to fill these in with actions corresponding to your AST nodes and type- checking structure. Most productions return a "RESULT", which is a CUP meta-variable. The type of the "RESULT" is defined at the beginning of the file in the "non terminal" clauses section (which also need to be filled in). For example: //At the beginning of the file non terminal ProgramNode program; non terminal ModuleNode module; .... //The productions program ::= MODULE module:a {: /******************** *Notice that program is of type ProgramNode *and RESULT is being assigned a ProgramNode ********************/ RESULT = new ProgramNode (a); parser.setProgramNode (RESULT); :} | INTERFACE interface:a {: RESULT = new ProgramNode (a); parser.setProgramNode (RESULT); :} ; module ::= uses:a defns:b {: RESULT = new ModuleNode (parser.getFilename (), Math.max (a.getLineno (), b.getLineno ()), (Vector) a.getValue (), (Vector) b.getValue ()); :} ; ... First, note that all Java code must go between {: and :}. Secondly, note that the ":" allows labels for each element of the right-hand side of the production (so, in the 'program' production 'module' in the right- hand side is labeled with an 'a'). The RESULT of the 'module' production can then be referred to in the Java code of the program production as 'a'. Also note that the labels are optional. For example, MODULE does not have an identifier associated with it, because it does not hold any useful information, since it is a terminal. =============================================================================== Running the program : Lexical Analysis ---------------- java Iota.LexTest [-quiet] Parsing ------- java Iota.SemTest [-dump_ast | -no_typecheck] Make sure the CUP class files are in your classpath before running Iota.SemTest =============================================================================== Tasks : (1) Give types corresponding to your AST nodes to all of the non-terminals in Iota.cup. (2) Fill in the parser actions for all the productions. (3) Modify SemTest.java to do AST dumps and typechecking. (4) Make sure the Iota portion of your program is working correctly (including code generation). If you suspect that there are bugs in the original grammar, please report them. (5) Create the Iota+ non-terminals. (6) Create productions and actions for these non-terminals, creating AST nodes and type-checking constructs as needed. (7) Implement code generation for Iota+.