CS 6353 Compiler Construction Project Assignments

Size: px
Start display at page:

Download "CS 6353 Compiler Construction Project Assignments"

Transcription

1 CS 6353 Compiler Construction Project Assignments In this project, you need to implement a compiler for a language defined in this handout. The programming language you need to use is C or C++ (and the language defined by the corresponding tools). The project includes three phases, lexical analysis, syntax analysis, and code generation. In the following, we first define the language syntax and tokens. The definitions are given in BNF form. After the language definition, the three phases of the project are specified. 1 Language Definitions 1.1 Syntax Definitions program ::= { Program program-name function-definitions { Main statements } } program-name ::= identifier function-definitions ::= (function-definition)* function-definition ::= { Function function-name arguments statements return return-arg } function-name ::= identifier arguments ::= (argument)* argument ::= identifier return-arg ::= identifier statements ::= (statement)+ statement ::= assignment-stmt function-call if-stmt while-stmt assignment-stmt ::= { = identifier parameter } function-call ::= { function-name parameters } { predefined-function parameters } predefined-function ::= + * / % read print parameters ::= (parameter)* parameter ::= function-call identifier number character-string Boolean number ::= integer float if-stmt ::= { if expression then statements else statements } while-stmt ::= { while expression do statements } expression ::= { comparison-operator parameter parameter } { Boolean-operator expression expression } Boolean comparison-operator ::= == > >= Boolean-operator ::= or and To make the later references easier, let s call this language the FP language (similar to functional language syntax, but has the procedural language characteristics).

2 1.2 Definitions of Some Tokens An identifier has the form [a-z, A-Z][a-z, A-Z, 0-9]*, but its length has to be between 1 to 6 characters. Confining the number of characters in an identifier is not a good language design feature, but this is for you to learn a new feature in lex. An integer can have a negative sign ( ) but no positive sign. It can be with or without space(s) between the sign and the digits. If the value is 0, only a single digit 0 is allowed. Otherwise, it is the same as common integer definitions (no leading 0 s). A float has to have the decimal point and at least one digit on each side. The left side of the decimal point follows the rule for integers. The right side of the decimal point can be any number of digits but should have at least one digit. A character string is enclosed within (). It can be [a-z, A-Z, 0-9,, \]+. For example, (I like lex and yacc) is a character string. We use \ to represent a new line, i.e., \n in C. The character strings are mainly used in the read and print functions. The space is simply ( ). Some functions may use character strings as parameters. A Boolean can only be T or F, where T represents true and F represents false. 1.3 Definitions of the Predefined Functions Each of the predefined comparison operations and Boolean operators takes two parameters and the corresponding functionality follows the conventional definition. The predefined functions +, *,, /, and % also have the conventional meanings. +, *,, and / can take two or more parameters. For example, {* A B C} implies A * B * C. Similarly, and / can also take two or more parameters. For example, {/ A B C} implies A / B / C and { A B C} implies A B C. The % function can only take two parameters and {% A B} means A % B (A mod B). The predefine function print takes one or more parameters. It simply prints the value of each parameter to the standard output. Whenever a character string (\) is encountered, a new line should be printed. The space character ( ) should not be skipped and should be specified properly in lex token definitions. The predefine function read also takes one or more parameters. It reads from the standard input the values for the parameters. Since there will be no type definition in advance, the input can be integer, float, string, or Boolean values. Each value for the parameter to be read is separated by a white space. Although there are functions that take a fixed number of parameters, it is not your job to check the number of parameters (not in the lexical and syntax analysis phases). Also, it is not necessary to check whether the number of arguments and number of parameters do match (not in the lexical and syntax analysis phases). You only need to follow the general rules defined in the syntax of the language.

3 1.4 White Space To ensure the correctness in processing the input FP-program, you need to consider white space as well. White space characters include space, tab, and new-line. Treat the white space the same way as in other high level languages such as C++ and Java (skip white space). Note that space in a character string should not be skipped. 1.5 Some Remarks Note that we do not consider the language typing rules. Thus, there is no need to predefine variables and your FP program does not need to handle mismatched types. Also note that he FP language is case sensitive. 2 First Project -- Lexical Analysis Using lex Define the tokens in the FP language in lex definitions and feed it to lex to generate a scanner (lexer). Then, use the sample program as well as other testing programs written in FP to test your scanner. Note that it is your responsibility to convert the BNF (or verbal) definitions to lex definitions. It is also your responsibility to insert appropriate statements (actions) in your lex definition file so that the lexer (created by lex) will generate a symbol table and print the output token names appropriately. You should design the symbol table such that it contains the necessary fields for this as well as the future projects (you can make the table easy to expand for future fields). One additional task in this project is not an ordinary compiler compiler task, but is designed to let you explore more features in lex. For five of the predefined-functions, +,, *, /, and %, if their parameters are all number s, then you need to evaluate the function and let the returned token be one number (integer or float) and let the numerical result be the corresponding token value. You can consider this as a simple optimization. For example, if you are processing a substring {+ 3 {* 5 2 7}}, then you need to return tokens {, +, integer, integer, and } (the second integer has a value 70), not {, +, integer, {, *, integer, integer, integer, }, and }, not just integer either. Note that you are required to define regular expressions to achieve this (with special lex features). Finally, you also need to handle errors. That means you need to capture wrong tokens instead of letting lex capture them. Your program should continue even if there are wrong tokens. You may not know where to break for an incorrect token, so you can proceed to white space after discovering an incorrect token and resume token recognition after the white space. You need design your token definitions to fulfill this capability. The token symbol for an incorrect token is error an the token value is the text you captured for the incorrect token. Here defines the output from your program. We cannot do any processing at this stage. So you need to output the token names. Print one token on each line, in the correct order. The names of the tokens should conform to those given below. Keyword: Program, Function, return, if, then, else, while, and do. Predefined function: =, +,, *, /, %, read, and, print. Special symbol: { and }. Comparison operator: ==, >, and >=. Boolean operator: or and and

4 The remainder tokens: identifier, integer, float, character-string, Boolean. Note that for each token, you should output the token names as well as the values you obtained (in the same line). If you do not keep track of the original values, such as the identifier s name, the integer s value, the actual character string, etc., then, the information will be lost. The symbol table should be printed as well. You need to print out the content of the symbol table, one entry on a line. (In this phase, you only have the identifier names). The standard platform for this project is the university Solaris systems, including the servers and workstations such as apache. You should make sure that your program runs on these platforms. You need to electronically submit your program before midnight of the due date (check the calendar for due dates). Follow the instruction below for submission. Login to one of the university Solaris platforms. Go to the directory that only contains: The lex definition file for FP language. The file name should be FP.l. A file containing a sample program written in FP language that you have tested with the scanner generated from your lex definition file. The file name should be sample.fp. If you have multiple sample files, you can name them sample1.fp, sample2.fp, etc. A readme file that explains how to interpret your output from lex (the list of tokens). Also, if you have some information that you would like the TA to know, you can also put it in this file. The optinal Design.doc file that contains the description of some special features of your project that is not specified in the project specification, including all problems your program may have and/or all additional features you implemented. Issue the command ~ilyen/handin/handin.compiler. This command has to be issued in the directory that contains the files listed above. After submitting your project, do not delete or modify your code. Just in case something is wrong, you will have a chance to resubmit your program files with the original dates on them. You are responsible for generating your own testing programs and test your project thoroughly. We will use a different set of FP programs for testing. You need to consider the incorrect cases carefully as well. If your program does not fully function, please try to have partial results printed clearly to obtain partial credits. If your program does not work or it does not provide any proper output, then there will be no partial credits given. If your program does work fully or partially but we cannot make it run properly, then it is your responsibility to make an appointment with the TA and come to the department to demonstrate your program. According to the problems, appropriate point deductions will apply in these situations. If you do not follow the instructions for naming, you are creating trouble for testing, and there will be some penalty for that as well. 3 Second Phase -- Syntax Analysis and Type Using yacc For the second project, you need to define the FP-language in yacc definitions and feed it to yacc to generate a parser. Your definitions should follow the BNF given earlier, but exclude the token

5 definitions which have already been processed by lex and instead use the token names. The goal of the program is to generate a parse tree for the input FP program. In addition, you need to assign data types to identifiers and perform type checking. Note that FP language is typeless. So, in this project, you also learn how to convert a typeless language to a typed one (but our practice is a simple one). A change is made for the FP language definition. Specifically, the predefined function read is split into two functions, read-int and read-float, which reads integers and floating numbers, respectively. They still take one or more parameters. There will be no read functions that read character strings or Boolean values. predefined-function ::= + * / % read-int read-float print You need to modify your lex definition file to handle the two new read functions. Also, please note that in the lexical analysis in Project 1, you may have processed some tokens too early and it may cause incorrect processing of the input program. You may have to revise the lex definition file and push some of the processing to be done at the yacc level. It is your responsibility to find the problems and make the changes. 3.1 During Parsing In this section, we discuss what you need to do during parsing. First of all, you need to generate a parse tree during parsing. Each node in your parse tree should be labeled by the symbol of the node defined in the BNF of the FP language (e.g., +, Program, argument, return-arg, statement, statements, if-stmt, etc.) and has the value which is the text string grabbed from lex. For each identifier, instead of giving the actual identifier name, the value should be the pointer to the symbol table (the index of the symbol table). You have created a symbol table in the first project. Now you need to add more information into it. During parsing, you need to assign identifier usage types to each identifier. The usage type of an identifier is how the identifier has been used in the FP program. The identifier usage types include: program-name function-name argument return-arg assignment-id: the identifier in the assignment statement and is to be assigned a value expression-id: appear after comparison operators or Boolean operators parameter: all other parameters besides those listed above An identifier may be used in multiple ways in different parts of the program. You need to list all its usage types. The usage type list will be as long as the number of occurrences of the identifier in the program. In your symbol table, if an identifier is labeled as a function-name (usage type), then you need to maintain a list of callers and a list of callees. When processing the function-call statement (not for the pre-defined functions), you need to find out who is the caller. You can either check the parsing stack provided by yacc (with special label to the function name) or push additional pointers into the stack to link to the caller. You are NOT allowed to use a global variable to keep track of the current function under processing, even though it is actually the most efficient method (since the goal is for you to understand how to manipulate the yacc stack). Once the caller and callee are identified, you add them

6 into the caller and callee lists in the corresponding symbol table entries. Note that both the caller and callee lists should contain the indices (or the pointers) to the symbol table, not the function names. You will need these pointers later. Also note that the identifier with type program-name should have a callee list. Again, caller and callee lists will not contain the pre-defined functions. The identifier usage type list and caller and callee lists assignments have to be done during parsing (coded in the action part of the production rules). Thus, the order of these lists should follow the order of parsing. To show your processing steps during parsing, each time you change the symbol table, you need to print the entries that are being changed. Please reference the output section regarding how to print out a symbol table entry. 3.2 After Parsing, Data Type Assignment and Type Checking Once you obtain the parse tree, you need to perform type checking and assign a data type to each identifier (not for the program-name and the function-name) by traversing the parse tree. Since there is no data type definition in the FP program, you need to do extra work to identify the data types of the identifiers. When you process a read function call, data type can be assigned to the parameters according to the type of the read function (the parameters of read-int and read-float are integers and floats, respectively). When you encounter an integer, a float, a character-string, or a Boolean token, the token name automatically becomes its data type (this means you need to store temporary data types for some nodes that are not identifiers). In an assignment statement, the assignment-id (identifier) has the type of the corresponding parameter in the statement. The result of the predefined function % is an integer. The predefined functions +,, *, and / can only be applied to integers and floats. If the parameters of the function +,, *, or / include a float, then the result of the function is a float. If all the parameters of the function +,, *, or / are integers, then the result of the function is an integer. When you encounter a comparison-operator or a Boolean-operator, the result is Boolean. When you encounter a function-call statement (not the pre-defined functions), you should have already obtained the types of the parameters of the function. You should then go to the callee function, identify its corresponding arguments and assign the data types of the identifiers for the arguments as the types of the actual parameters. You also need to perform type checking for the input FP program. +,, *, and / can only be applied to integers and floats. % can only be applied to integers. Comparison operators > and >= can be applied to integers, floats, and character strings. Comparison operator == can be applied to any data type (integer, float, character string, and Boolean). Boolean operators can only be applied to Boolean. An expression has to be of type Boolean. Generally, in semantic analysis, type checking and semantic rule checking are performed. In this project, you do not need to check the semantics of the input FP program. You can consider the following semantic rules and assume that they are always satisfied in the input FP program. A function can only be defined once. For each function call, the corresponding function has to be defined in the program.

7 The number of actual parameters should be the same as the number of formal parameters. Each variable has to be defined before it is used. Note that there is no scoping in our FP program. Every identifier is global in the program. Thus, each identifier can only have one data type. When an identifier is assigned to two or more inconsistent data types, an error should be reported. Note that a subtype and a super-type are considered consistent. In our case, integer is a subtype of float and it is the only subtype and super-type relation we have in the language. When you find data type errors, you need to report the error by printing an error message together with the statement that is wrong, the identifiers that do not have the correct data types, and their actual (incorrect) types. It is very important that you perform data type assignments in a proper order. Otherwise, you may have to do the assignments in many rounds. When you process a function definition, you need to make sure that the data types of all its arguments must have already been assigned. If a function F was processed (have data type assignment done) using subtypes for some of its arguments and then later super-types are assigned to those arguments, then F needs to be processed again to correct its data type definitions. This correction may further impact the callers of F because its returned data type may change. Also, during processing, a caller of F may not know the data type of the returned argument till it is at least processed once. You should have your own design to minimize the number of rounds for traversing the tree. For example, you may want to start from the main body of the program. Also, you may want to use the caller and callee lists to help determine the processing order of the function definitions. You need to wait till all data type assignments for the arguments of a function to be fully determined (no way to change further) before proceeding to process the function (but watch out for recursive calls). This design is very important and should be discussed in your design document. In our FP program, it is possible that a function is a parameter for another function call. For example, assume that in the function definition for f1 we have: { Function f1 x y { } { f2 { f3 a b } c } { } return }. In functional languages, functions are considered as the first class objects and can be used just as any other objects. In procedural languages, this can be considered as passing a value that is evaluated in advance before the invocation. Here, we will consider the semantics of the case in the pure procedural language view. In other words, { f2 { f3 a b } c } can be viewed as: { = t1 { f3 a b } } { f2 t1 c }, where t1 is a temporary variable, not exactly existing. Thus, f2 and f3 do not have caller-callee relationship. They are callees of f1 and f1 is a caller for both. During type assignment, you have to conceptually convert the function parameter to a separate assignment statement and process them according to your design. When you perform data type assignment for a function definition, print out a message stating the function you start to work on in the beginning of the process and print out another message stating the function you have finished the data type assignments after the function definition is done. If a function definition is processed more than once, then print the message each time it is processed. If for an identifier, a new data type assignment is done or the existing data type assignment is changed, then print out the symbol table entry after the assignment. Please reference the output section regarding how to print out a symbol table entry.

8 If a function gets called several times in the program and the corresponding argument types are inconsistent, then you need to report errors (note that subtype and supertype are consistent). If there exist functions in the program that were never called, then you are required to prune the parse tree by removing the function definition subtrees for the unused functions from the parse tree of the program. After removing a subtree of a function definition, you need to print out a message to the standard output stating which function definitions have been removed. 3.3 Output At the end (best is in the main program), after all processings, you need to print out two things: the symbol table and the parse tree. The parse tree should be printed to a file named parsetree.out. The nodes of the parse tree should be printed in the in-fix order with indentations. Each node of the tree should be printed on one line. For each node, you need to print the node label as well as its value (for an identifier, you should only print the index to the symbol table). After you print a tree node, its child nodes should be printed following it with indentation and the indentation should be 2 blank spaces from the parent starting column. Note that your final parse tree should not include the function definitions that were removed (because the functions are unused). Your symbol table should be printed to a file named symboltable.out. For each entry, first print the index of the entry, the identifier name, and the data type if applicable (not for function-name or program-name), in one line. In case the identifier is a function-name, then in the next two lines print its callee and caller lists, with indentation. In case the identifier is a program-name, then in the next line print its callee list, with indentation. Otherwise, print the list of identifier usage types in the next line with indentation. When you print an entry in the symbol table during parsing or during processing, print to the standard output, not to the file symboltable.out. The printing format should be the same as stated above. When you print error messages, please separate the lines with two marking lines: ========== ERROR!!! (you can put equal signs) and print out the error message in between the two marking lines. This is to let the tester (most likely our TA) and yourself to see the error messages distinctively. 3.4 Submission The standard platform for this project is the university Sun systems, including the servers and workstations such as apache. You should make sure that your program runs on these platforms. You can use the sample program provided by TA to test your parser. But you definitely need to create other programs to test your parser. Note that it is your responsibility to thoroughly test your program. You need to electronically submit your program before midnight of the due date (check the web page for due dates). Follow the instruction below for submission. Login to one of the university Sun platforms. Go to the directory that only contains: The lex definition file for FP language. The file name should be FP.l. The yacc definition file for FP language. The file name should be FP.y. Any other files that contains code being used in FP.y.

9 A makefile if you code contains more than FP.l and FP.y. The Design.doc file that contains the description of some special features of your project that is not already specified in the project specification, including all problems your program may have, how you handled some problems listed in the handout, and/or all additional features you implemented. Issue the command ~ilyen/handin/handin.compiler. This command has to be issued in the directory that contains the files listed above. After submitting your project, do not delete or modify your code. Just in case something is wrong, you will have a chance to resubmit your program files with the original dates on them. You are responsible for generating your own testing programs and test your project thoroughly. We will use a different set of FP programs for testing. You need to consider the incorrect cases carefully as well. If your program does not fully function, please try to have partial results printed clearly to obtain partial credits. If your program does not work or it does not provide any output, then there will be no partial credits given. If your program does work fully or partially but we cannot make it run properly, then it is your responsibility to make an appointment with TA and come to the TA office to demonstrate your program. According to the problems, appropriate point deductions will apply in these situations. 4 Third Phase -- Code Generation For the third project, you will generate the pseudo machine code (PMC) for the input FP program. Before code generation, some simple code optimization will be performed. The code generation and optimization procedures are performed on the parse tree obtained in Project PMC Definition The definition for the pseudo machine code PMC is as follows. <program> ::= <declarations> <statements> <declarations> ::= <dclr> <declarations> <dclr> <dclr> ::= <type> <identifier> ; <type> ::= integer float string Boolean label <statements> ::= <stmt> <statements> <stmt> <stmt> ::= <label> <instruction> ; <instruction> ; <instruction> ::= <add-instruction> <sub-instruction>... (as shown in the following) <add-instruction> ::= add <op-dest> <math-param> <math-param> <sub-instruction> ::= sub <op-dest> <math-param> <math-param> <mul-instruction> ::= mul <op-dest> <math-param> <math-param> <div-instruction> ::= div <op-dest> <math-param> <math-param> <mod-instruction> ::= mod <op-dest> <math-param> <math-param> <init-instruction> ::= init <identifier> <all-param> <and-instruction> ::= and <op-dest> <bool-param> <bool-param> <or-instruction> ::= or <op-dest> <bool-param> <bool-param>

10 <test-instruction> ::= <comparison-operator> <op-dest> <math-param> <math-param> <if-instruction> ::= if <register> <label> <goto-instruction> ::= goto <label> <fgoto-instruction> ::= fgoto <identifier> <read-instruction> ::= read <identifier>+ <print-instruction> ::= print <all-parameter>+ <op-dest> ::= <identifier> <register> <constant> ::= <integer> <float> <string> <Boolean> <math-param> ::= <identifier> <register> <integer> <float> <bool-param> ::= <identifier> <register> <Boolean> <all-param> ::= <identifier> <constant> Here are the semantic definitions of the instructions. <add-instruction> computes the first <math-param> + the second <math-param> and stores the result to the <identifier> or <register>. <sub-instruction>, <mul-instruction>, <div-instruction>, and <mod-instruction> are the same as the <add-instruction> but are for, *, /, and % operators, respectively. <init-instruction>: initializes the identifier to the constant or another identifier. <and-instruction> and <or-instruction> compute the first <bool-param> and/or the second <bool-param> and stores the result to <identifier> or <register>. <test-instruction> tests whether the first <math-param> is = or > or >= the second <math-param>. If true then the result is 1; otherwise, the result is 0. The result is store in an <identifier> or a <register> <if-instruction> tests if <register> content is positive (true). If so, then the program flow should go to the instruction labeled by <label>. If not, then it continues to the next instruction. <goto-instruction> simply causes the program flow to go to the instruction labeled by <label>. <fgoto-instruction> is the flexible goto instruction. It causes the program flow to go to the instruction labeled by the content of the <identifier>. The content of the <identifier> has to be a positive integer within the range of the labels in the program. <read-instruction> reads from the standard input into one or more identifiers. It can read multiple inputs for multiple variables. <print-instruction> prints the parameters following it. The syntax and semantics of some of the tokens in PMC are defined as follows. <label> = L[1-9][0-9]*. A few example labels are: L1, L30, etc. The number parts of the labels in PMC have to be consecutive. For example, if the program has labels L5 and L7, then L6 has to also be in the program. <register> = R[0-9] <type> can be integer, float, Boolean, and string. <identifier>, <integer>, <float>, <string>, and <Boolean> are the same as those in FP. But here we have to change FP s <identifier> so that they will not start with R or L. Temporary identifiers generated by the code generator have to be declared also. You will need to add temporary variables to the symbol table because they may be referenced later.

11 4.2 Optimization on Parse Tree Before code generation, you are to perform code optimizations based on the parse tree. We consider two optimization goals: constant propagation and dead code elimination. You only need to perform optimization for the main body of the program, not for the function definitions. Since you are working on the parse tree, you sort of already have a control flow graph. For constant propagation, you need to identify the constant definition statements. A statement that assigns a constant to an identifier is a constant definition statement. If the parameter of an assignment statement includes a pre-defined function (+,, *, /, %) with constant parameters, then you should evaluate the pre-defined function statement and replace the function-parameter by the constantparameter (the evaluation result). This can be done recursively till a constant is derived as the parameter for the assignment statement or till it is not possible to evaluate further. When you encounter function calls, you consider it the same as a variable. Once a variable is defined as a constant, you need to propagate the definition till the variable is no longer a constant or till the end of the program. The goal for constant propagation is to replace a constant variable by the constant. You may want to do so during analysis and do it on the parse tree, instead of waiting till the end of analysis and come back to find out again where such replacement should take place. For dead code elimination, you are supposed to start from the end of the program and derive back the liveliness set. After the analysis, from the liveliness set after an assignment statement you can decide whether the statement can be removed. If so, then remove the statement from the parse tree. In fact, you can identify the dead code and remove it during analysis, instead of waiting till the end. You need to clearly show the steps you take in optimization. When you construct the set of constant definition statements, you should print the set after each step. You need to do the same for liveliness set. When you perform an optimization action, including when a variable is changed to a constant and/or a dead code is eliminated, you need to print out what optimization you are doing. 4.3 Code Generation After optimization, you need to generate PMC code for the input FP program. First, you need to go through the symbol table and generate the declaration statements for all the identifiers (not for the function names and the program name). Then you need to generate the PMC statements based on the parse tree. During code generation, you may create new temporary variables and labels. You need to put them also in the symbol table for references. You should assign types to temporary variables and you need to generate declaration statements for them. When generating code for a function call in FP, you need to generate the code to copy the values of the actual parameters to the formal parameters, record the return label index, and then jump to the function for execution. After execution of a function, you need to generate code to copy the return value to whatever variable in the caller and jump back to the recorded address. Since the return address is not a fixed label, you need to use fgoto and provide the identifier that stores the return label index to the fgoto instruction. We assume that the parameter passing mechanism used in FP is pass-by-value. Also, to simplify function handling, we assume that there will be no recursive calls in user-defined FP functions (pre-defined functions can be recursive).

12 The input FC program should be read from a file and the output PMC program should be stored in a file. Do not use hard coded file names, but pass the input and output file names as the program arguments. A PMC executor will be provided so that you can execute the PMC code you generated from your FP program. TA s web page will post the executable of the PMC executor and how to integrate with your code. 4.4 Submission You need to electronically submit your program before midnight of the due date (check the web page for due dates). Follow the instruction below for submission. Login to one of the university Sun platforms. Go to the directory that only contains: The lex definition file for the FP language. The file name should be FP.lex. The yacc definition file for the FP language. The file name should be FP.yacc. Other files that implement the code generation system. A makefile for invoking lex, then invoking yacc, then compiling your program with the code generated by lex and yacc. The sample program(s) written in the FP language. A readme file that explains how to compile and run your program and how to interpret your output. Also, if you have some information that you would like the TA to know, you can also put it in this file. The Design.doc file that contains the description of some special features of your project that is not specified in the project specification, including all problems your program may have and/or all additional features you implemented. Issue the command ~ilyen/handin/handin.compiler. This command has to be issued in the directory that contains the files listed above. After submitting your project, do not delete or modify your code. Just in case something is wrong, you will have a chance to resubmit your program files with the original dates on them. You are responsible for generating your own testing programs and test your project thoroughly. We will use a different set of FP programs for testing. You need to consider the incorrect cases carefully as well. If your program does not fully function, please try to have partial results printed clearly to obtain partial credits. If your program does not work or it does not provide any output, then there will be no partial credits given. If your program does work fully or partially but we cannot make it run properly, then it is your responsibility to make an appointment with TA and come to the TA office to demonstrate your program. According to the problems, appropriate point deductions will apply in these situations.

CS 6353 Compiler Construction Project Assignments

CS 6353 Compiler Construction Project Assignments CS 6353 Compiler Construction Project Assignments In this project, you need to implement a compiler for a language defined in this handout. The programming language you need to use is C or C++ (and the

More information

1 Lexical Considerations

1 Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2013 Handout Decaf Language Thursday, Feb 7 The project for the course is to write a compiler

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2005 Handout 6 Decaf Language Wednesday, September 7 The project for the course is to write a

More information

The PCAT Programming Language Reference Manual

The PCAT Programming Language Reference Manual The PCAT Programming Language Reference Manual Andrew Tolmach and Jingke Li Dept. of Computer Science Portland State University September 27, 1995 (revised October 15, 2002) 1 Introduction The PCAT language

More information

Lexical Considerations

Lexical Considerations Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Spring 2010 Handout Decaf Language Tuesday, Feb 2 The project for the course is to write a compiler

More information

Midterm II CS164, Spring 2006

Midterm II CS164, Spring 2006 Midterm II CS164, Spring 2006 April 11, 2006 Please read all instructions (including these) carefully. Write your name, login, SID, and circle the section time. There are 10 pages in this exam and 4 questions,

More information

CS 2210 Programming Project (Part IV)

CS 2210 Programming Project (Part IV) CS 2210 Programming Project (Part IV) April 25, 2018 Code Generation This project is intended to give you experience in writing a code generator as well as bring together the various issues of code generation

More information

Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm

Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm 1 Overview Programming assignments I IV will direct you to design and build a compiler for Cool. Each assignment will cover one component

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction David Sinclair When procedure A calls procedure B, we name procedure A the caller and procedure B the callee. A Runtime Environment, also called an Activation Record, is

More information

Project 1: Scheme Pretty-Printer

Project 1: Scheme Pretty-Printer Project 1: Scheme Pretty-Printer CSC 4101, Fall 2017 Due: 7 October 2017 For this programming assignment, you will implement a pretty-printer for a subset of Scheme in either C++ or Java. The code should

More information

Time : 1 Hour Max Marks : 30

Time : 1 Hour Max Marks : 30 Total No. of Questions : 6 P4890 B.E/ Insem.- 74 B.E ( Computer Engg) PRINCIPLES OF MODERN COMPILER DESIGN (2012 Pattern) (Semester I) Time : 1 Hour Max Marks : 30 Q.1 a) Explain need of symbol table with

More information

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Compiler Theory. (Semantic Analysis and Run-Time Environments) Compiler Theory (Semantic Analysis and Run-Time Environments) 005 Semantic Actions A compiler must do more than recognise whether a sentence belongs to the language of a grammar it must do something useful

More information

Project Compiler. CS031 TA Help Session November 28, 2011

Project Compiler. CS031 TA Help Session November 28, 2011 Project Compiler CS031 TA Help Session November 28, 2011 Motivation Generally, it s easier to program in higher-level languages than in assembly. Our goal is to automate the conversion from a higher-level

More information

Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm

Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm 1 Overview of the Programming Project Programming assignments I IV will direct you to design and build a compiler for Cool. Each assignment

More information

Language Reference Manual simplicity

Language Reference Manual simplicity Language Reference Manual simplicity Course: COMS S4115 Professor: Dr. Stephen Edwards TA: Graham Gobieski Date: July 20, 2016 Group members Rui Gu rg2970 Adam Hadar anh2130 Zachary Moffitt znm2104 Suzanna

More information

CS 415 Midterm Exam Spring 2002

CS 415 Midterm Exam Spring 2002 CS 415 Midterm Exam Spring 2002 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Good Luck! Score Fortran Algol 60 Compilation Names, Bindings, Scope Functional Programming

More information

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find

CS1622. Semantic Analysis. The Compiler So Far. Lecture 15 Semantic Analysis. How to build symbol tables How to use them to find CS1622 Lecture 15 Semantic Analysis CS 1622 Lecture 15 1 Semantic Analysis How to build symbol tables How to use them to find multiply-declared and undeclared variables. How to perform type checking CS

More information

Decaf Language Reference Manual

Decaf Language Reference Manual Decaf Language Reference Manual C. R. Ramakrishnan Department of Computer Science SUNY at Stony Brook Stony Brook, NY 11794-4400 cram@cs.stonybrook.edu February 12, 2012 Decaf is a small object oriented

More information

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square) Introduction This semester, through a project split into 3 phases, we are going

More information

Decaf Language Reference

Decaf Language Reference Decaf Language Reference Mike Lam, James Madison University Fall 2016 1 Introduction Decaf is an imperative language similar to Java or C, but is greatly simplified compared to those languages. It will

More information

CS 415 Midterm Exam Spring SOLUTION

CS 415 Midterm Exam Spring SOLUTION CS 415 Midterm Exam Spring 2005 - SOLUTION Name Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you

More information

Compilers Project 3: Semantic Analyzer

Compilers Project 3: Semantic Analyzer Compilers Project 3: Semantic Analyzer CSE 40243 Due April 11, 2006 Updated March 14, 2006 Overview Your compiler is halfway done. It now can both recognize individual elements of the language (scan) and

More information

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100 GATE- 2016-17 Postal Correspondence 1 Compiler Design Computer Science & Information Technology (CS) 20 Rank under AIR 100 Postal Correspondence Examination Oriented Theory, Practice Set Key concepts,

More information

Languages and Compilers

Languages and Compilers Principles of Software Engineering and Operational Systems Languages and Compilers SDAGE: Level I 2012-13 4. Lexical Analysis (Scanning) Dr Valery Adzhiev vadzhiev@bournemouth.ac.uk Office: TA-121 For

More information

CS 541 Spring Programming Assignment 2 CSX Scanner

CS 541 Spring Programming Assignment 2 CSX Scanner CS 541 Spring 2017 Programming Assignment 2 CSX Scanner Your next project step is to write a scanner module for the programming language CSX (Computer Science experimental). Use the JFlex scanner-generation

More information

Intermediate Code Generation

Intermediate Code Generation Intermediate Code Generation In the analysis-synthesis model of a compiler, the front end analyzes a source program and creates an intermediate representation, from which the back end generates target

More information

Semantic actions for declarations and expressions

Semantic actions for declarations and expressions Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

1. Consider the following program in a PCAT-like language.

1. Consider the following program in a PCAT-like language. CS4XX INTRODUCTION TO COMPILER THEORY MIDTERM EXAM QUESTIONS (Each question carries 20 Points) Total points: 100 1. Consider the following program in a PCAT-like language. PROCEDURE main; TYPE t = FLOAT;

More information

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou

COMP-421 Compiler Design. Presented by Dr Ioanna Dionysiou COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou Administrative! Any questions about the syllabus?! Course Material available at www.cs.unic.ac.cy/ioanna! Next time reading assignment [ALSU07]

More information

COP4020 Programming Assignment 1 CALC Interpreter/Translator Due March 4, 2015

COP4020 Programming Assignment 1 CALC Interpreter/Translator Due March 4, 2015 COP4020 Programming Assignment 1 CALC Interpreter/Translator Due March 4, 2015 Purpose This project is intended to give you experience in using a scanner generator (Lex), a parser generator (YACC), writing

More information

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore

Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Principle of Complier Design Prof. Y. N. Srikant Department of Computer Science and Automation Indian Institute of Science, Bangalore Lecture - 20 Intermediate code generation Part-4 Run-time environments

More information

Semantic actions for declarations and expressions. Monday, September 28, 15

Semantic actions for declarations and expressions. Monday, September 28, 15 Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

Semantic actions for expressions

Semantic actions for expressions Semantic actions for expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate representations

More information

Types and Static Type Checking (Introducing Micro-Haskell)

Types and Static Type Checking (Introducing Micro-Haskell) Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 13 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 16 October, 2012 1 / 21 1 Types 2 3 4 2 / 21 Thus far

More information

Types and Static Type Checking (Introducing Micro-Haskell)

Types and Static Type Checking (Introducing Micro-Haskell) Types and Static (Introducing Micro-Haskell) Informatics 2A: Lecture 14 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 17 October 2017 1 / 21 1 Types 2 3 4 2 / 21 So far in

More information

MP 3 A Lexer for MiniJava

MP 3 A Lexer for MiniJava MP 3 A Lexer for MiniJava CS 421 Spring 2010 Revision 1.0 Assigned Tuesday, February 2, 2010 Due Monday, February 8, at 10:00pm Extension 48 hours (20% penalty) Total points 50 (+5 extra credit) 1 Change

More information

Semantics of programming languages

Semantics of programming languages Semantics of programming languages Informatics 2A: Lecture 27 John Longley School of Informatics University of Edinburgh jrl@inf.ed.ac.uk 21 November, 2011 1 / 19 1 2 3 4 2 / 19 Semantics for programming

More information

Programming Assignment II

Programming Assignment II Programming Assignment II 1 Overview of the Programming Project Programming assignments II V will direct you to design and build a compiler for Cool. Each assignment will cover one component of the compiler:

More information

CS 231 Data Structures and Algorithms, Fall 2016

CS 231 Data Structures and Algorithms, Fall 2016 CS 231 Data Structures and Algorithms, Fall 2016 Dr. Bruce A. Maxwell Department of Computer Science Colby College Course Description Focuses on the common structures used to store data and the standard

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2009 P. N. Hilfinger CS 164: Final Examination (corrected) Name: Login: You have

More information

Full file at

Full file at Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

More information

COMP 202 Java in one week

COMP 202 Java in one week COMP 202 Java in one week... Continued CONTENTS: Return to material from previous lecture At-home programming exercises Please Do Ask Questions It's perfectly normal not to understand everything Most of

More information

COMPILERS BASIC COMPILER FUNCTIONS

COMPILERS BASIC COMPILER FUNCTIONS COMPILERS BASIC COMPILER FUNCTIONS A compiler accepts a program written in a high level language as input and produces its machine language equivalent as output. For the purpose of compiler construction,

More information

1 The Var Shell (vsh)

1 The Var Shell (vsh) CS 470G Project 1 The Var Shell Due Date: February 7, 2011 In this assignment, you will write a shell that allows the user to interactively execute Unix programs. Your shell, called the Var Shell (vsh),

More information

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017 CS 426 Fall 2017 1 Machine Problem 1 Machine Problem 1 CS 426 Compiler Construction Fall Semester 2017 Handed Out: September 6, 2017. Due: September 21, 2017, 5:00 p.m. The machine problems for this semester

More information

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis Handout written by Julie Zelenski with edits by Keith Schwarz. The Goal In the first programming project, you will get

More information

Semantic actions for declarations and expressions

Semantic actions for declarations and expressions Semantic actions for declarations and expressions Semantic actions Semantic actions are routines called as productions (or parts of productions) are recognized Actions work together to build up intermediate

More information

Syntax-Directed Translation

Syntax-Directed Translation Syntax-Directed Translation ALSU Textbook Chapter 5.1 5.4, 4.8, 4.9 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 What is syntax-directed translation? Definition: The compilation

More information

Implementing a VSOP Compiler. March 20, 2018

Implementing a VSOP Compiler. March 20, 2018 Implementing a VSOP Compiler Cyril SOLDANI, Pr. Pierre GEURTS March 20, 2018 Part III Semantic Analysis 1 Introduction In this assignment, you will do the semantic analysis of VSOP programs, according

More information

CS 211 Programming Practicum Fall 2018

CS 211 Programming Practicum Fall 2018 Due: Wednesday, 11/7/18 at 11:59 pm Infix Expression Evaluator Programming Project 5 For this lab, write a C++ program that will evaluate an infix expression. The algorithm REQUIRED for this program will

More information

Stating the obvious, people and computers do not speak the same language.

Stating the obvious, people and computers do not speak the same language. 3.4 SYSTEM SOFTWARE 3.4.3 TRANSLATION SOFTWARE INTRODUCTION Stating the obvious, people and computers do not speak the same language. People have to write programs in order to instruct a computer what

More information

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; } Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas

More information

IC Language Specification

IC Language Specification CS 301 Spring 2016 IC Language Specification The IC Language For the implementation project, you will build a compiler for an object-oriented language called IC (for Irish Coffee 1 ), which is essentially

More information

YOLOP Language Reference Manual

YOLOP Language Reference Manual YOLOP Language Reference Manual Sasha McIntosh, Jonathan Liu & Lisa Li sam2270, jl3516 and ll2768 1. Introduction YOLOP (Your Octothorpean Language for Optical Processing) is an image manipulation language

More information

Project 3 Due October 21, 2015, 11:59:59pm

Project 3 Due October 21, 2015, 11:59:59pm Project 3 Due October 21, 2015, 11:59:59pm 1 Introduction In this project, you will implement RubeVM, a virtual machine for a simple bytecode language. Later in the semester, you will compile Rube (a simplified

More information

Project 2 Interpreter for Snail. 2 The Snail Programming Language

Project 2 Interpreter for Snail. 2 The Snail Programming Language CSCI 2400 Models of Computation Project 2 Interpreter for Snail 1 Overview In this assignment you will use the parser generator yacc to construct an interpreter for a language called Snail containing the

More information

CSCI312 Principles of Programming Languages!

CSCI312 Principles of Programming Languages! CSCI312 Principles of Programming Languages!! Chapter 3 Regular Expression and Lexer Xu Liu Recap! Copyright 2006 The McGraw-Hill Companies, Inc. Clite: Lexical Syntax! Input: a stream of characters from

More information

// the current object. functioninvocation expression. identifier (expressionlist ) // call of an inner function

// the current object. functioninvocation expression. identifier (expressionlist ) // call of an inner function SFU CMPT 379 Compilers Spring 2015 Assignment 4 Assignment due Thursday, April 9, by 11:59pm. For this assignment, you are to expand your Bunting-3 compiler from assignment 3 to handle Bunting-4. Project

More information

Examination in Compilers, EDAN65

Examination in Compilers, EDAN65 Examination in Compilers, EDAN65 Department of Computer Science, Lund University 2016 10 28, 08.00-13.00 Note! Your exam will be marked only if you have completed all six programming lab assignments in

More information

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4

Jim Lambers ENERGY 211 / CME 211 Autumn Quarter Programming Project 4 Jim Lambers ENERGY 211 / CME 211 Autumn Quarter 2008-09 Programming Project 4 This project is due at 11:59pm on Friday, October 31. 1 Introduction In this project, you will do the following: 1. Implement

More information

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation

CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation CS164: Programming Assignment 5 Decaf Semantic Analysis and Code Generation Assigned: Sunday, November 14, 2004 Due: Thursday, Dec 9, 2004, at 11:59pm No solution will be accepted after Sunday, Dec 12,

More information

The SPL Programming Language Reference Manual

The SPL Programming Language Reference Manual The SPL Programming Language Reference Manual Leonidas Fegaras University of Texas at Arlington Arlington, TX 76019 fegaras@cse.uta.edu February 27, 2018 1 Introduction The SPL language is a Small Programming

More information

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres

Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres Computer Science Department Carlos III University of Madrid Leganés (Spain) David Griol Barres dgriol@inf.uc3m.es Introduction He am a driver might be syntactically correct but semantically wrong. Semantic

More information

Compilers. Compiler Construction Tutorial The Front-end

Compilers. Compiler Construction Tutorial The Front-end Compilers Compiler Construction Tutorial The Front-end Salahaddin University College of Engineering Software Engineering Department 2011-2012 Amanj Sherwany http://www.amanj.me/wiki/doku.php?id=teaching:su:compilers

More information

CS /534 Compiler Construction University of Massachusetts Lowell

CS /534 Compiler Construction University of Massachusetts Lowell CS 91.406/534 Compiler Construction University of Massachusetts Lowell Professor Li Xu Fall 2004 Lab Project 2: Parser and Type Checker for NOTHING Due: Sunday, November 14, 2004, 11:59 PM 1 Introduction

More information

Parser Design. Neil Mitchell. June 25, 2004

Parser Design. Neil Mitchell. June 25, 2004 Parser Design Neil Mitchell June 25, 2004 1 Introduction A parser is a tool used to split a text stream, typically in some human readable form, into a representation suitable for understanding by a computer.

More information

Part 5 Program Analysis Principles and Techniques

Part 5 Program Analysis Principles and Techniques 1 Part 5 Program Analysis Principles and Techniques Front end 2 source code scanner tokens parser il errors Responsibilities: Recognize legal programs Report errors Produce il Preliminary storage map Shape

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler Front-End Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

A Simple Syntax-Directed Translator

A Simple Syntax-Directed Translator Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called

More information

The role of semantic analysis in a compiler

The role of semantic analysis in a compiler Semantic Analysis Outline The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Static analyses that detect type errors

More information

CSE 340 Fall 2014 Project 4

CSE 340 Fall 2014 Project 4 CSE 340 Fall 2014 Project 4 Due on Dec. 5, 2014 by 11:59 pm Abstract The goal of this project is to give you some hands-on experience with implementing a compiler. You will write a compiler for a simple

More information

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; }

for (i=1; i<=100000; i++) { x = sqrt (y); // square root function cout << x+i << endl; } Ex: The difference between Compiler and Interpreter The interpreter actually carries out the computations specified in the source program. In other words, the output of a compiler is a program, whereas

More information

Programming Assignment IV

Programming Assignment IV Programming Assignment IV 1 Introduction In this assignment, you will implement the static semantics of Cool. You will use the abstract syntax trees (AST) built by the parser to check that a program conforms

More information

LECTURE 3. Compiler Phases

LECTURE 3. Compiler Phases LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent

More information

Formal Languages and Compilers Lecture VI: Lexical Analysis

Formal Languages and Compilers Lecture VI: Lexical Analysis Formal Languages and Compilers Lecture VI: Lexical Analysis Free University of Bozen-Bolzano Faculty of Computer Science POS Building, Room: 2.03 artale@inf.unibz.it http://www.inf.unibz.it/ artale/ Formal

More information

Pace University. Fundamental Concepts of CS121 1

Pace University. Fundamental Concepts of CS121 1 Pace University Fundamental Concepts of CS121 1 Dr. Lixin Tao http://csis.pace.edu/~lixin Computer Science Department Pace University October 12, 2005 This document complements my tutorial Introduction

More information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4020 July 5, 2007 14.00-15.30 This exam (8 pages) consists of 60 True/False

More information

Implementing a VSOP Compiler. March 12, 2018

Implementing a VSOP Compiler. March 12, 2018 Implementing a VSOP Compiler Cyril SOLDANI, Pr. Pierre GEURTS March 12, 2018 Part II Syntax Analysis 1 Introduction In this assignment, you will implement a parser for the VSOP language, according to the

More information

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University

Lecture 7: Type Systems and Symbol Tables. CS 540 George Mason University Lecture 7: Type Systems and Symbol Tables CS 540 George Mason University Static Analysis Compilers examine code to find semantic problems. Easy: undeclared variables, tag matching Difficult: preventing

More information

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1

Static Semantics. Lecture 15. (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1 Static Semantics Lecture 15 (Notes by P. N. Hilfinger and R. Bodik) 2/29/08 Prof. Hilfinger, CS164 Lecture 15 1 Current Status Lexical analysis Produces tokens Detects & eliminates illegal tokens Parsing

More information

CS 415 Midterm Exam Fall 2003

CS 415 Midterm Exam Fall 2003 CS 415 Midterm Exam Fall 2003 Name KEY Email Address Student ID # Pledge: This exam is closed note, closed book. Questions will be graded on quality of answer. Please supply the best answer you can to

More information

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002

University of Arizona, Department of Computer Science. CSc 453 Assignment 5 Due 23:59, Dec points. Christian Collberg November 19, 2002 University of Arizona, Department of Computer Science CSc 453 Assignment 5 Due 23:59, Dec 4 100 points Christian Collberg November 19, 2002 1 Introduction Your task is to write a code generator for the

More information

Important Project Dates

Important Project Dates Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science 6.035, Fall 2002 Handout 4 Project Overview Wednesday, September 4 This is an overview of the course project

More information

CS4215 Programming Language Implementation

CS4215 Programming Language Implementation CS4215 Programming Language Implementation You have 45 minutes to complete the exam. Use a B2 pencil to fill up the provided MCQ form. Leave Section A blank. Fill up Sections B and C. After finishing,

More information

CSc 520 final exam Wednesday 13 December 2000 TIME = 2 hours

CSc 520 final exam Wednesday 13 December 2000 TIME = 2 hours NAME s GRADE Prob 1 2 3 4 5 I II III Σ Max 12 12 12 12 12 26 26 26 100(+... ) Score CSc 520 exam Wednesday 13 December 2000 TIME = 2 hours Write all answers ON THIS EXAMINATION, and submit it IN THE ENVELOPE

More information

CS 1044 Program 6 Summer I dimension ??????

CS 1044 Program 6 Summer I dimension ?????? Managing a simple array: Validating Array Indices Most interesting programs deal with considerable amounts of data, and must store much, or all, of that data on one time. The simplest effective means for

More information

Chapter 4 Defining Classes I

Chapter 4 Defining Classes I Chapter 4 Defining Classes I This chapter introduces the idea that students can create their own classes and therefore their own objects. Introduced is the idea of methods and instance variables as the

More information

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators

Objectives. Chapter 4: Control Structures I (Selection) Objectives (cont d.) Control Structures. Control Structures (cont d.) Relational Operators Objectives Chapter 4: Control Structures I (Selection) In this chapter, you will: Learn about control structures Examine relational and logical operators Explore how to form and evaluate logical (Boolean)

More information

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements

Programming Languages Third Edition. Chapter 9 Control I Expressions and Statements Programming Languages Third Edition Chapter 9 Control I Expressions and Statements Objectives Understand expressions Understand conditional statements and guards Understand loops and variation on WHILE

More information

Yacc: A Syntactic Analysers Generator

Yacc: A Syntactic Analysers Generator Yacc: A Syntactic Analysers Generator Compiler-Construction Tools The compiler writer uses specialised tools (in addition to those normally used for software development) that produce components that can

More information

Section 2: Introduction to Java. Historical note

Section 2: Introduction to Java. Historical note The only way to learn a new programming language is by writing programs in it. - B. Kernighan & D. Ritchie Section 2: Introduction to Java Objectives: Data Types Characters and Strings Operators and Precedence

More information

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division CS 164 Spring 2010 P. N. Hilfinger CS 164: Final Examination (revised) Name: Login: You have

More information

Summary: Direct Code Generation

Summary: Direct Code Generation Summary: Direct Code Generation 1 Direct Code Generation Code generation involves the generation of the target representation (object code) from the annotated parse tree (or Abstract Syntactic Tree, AST)

More information

ML 4 A Lexer for OCaml s Type System

ML 4 A Lexer for OCaml s Type System ML 4 A Lexer for OCaml s Type System CS 421 Fall 2017 Revision 1.0 Assigned October 26, 2017 Due November 2, 2017 Extension November 4, 2017 1 Change Log 1.0 Initial Release. 2 Overview To complete this

More information

Writing a Lexer. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, Glenn G.

Writing a Lexer. CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, Glenn G. Writing a Lexer CS F331 Programming Languages CSCE A331 Programming Language Concepts Lecture Slides Monday, February 6, 2017 Glenn G. Chappell Department of Computer Science University of Alaska Fairbanks

More information

Programming Assignment III

Programming Assignment III Programming Assignment III First Due Date: (Grammar) See online schedule (submission dated midnight). Second Due Date: (Complete) See online schedule (submission dated midnight). Purpose: This project

More information

Do not write in this area EC TOTAL. Maximum possible points:

Do not write in this area EC TOTAL. Maximum possible points: Name: Student ID: Lab Instructor: Borja Sotomayor Do not write in this area 1 2 3 4 EC TOTAL Maximum possible points: 40 + 5 One of the exercises in this lab has to be done in a group of 4. In particular,

More information

The Decaf Language. 1 Lexical considerations

The Decaf Language. 1 Lexical considerations The Decaf Language In this course, we will write a compiler for a simple object-oriented programming language called Decaf. Decaf is a strongly-typed, object-oriented language with support for inheritance

More information

CS 314 Principles of Programming Languages Fall 2017 A Compiler and Optimizer for tinyl Due date: Monday, October 23, 11:59pm

CS 314 Principles of Programming Languages Fall 2017 A Compiler and Optimizer for tinyl Due date: Monday, October 23, 11:59pm CS 314 Principles of Programming Languages Fall 2017 A Compiler and Optimizer for tinyl Due date: Monday, October 23, 11:59pm THIS IS NOT A GROUP PROJECT! You may talk about the project and possible solutions

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Statically vs. Dynamically typed languages

More information