CST320 Final Project Due Thursday of Dead week. Must be checked off before Wednesday of Finals week. Goal: The goal for the final project is complete all phases of the compilation process for a small language. In addition to the preprocessor, lexical analyzer and parser steps that we already did in previous labs, the final project will explore some back-end processing which includes semantic analysis, optimization and code generation. It depends on which project option you pick, one or more of these back-end steps would need to be implemented. You can work in pairs on the final project. You can pick any of the options below: 1. Project Option One: Traditional Compiler Back-end Processing. For this option, you can use your language and grammar from Lab 1. You can even build on your previous labs or use a Lex/Yacc-like tool. Project Requirements: It must provide these additional functionalities: a. Produce a parse tree data structure as an output from your parser. b. Perform semantic analysis on the program, including type checking, redefinitions of variables, undeclared variables, undefined functions, etc. c. Produce some intermediate representation or final target code. For example, Microsoft’s IL language or assembly instructions. You must verify that your instructions are correct. 2. Project Option Two: A Graphical Language and Simulator For this option, you need to write a lexical analyzer and parser for a language call Logo320. Logo320 is a subset of Logo language that controls “turtles” on the screen. You can write programs to create graphics using these turtles. Logo320 Grammar: Program -> Statement Statlist Statlist -> Statement Statlist Statlist -> lambda Statement -> Penup | Pendown | Forward number | Back number | Right number | Left number | Create number | If (Color == colorCode ) [ Statlist ] [ Statlist]| Setcolor colorCode | Repeat number [ Statlist ]| Define ID Statlist End | Call ID number is just an integer colorCode is a list of possible colors. You can make your own list. Some example colors include red, blue, black, green, yellow, purple, pink. ID is any combination of letters and digits but it must start with a letter. Bold are keywords. Here is an example program: Create 10 //this creates 10 turtles at random locations on the //screen. Each turtle is also given a random color //Each turtle is also facing a random direction Penup // do not draw with turtle movement Forward 10 // move all turtles on the screen 10 pixels in the // direction that they are headed Pendown // do draw with next turtle movement Right 90 // turn all turtles on screen 90 degrees Repeat 4 [Forward 10 Right 90 ] // repeat Forward 10 and Right 90 4 times for all // turtles on the screen. Since pen is down, // these turtles will leave a trail If (Color == pink ) [ Setcolor red ] [ Setcolor blue] //turn all pink turtles red and all other turtles blue Define drawbox Repeat 4 [Forward 10 Right 90] End //define a drawbox function with a repeat command in it Call drawbox //call the drawbox function Project Requirements: a. Implement a lexical analyzer to tokenize the Logo320 program. b. Implement a parser to check the syntax of the language (you can use either recursive descent or LL(1)) c. Construct a parse tree to save all the commands recognized in the parser. d. Implement some semantic analysis – checks to see if a function has been declared before use. e. Create a simple GUI program to simulate the program, i.e. draw something in the window as specified by the program. You don’t have to show actual turtles, just their trails. 3. Project Option Three: Language Interpreter For this option, you can use your language from Lab 1. Project Requirements: It must provide these additional functionalities: a. Produce a parse tree data structure as an output from your parser. b. Perform semantic analysis on the program, including type checking, redefinitions of variables, undeclared variables, undefined functions, etc. c. Process the statements and produce an output from the program, i.e. go ahead and “run it” and show the output from your input program. 4. Project Option Four: C++ language analyzer For this option, you will need to implement enough C++ syntax for a typical CST116 program. (Sample programs will be posted). Project Requirements: It must provide these additional functionalities: a. Implement a lexical analyzer for the language. b. Implement a parser of your choice to check the syntax of the language. (You may need to add to your subset in order to parse through a typical CST116 program). You can assume the file has been preprocessed correctly. You don’t have to worry about preprocessor directives or comments. c. Construct a parse tree as an output from the parser. d. Insert symbols into the symbol table as appropriate (variable names, function names, parameters, etc.) e. Insert the scope information into the symbol table also (0 for global, 1+ for non-global scopes) f. Perform analysis by computing the following metrics from the parse tree and symbol table: - Total number of symbols in the program. - Average length of identifiers in the program. - Average number of statements for compound statements. - Maximum number of scope levels for identifiers. - Number of if statements in the program. - Number of while loops in the program. - Number of input/output statements in the program. - Number of functions in the program. 5. LL(1) compiler tool For this option, you will need to implement a LL(1) parser generator. Input: A grammar specification. You should use your full language grammar as one of the input files. Output: A LL(1) table to work with your lab3. Project Requirements: - You can assume that left recursion has been removed from the grammar already, but your program still needs to be able to left factor the grammar. - Your program should be general enough to take any grammar as input but you can specify the file format for the grammar. - Your program needs to compute the first and follow sets from the grammar and produce the LL(1) table.