Sticker. CS 241 Fall 2009 Final Exam. Draft of 6 December 01:43 hrs

Size: px
Start display at page:

Download "Sticker. CS 241 Fall 2009 Final Exam. Draft of 6 December 01:43 hrs"

Transcription

1 Date: Weds, 16 December 2009 Time: 16:00-18:30 hours Permitted Aids: Provided reference booklet only. Closed book. CS 241 Fall 2009 Final Exam Cheating is an academic offense. Your signature below indicates that you understand you are bound by the University s policies regarding cheating on exams; unsigned exams will not be marked. Sticker Draft of 6 December 01:43 hrs Signature: Instructors: John Beatty, Gord Cormack, Troy Vasiga Instructions read carefully before the exam begins. E 1. This is a closed book examination. No aids are permitted other than the reference booklet provided. 2. Place answers in this booklet. Use the back of the previous page if additional space is required, and indicate clearly when an answer continues there to ensure your entire answer is marked. 3. Before you begin, make certain that you have 17 pages in this booklet and the 6-page reference booklet containing the MIPS reference sheet, the WL grammar and WLPP language specification. 4. Do not attempt to deduce anything about the content of an answer from the number of marks available for it. (Spreadsheets are good at arithmetic.) 5. To ensure that no student is unfairly disadvantaged, questions will not be interpreted or explained. Proctors may only confirm or deny the presence of an error. If you consider the wording of a question to be ambiguous, state your assumption(s) clearly, then answer the question to the best of your ability. Q# Marks Available 1 4 Scanning 2 11 CompPhases 3 7 WLPP 4 5 Trees&Der 5 6 guarded 6 14 CodeGen 7 5 LL-Predict 8 6 LL(1) 9 8 SLR(1) HeapMgmt Total 80 Marks Earned Marker s Initials page 2 page 3 page 4 page 6 page 7 page 8 page 11 page 12 page 13 page 15

2 Question 1: [4 marks] Suppose that the DFA shown to the right defines the valid tokens for some mythical language. Part a) Assume that the simplified maximal munch algorithm is executed using this DFA on the two input strings listed below. List the names of the tokens returned (which correspond to the relevant state names), in the order returned; if no ID a-z token can be returned at some point, write the pseudo-token name ERROR and assume that the lexical analyzer exits immediately thereafter. 0-9 a-z INT S * PLUS + STAR MINUS AINC ADEC * SS * COM alpha* beta alpha01*****beta02 ID STAR MINUS ID ID INT COM ERROR Part b) The DFA shown to the right accepts strings comprising a valid MIPS assembly language token. Observe that this DFA has transitions for the space character only from the COMMENT state, and recognizes an end-of-line character '\n' as an instance of the token EOL. LPAREN REG In pseudocode, provide a detailed description DOLLAR RPAREN of how this DFA could be used as part of a COMMENT lexical scanner for MIPS assembly language DOT DOTW DOTWO DOTWOR programs that reads the characters in a source file, generating a stream of MIPS assembly language tokens in which successive assembly language statements are separated by an EOL token. Your lexical scanner should return a special EOF token (not present in the above DFA) after processing the entire input file and may exit immediately if an error is detected. You may assume that the last character of any input file is the end-of-line character '\n'. I'll refer below to the DFA as the machine M. 1 mark for Place M in its START state and feed it characters from the source file until it blocks (cannot read the next character of input). If M is in a non-accepting state, declare an error and quit. If M is in an accepting state, return the token corresponding to that state. 1 mark for Then throw away whitespace characters (space, tab, or end-of-line), if any, until you encounter (c) the end-of-file or (d) a non-whitespace character. If (c), you return the special EOF token. if (d), you set M to the START state and continue scanning characters from the source file as described above. It s fine if they say modify the DFA so it has a transition from START under all space and tab to a WHITESPACE token that has transitions under both whitespace characters to itself, and explain that, as a special case, you DON T return/output a WHITESPACE token but instead reset the DFA to START and continue scanning as described above. \n START EOL a-za-z ; 0 - ( ), w $ MINUS 1-9 ZERO COMMA ID a-za-z x 0-9 : INT ZEROX LABEL o r a-f 0-9 all but \n d HEXINT a-f DOTWORD CS 241 Fall 2009 Page 2 of 17

3 Question 2: [11 marks] Listed below are several kinds of errors typically encountered during compilation and/or linking. For each of them, indicate the phase of the compilation and linking process in which the error would most likely be reported. Your answer in each case should be one of the following: scanning parsing semantic analysis optimization code generation linking a) Illegal character " " encountered. scanning b) Missing semicolon. parsing c) Attempt to assign a pointer to an int. semantic analysis d) String literal missing an end quotation mark. scanning e) Numeric literal out of range. code generation (or scanning, or semantic analysis) f) Multiple definitions encountered for the external symbol "Camelot". linking g) Attempt to use the undeclared variable "foo". semantic analysis h) Unmatched right parenthesis encountered. parsing i) Fill in the blank to produce a program that violates the WL lexical syntax rules. int wain( int foo, int bar ) { return ; } j) Fill in the blank to produce a program that satisfies the WL lexical syntax rules but violates the WL context-free syntax rules. int wain( int foo, int bar ) { return ; } k) Fill in the blank to produce a program that satisfies the WL lexical syntax and context-free syntax rules but violates the WL context-sensitive syntax rules. int wain( int foo, int bar ) { return ; } CS 241 Fall 2009 Page 3 of 17

4 Question 3: [7 marks] On the next page, write a WLPP program that takes as input an integer n+1 and an array containing n+1 numbers. The first number in the array is k (you can assume 0 k n-1), followed by n elements which form array A. Your program should print the elements of array A in the following order: A[k] A[k+1] A[k+2]... A[n-1] A[0] A[1]... A[k-2] A[k-1] and should return the value k. That is, begin printing at index k, increasing the index, and eventually wrapping around the array and end by printing the value at index k-1. For example if the input is: the output should be: and the returned value should be: 2 Please write your answer on the next page. (You will find the WLPP Language Specification in the Reference Booklet.) CS 241 Fall 2009 Page 4 of 17

5 Write below your answer to the question on the preceding page. CS 241 Fall 2009 Page 5 of 17

6 Question 4: [5 marks] Consider the following context-free grammar G S X C S A Y X a X b X ε Y b Y c Y ε A a A A ε C c C C ε and the following derivation of a word in L(G). S AY AbYc AbbYcc AbbbYccc Abbbccc aabbbccc abbbccc Part a) Circle each of the following phrases that correctly describes the above derivation. leftmost rightmost neither leftmost nor rightmost both leftmost & rightmost Part b) Draw the parse tree corresponding to the above derivation. Part c) Give a leftmost derivation of the string abc. S L XC L axbc L abc L abcc L abc S L AY L aay L ay L abyc L abc 1 f or either leftmost derivation if done perfectly, else 0. It s OK if there s no subscript L on the arrows. Part d) Is this grammar ambiguous? Justify your answer briefly. Yes. There are two distinct derivation trees for any non-null string having an equal number of a s, b s & c s. EG 1 for Yes. 1 for the justification. Anything they say that conveys an understanding that a grammar is ambiguous iff it generates at least one string for which there are at least two distinct derivation trees or canonical derivations is sufficient. And they must produce example derivations or trees illustrating this. CS 241 Fall 2009 Page 6 of 17

7 Question 5: [6 marks] Suppose that we wish to add to the WL language generalized conditional statements like the following guarded case test { } case test { } case test { } default { } endguarded that may appear wherever any other WL statement may appear, and in which: each test is an instance of a WL test such as may appear in a WL if statement; there must be at least one case clause; there may be an arbitrarily large number of case clauses; { } represents a sequence of zero or more WL statements (exactly as may appear in the body of a WL loop); the default clause may be absent. What changes are needed to the WL grammar to implement this additional statement type? You may add new vocabulary and productions as needed, but may not change existing vocabulary and productions. Four additional terminals are needed: guarded, case, default and endguarded. [1] mark. [1] mark for adding a non-terminal with which to define a list of one or more cases, distinct from whether the rules are correct. They need not expiicitly say it's a new non-terminal, provided that it appears on the LHS of at least one production. They need not define the non-terminals I've named defaultclause, since these can be directly included and there's a mark for each of these listed below, which they should get regardless of how they (correctly) get cases and the default clause into the statement. The following additional rules are needed: statement GUARDED caselist defaultclause ENDGUARDED caselist casestmt caselist caselist casestmt casestmt case test LBRACE statements RBRACE defaultclause DEFAULT LBRACE statements RBRACE defaultclause ε [1] mark. [1] mark. May be either L- or R-recursive. Marking: it's OK if they add two alternatives for statement, one with a default stmt and one w/o. It's also OK if they include the [1] mark. [1] mark. CS 241 Fall 2009 Page 7 of 17

8 Question 6: [14 marks] You are to extend WL to include the ability to declare and call functions of one or two parameters that return an integer as part of a WL expression. If a program calls one or more functions, it will be linked with a library of available functions as the program is loaded for execution. To accomplish this extension, the terminal keyword function (represented by the token FUNCTION) and the productions Rule 1: dcl Rule 2: dcl FUNCTION INT ID LPAREN INT RPAREN FUNCTION INT ID LPAREN INT COMMA INT RPAREN Rule 3: factor ID LPAREN expr RPAREN Rule 4: factor ID LPAREN expr COMMA expr RPAREN are added to WL s grammar and the WL specification is modified to require that any function called must have appeared in exactly one function declaration, be called with the number of parameters appearing in its declaration, not have appeared in a variable declaration, and the first (left) parameter is evaluated before the second (right) when there are two parameters. You should use our standard MIPS parameter passing conventions: $1 contains the first parameter, $2 contains the second parameter (when there is a second parameter), and the function called will return its value in $3. You may assume that the following helper methods/functions already exist: exprcode( node ), which takes a node of the parse tree as a parameter and returns MIPS assembly language code that evaluates the expression represented by the subtree rooted at that node and places its value in register $3; pushregister( number ), which returns MIPS assembly language code that pushes the contents of the register specified as a parameter onto the stack and decrements the stack pointer appropriately; popregister( number ), which returns MIPS assembly language code that pops the topmost value off the stack into the register whose number is specified as a parameter. Part a) On the next page you are to write pseudo code for helper methods/functions oneparametercall( node ) and twoparametercall( node ) that take a node of the parse tree as a parameter and return MIPS assembly code appropriate for rules 3 and 4, respectively. You may assume that the node passed to oneparametercall(...) does, indeed, correspond to an instance in the parse tree of rule 3, and similarly for twoparametercall(...) you do not need to do any error-checking. Neither do you need to implement any of the other rules already present in the WL language. Please answer on the next page. (You will find the WL grammar in the Reference Booklet, should you wish to refer to it.) CS 241 Fall 2009 Page 8 of 17

9 (Space in which to answer part a of Question 6 on the preceding page.) oneparametercall( node ) { fcnname = lexeme( child 0 of node ) // factor ID LPAREN expr RPAREN [1] for obtaining the id (here or inline below) ans = exprcode( child 2 of node ) [1] for call & order. ans += " add $1, $0,$3" + "\n" [1] for moving the returned value to $1 ans += " lis $JR " + "\n" [1] for setup and call ans += ".word" + fcnname + "\n" ans += " jalr $JR " + "\n" ans += " jr $31 " + "\n" [1] for return return ans [1] for returning the accumulated assembly code. $JR can be any register except $1, $30, or $31. It's ok if they forget to surround things with quotes, and it's ok if they forget to append the "\n"s. Full credit in each case only if the same (or equivalent) code is present in the implementation of twoparameter(...), too, and full credit if one of the instances has a trivial error; otherwise 1/2 point. Mainly the intent is to give a 1/2 point for each of the above if they have no answerr whatsoever for twoparameter(...), and of course 0 if neither answer is present, with the expectation that if they get it right here, they ll get it right below, and to give additional credit below for things that aren t relevant here. That s 6 marks for oneparameter(...) (if the corresponding assembly is in twoparameter(...), too). } twoparametercall( node ) { // factor ID LPAREN expr COMMA expr RPAREN fcnname = lexeme( child 0 of node ) ans = exprcode( child 2 of node ) ans += " pushregister( $3 )" + "\n" ans = exprcode( child 4 of node ) ans += " popregister( $1 ) " + "\n" ans += " add $2, $0,$3" + "\n" ans += " lis $JR " + "\n" ans += ".word" + fcnname + "\n" ans += " jalr $JR " + "\n" ans += " jr $31 " + "\n" return ans [1] for evaluating the left expression (child 2) before the right expression (child 4 of node). [1] for saving the left expression on the stack while the right expression is computed, then restoring it to $1 [1] for moving the returned value of the right expression from $3 to $2 before the jalr. That s an additional 3 marks for the things in twoparametercall(...) that aren t in oneparametercall(...), for a total of 9 marks for part a. } CS 241 Fall 2009 Page 9 of 17

10 Part b) Briefly explain the other significant changes to the WL compiler that would be needed to implement the added capability described on page 8. The entry in the symbol table for a function must have an additional field that records whether the ID corresponds to a variable or a function name [1] and an additional field that records whether the function takes one or two parameters [1]. It's ok, though unaesthetic, if they add ONE field to the symbol table that has the value 0 for variables and 1 or 2 for functions. The compiler must verify that every function call made invokes an ID that was declared to be of type function [1], and passes the correct number of arguements [1]. At the beginning of the code generation phase the compiler must generate a.export statement for each function declared [1]. That's a total of 5. If they cover a point listed here in their answer to part a, give them credit for it. CS 241 Fall 2009 Page 10 of 17

11 Question 7: [5 marks] Consider the following context-free grammar G S A A a B c A B B b B ε Fill in the following LL(1) parsing table [aka Predict( non-terminal, terminal)] for this grammar. a b c S S A A A B A a B c A B B B ε B b B ε Marking: 1 for each completely correct cell, then divide by 3 and round to the nearest integer. It's fine if they enter ERROR in the cells I ve left empty. CS 241 Fall 2009 Page 11 of 17

12 Question 8: [6 marks] Consider the following augmented LL(1) grammar G, whose start symbol is S, whose non-terminals are { S, P, L, B, E, T } and whose remaining symbols { if, then, else, print,... } are terminals. Here is the LL(1) parsing table for this grammar. r0 represents the rule S P, r1 represents the rule P if B then P else P, etc. S if then else { } print ; = # + r0 P r1 r2 r3 L r5 r4 B E r0: S P r1: P if B then P else P r2: P { P L } r3: P print E r4: L ; P L r5: L ε r6: B E = E r7: E # T r8: T + # T r9: T ε T r9 r9 r9 r9 r9 r9 r8 In the table below, write the next six steps of an LL(1) parse for the input shown, supplying information as is done in the first three rows. Action Stack Input yet to be read Initialization S if # = # then print # Expand r0 P if # = # then print # Read P if # = # then print # r6 r7 P if B then P else P [r1] if B then P else P if # = # then print # Read if B then P else P # = # then print # B E = E [r6] E = E then P else P # = # then print # E # T [r7] # T = E then P else P # = # then print # Read # T = E then S else P = # then print # T ε [r9] = E then S else P = # then print # 1 for each correct cell (total of 18), then divide by 3 and round up to get the marks awarded (max of 6). CS 241 Fall 2009 Page 12 of 17

13 Question 9: [8 marks] Consider the augmented cfg G S P P ( L ) P x L P L P, L whose start symbol is S, whose non-terminals are S, P and L, and whose terminal symbols are ( ) x, The LR(1) parsing table for this grammar appears below. snn means shift and move to state NN; A γ means reduce using the rule A γ. On the next page, you are to use this parsing table to parse the input shown there until you have filled the table or the parse is complete. DFA State ( ) x, S P L 00 s01 01 s02 s03 s09 02 s02 s03 s04 s07 03 P x P x P x 04 L P s05 05 s02 s03 s04 s06 06 L P, L 07 s08 08 P ( L ) P ( L ) P ( L ) 09 Accept CS 241 Fall 2009 Page 13 of 17

14 Row # State Action (Bot) Stack (Top) Remaining Input On even numbered rows, state the next action of the parser. On odd numbered rows, enter the current state of the parser, the contents of the stack, and the input remaining to be read in the appropriately labelled column. The first few entries have already been filled in so that you will know exactly how to supply the information needed. 00: Initialize! 01: 00 ( x, ( x ) ) 02: Shift 03: 01 [,1] 04: Shift ( ( x, ( x ) ) 05: 02 [,1] [(,2] x, ( x ) ) 06: Shift x 07: 03 [,1] [(,2] [x,3], ( x ) ) 08: Reduce P x 09: 04 [,1] [(,2] [P,4], ( x ) ) 10: Shift 11: 05 [,1] [(,2] [P,4] [,,5] ( x ) ) 12: Shift 13: 02 [,1] [(,2] [P,4] [,,5] [(,2] x ) ) 14: Shift x 15: 03 [,1] [(,2] [P,4] [,,5] [(,2] [x,3] ) ) 16: Reduce P x 17: 04 [,1] [(,2] [P,4] [,,5] [(,2] [P,4] ) ) 18: Reduce L P 19: 07 [,1] [(,2] [P,4] [,,5] [(,2] [L,7] ) ) 20: Shift ) 21: 08 [,1] [(,2] [P,4] [,,5] [(,2] [L,7] [),8] ) 22: Reduce P (L) 23: 04 [,1] [(,2] [P,4] [,,5] [P,4] ) (The parse may not be done yet, but if so, you are not asked to trace it further.) CS 241 Fall 2009 Page 14 of 17

15 Question 10: [14 marks] Part a) Consider a system to allocate and deallocate fixed-sized non-relocatable blocks of memory in an arena starting at address S and ending at address E. The operations required are: init() a = allocate() Initialize the arena and any necessary variables. Allocate a two-word block of memory. Return the address of the first word, or null if the allocation fails. deallocate(a) Deallocate the two-word block of memory at address a. Assume that Figure 1 illustrates the result of the sequence of operations shown immediately below. init() a = allocate() b = allocate() c = allocate() deallocate( a ) deallocate( c ) Figure 1 S free b cur E In Figure 2, draw the final result of applying the following four additional operations, starting from Figure 1. Draw on Figure 1 for your rough work, then copy the final result to Figure 2. Please ensure that Figure 2 contains no erasures or crossed-out material. ( *) d = allocate() e = allocate() Figure 2 f = allocate() g = allocate() S free cur E In Figure 3, draw the final result of applying the three following additional operations, starting from Figure 2. Please ensure that Figure 3 contains no erasures or crossed-out material. ( *) deallocate( d ) deallocate( e ) Figure 3 deallocate( f ) S free cur E (*) If you make a mistake in Figure 2 or 3, cross out the entire diagram clearly and redraw your answer on the back of the previous page. CS 241 Fall 2009 Page 15 of 17

16 Part b) Give pseudocode for each of the operations listed below. Assume that S and E contain appropriate values prior to init(); assume that all other memory is uninitialized. init() cur = S free = NULL a = allocate() if free!= NULL tmp = free free = *free else if cur < S tmp = cur cur++ return tmp deallocate( a ) *a = free free = a CS 241 Fall 2009 Page 16 of 17

17 Part c) Suppose that you wish to extend your solution to allocate blocks of variable size; that is, a = allocate( k ) allocates a block of k words, returning its address or null. Please read part (ii) before answering part (i). (i) What structural information must be added to each block? pointers for doubly linked list of blocks size of block whether allocated or free General marking instructions are on the preceding page. (ii) Outline an implementation of deallocate(a), assuming that the other operations correctly maintain the structural information described in (i). Use high level operations such as insert from list or delete from list. You need not give the detailed pointer operations necessary to implement these operations. if next(a) is unallocated combine a, next(a), adjusting length, and list pointers to form one node if prev(a) is unallocated combine prev(a), a, adjusting length and list pointers to form one node set a to point to the one node mark a as unallocated Note: they will give various levels of detail for the pointer threading. Give full marks if they outline a scenario that covers the four cases: alloc, a, alloc alloc, a, free free, a, alloc free, a, free General marking instructions are on the preceding page. CS 241 Fall 2009 Page 17 of 17

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name

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

University of Waterloo Midterm Examination

University of Waterloo Midterm Examination University of Waterloo Midterm Examination 1 Fall 2008 Student Name: UW Student ID Number: UW Userid: Course Abbreviation and Number: CS 241 Course Title: Foundations of Sequential Programs Section(s):

More information

CS241 Final Exam Review

CS241 Final Exam Review CS241 Final Exam Review Winter 2018 1 Notes and disclaimer These review materials only cover topics discussed after the midterm. For a review of pre-midterm content, see the midterm review materials. These

More information

Parsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones

Parsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones Parsing III (Top-down parsing: recursive descent & LL(1) ) (Bottom-up parsing) CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones Copyright 2003, Keith D. Cooper,

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

10/4/18. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntactic Analysis

10/4/18. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntactic Analysis Lexical and Syntactic Analysis Lexical and Syntax Analysis In Text: Chapter 4 Two steps to discover the syntactic structure of a program Lexical analysis (Scanner): to read the input characters and output

More information

Compiler Design Concepts. Syntax Analysis

Compiler Design Concepts. Syntax Analysis Compiler Design Concepts Syntax Analysis Introduction First task is to break up the text into meaningful words called tokens. newval=oldval+12 id = id + num Token Stream Lexical Analysis Source Code (High

More information

Defining syntax using CFGs

Defining syntax using CFGs Defining syntax using CFGs Roadmap Last time Defined context-free grammar This time CFGs for specifying a language s syntax Language membership List grammars Resolving ambiguity CFG Review G = (N,Σ,P,S)

More information

Question Marks 1 /16 2 /13 3 /12 4 /15 5 /8 6 /15 7 /8 8 /5 9 /8 Total /100

Question Marks 1 /16 2 /13 3 /12 4 /15 5 /8 6 /15 7 /8 8 /5 9 /8 Total /100 CSC 460/660, Midterm March 22, 2006 Name: Student ID: Signature: You have 75 minutes to write the 9 questions on this examination. A total of 100 marks is available. Justify all of your answers You may

More information

CS 536 Midterm Exam Spring 2013

CS 536 Midterm Exam Spring 2013 CS 536 Midterm Exam Spring 2013 ID: Exam Instructions: Write your student ID (not your name) in the space provided at the top of each page of the exam. Write all your answers on the exam itself. Feel free

More information

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 97 INSTRUCTIONS

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 97 INSTRUCTIONS RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 97 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name

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

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

10/5/17. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntax Analysis

10/5/17. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntax Analysis Lexical and Syntactic Analysis Lexical and Syntax Analysis In Text: Chapter 4 Two steps to discover the syntactic structure of a program Lexical analysis (Scanner): to read the input characters and output

More information

Lecture Code Generation for WLM

Lecture Code Generation for WLM Lecture 17+18 Code Generation for WLM CS 241: Foundations of Sequential Programs Winter 2018 Troy Vasiga et al University of Waterloo 1 Code Generation (A9/A10) Input: Output: Number of different outputs:

More information

CSE 582 Autumn 2002 Exam Sample Solution

CSE 582 Autumn 2002 Exam Sample Solution Question 1. (10 points) Regular expressions. Describe the set of strings that are generated by the each of the following regular expressions. a) (a (bc)* d)+ One or more of the string a or the string d

More information

CSE 401 Midterm Exam 11/5/10

CSE 401 Midterm Exam 11/5/10 Name There are 5 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed books, closed notes, closed

More information

CS143 Handout 20 Summer 2012 July 18 th, 2012 Practice CS143 Midterm Exam. (signed)

CS143 Handout 20 Summer 2012 July 18 th, 2012 Practice CS143 Midterm Exam. (signed) CS143 Handout 20 Summer 2012 July 18 th, 2012 Practice CS143 Midterm Exam This midterm exam is open-book, open-note, open-computer, but closed-network. This means that if you want to have your laptop with

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

Question Points Score

Question Points Score CS 453 Introduction to Compilers Midterm Examination Spring 2009 March 12, 2009 75 minutes (maximum) Closed Book You may use one side of one sheet (8.5x11) of paper with any notes you like. This exam has

More information

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID #

CSE 401/M501 18au Midterm Exam 11/2/18. Name ID # Name ID # There are 7 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. The exam is closed books, closed notes,

More information

Syntax Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

Syntax Analysis. Amitabha Sanyal. (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay Syntax Analysis (www.cse.iitb.ac.in/ as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay September 2007 College of Engineering, Pune Syntax Analysis: 2/124 Syntax

More information

CSE 401 Final Exam. December 16, 2010

CSE 401 Final Exam. December 16, 2010 CSE 401 Final Exam December 16, 2010 Name You may have one sheet of handwritten notes plus the handwritten notes from the midterm. You may also use information about MiniJava, the compiler, and so forth

More information

CSE 401 Midterm Exam Sample Solution 2/11/15

CSE 401 Midterm Exam Sample Solution 2/11/15 Question 1. (10 points) Regular expression warmup. For regular expression questions, you must restrict yourself to the basic regular expression operations covered in class and on homework assignments:

More information

Lexical and Syntax Analysis

Lexical and Syntax Analysis Lexical and Syntax Analysis In Text: Chapter 4 N. Meng, F. Poursardar Lexical and Syntactic Analysis Two steps to discover the syntactic structure of a program Lexical analysis (Scanner): to read the input

More information

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design i About the Tutorial A compiler translates the codes written in one language to some other language without changing the meaning of the program. It is also expected that a compiler should make the target

More information

CS143 Midterm Fall 2008

CS143 Midterm Fall 2008 CS143 Midterm Fall 2008 Please read all instructions (including these) carefully. There are 4 questions on the exam, some with multiple parts. You have 75 minutes to work on the exam. The exam is closed

More information

Context-free grammars

Context-free grammars Context-free grammars Section 4.2 Formal way of specifying rules about the structure/syntax of a program terminals - tokens non-terminals - represent higher-level structures of a program start symbol,

More information

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

Examples of attributes: values of evaluated subtrees, type information, source file coordinates, 1 2 3 Attributes can be added to the grammar symbols, and program fragments can be added as semantic actions to the grammar, to form a syntax-directed translation scheme. Some attributes may be set by

More information

Part III : Parsing. From Regular to Context-Free Grammars. Deriving a Parser from a Context-Free Grammar. Scanners and Parsers.

Part III : Parsing. From Regular to Context-Free Grammars. Deriving a Parser from a Context-Free Grammar. Scanners and Parsers. Part III : Parsing From Regular to Context-Free Grammars Deriving a Parser from a Context-Free Grammar Scanners and Parsers A Parser for EBNF Left-Parsable Grammars Martin Odersky, LAMP/DI 1 From Regular

More information

Parsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.

Parsing. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Parsing Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice. Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students

More information

Compiler Construction: Parsing

Compiler Construction: Parsing Compiler Construction: Parsing Mandar Mitra Indian Statistical Institute M. Mitra (ISI) Parsing 1 / 33 Context-free grammars. Reference: Section 4.2 Formal way of specifying rules about the structure/syntax

More information

CSE 401 Midterm Exam Sample Solution 11/4/11

CSE 401 Midterm Exam Sample Solution 11/4/11 Question 1. (12 points, 2 each) The front end of a compiler consists of three parts: scanner, parser, and (static) semantics. Collectively these need to analyze the input program and decide if it is correctly

More information

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F).

CS 2210 Sample Midterm. 1. Determine if each of the following claims is true (T) or false (F). CS 2210 Sample Midterm 1. Determine if each of the following claims is true (T) or false (F). F A language consists of a set of strings, its grammar structure, and a set of operations. (Note: a language

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

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

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Computer Science and Engineering TEST 1 Date : 24 02 2015 Marks : 50 Subject & Code : Compiler Design ( 10CS63) Class : VI CSE A & B Name of faculty : Mrs. Shanthala P.T/ Mrs. Swati Gambhire Time : 8:30 10:00 AM SOLUTION MANUAL 1. a.

More information

CS 164 Handout 11. Midterm Examination. There are seven questions on the exam, each worth between 10 and 20 points.

CS 164 Handout 11. Midterm Examination. There are seven questions on the exam, each worth between 10 and 20 points. Midterm Examination Please read all instructions (including these) carefully. Please print your name at the bottom of each page on the exam. There are seven questions on the exam, each worth between 10

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

Syntax Analysis, III Comp 412

Syntax Analysis, III Comp 412 Updated algorithm for removal of indirect left recursion to match EaC3e (3/2018) COMP 412 FALL 2018 Midterm Exam: Thursday October 18, 7PM Herzstein Amphitheater Syntax Analysis, III Comp 412 source code

More information

SYNTAX ANALYSIS 1. Define parser. Hierarchical analysis is one in which the tokens are grouped hierarchically into nested collections with collective meaning. Also termed as Parsing. 2. Mention the basic

More information

Syntax Analysis, III Comp 412

Syntax Analysis, III Comp 412 COMP 412 FALL 2017 Syntax Analysis, III Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2017, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp

More information

Bottom-Up Parsing II. Lecture 8

Bottom-Up Parsing II. Lecture 8 Bottom-Up Parsing II Lecture 8 1 Review: Shift-Reduce Parsing Bottom-up parsing uses two actions: Shift ABC xyz ABCx yz Reduce Cbxy ijk CbA ijk 2 Recall: he Stack Left string can be implemented by a stack

More information

BSCS Fall Mid Term Examination December 2012

BSCS Fall Mid Term Examination December 2012 PUNJAB UNIVERSITY COLLEGE OF INFORMATION TECHNOLOGY University of the Punjab Sheet No.: Invigilator Sign: BSCS Fall 2009 Date: 14-12-2012 Mid Term Examination December 2012 Student ID: Section: Morning

More information

COMPILER DESIGN. For COMPUTER SCIENCE

COMPILER DESIGN. For COMPUTER SCIENCE COMPILER DESIGN For COMPUTER SCIENCE . COMPILER DESIGN SYLLABUS Lexical analysis, parsing, syntax-directed translation. Runtime environments. Intermediate code generation. ANALYSIS OF GATE PAPERS Exam

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

CS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University

CS415 Compilers. Syntax Analysis. These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University CS415 Compilers Syntax Analysis These slides are based on slides copyrighted by Keith Cooper, Ken Kennedy & Linda Torczon at Rice University Limits of Regular Languages Advantages of Regular Expressions

More information

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών Lecture 5a Syntax Analysis lias Athanasopoulos eliasathan@cs.ucy.ac.cy Syntax Analysis Συντακτική Ανάλυση Context-free Grammars (CFGs) Derivations Parse trees

More information

ECE251 Midterm practice questions, Fall 2010

ECE251 Midterm practice questions, Fall 2010 ECE251 Midterm practice questions, Fall 2010 Patrick Lam October 20, 2010 Bootstrapping In particular, say you have a compiler from C to Pascal which runs on x86, and you want to write a self-hosting Java

More information

2.2 Syntax Definition

2.2 Syntax Definition 42 CHAPTER 2. A SIMPLE SYNTAX-DIRECTED TRANSLATOR sequence of "three-address" instructions; a more complete example appears in Fig. 2.2. This form of intermediate code takes its name from instructions

More information

LL(k) Parsing. Predictive Parsers. LL(k) Parser Structure. Sample Parse Table. LL(1) Parsing Algorithm. Push RHS in Reverse Order 10/17/2012

LL(k) Parsing. Predictive Parsers. LL(k) Parser Structure. Sample Parse Table. LL(1) Parsing Algorithm. Push RHS in Reverse Order 10/17/2012 Predictive Parsers LL(k) Parsing Can we avoid backtracking? es, if for a given input symbol and given nonterminal, we can choose the alternative appropriately. his is possible if the first terminal of

More information

Question Bank. 10CS63:Compiler Design

Question Bank. 10CS63:Compiler Design Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a

More information

Assignment 1. Due 08/28/17

Assignment 1. Due 08/28/17 Assignment 1. Due 08/28/17 1. Implement Scanner for Micro language (Micro Scanner) employing routines considered in class. When you call Scanner in a the output must be a list of tokens. Scan the following

More information

VIVA QUESTIONS WITH ANSWERS

VIVA QUESTIONS WITH ANSWERS VIVA QUESTIONS WITH ANSWERS 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the

More information

CSE 5317 Midterm Examination 4 March Solutions

CSE 5317 Midterm Examination 4 March Solutions CSE 5317 Midterm Examination 4 March 2010 1. / [20 pts] Solutions (parts a j; -1 point for each wrong answer, 0 points for each blank answer, 2 point for each correct answer. Therefore, the score for this

More information

Syntax Analysis Part I

Syntax Analysis Part I Syntax Analysis Part I Chapter 4: Context-Free Grammars Slides adapted from : Robert van Engelen, Florida State University Position of a Parser in the Compiler Model Source Program Lexical Analyzer Token,

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 in4303 April 9, 2010 14.00-15.30 This exam (6 pages) consists of 52 True/False

More information

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING Subject Name: CS2352 Principles of Compiler Design Year/Sem : III/VI UNIT I - LEXICAL ANALYSIS 1. What is the role of Lexical Analyzer? [NOV 2014] 2. Write

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

Midterm I (Solutions) CS164, Spring 2002

Midterm I (Solutions) CS164, Spring 2002 Midterm I (Solutions) CS164, Spring 2002 February 28, 2002 Please read all instructions (including these) carefully. There are 9 pages in this exam and 5 questions, each with multiple parts. Some questions

More information

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees

Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees Chapter 3: CONTEXT-FREE GRAMMARS AND PARSING Part2 3.3 Parse Trees and Abstract Syntax Trees 3.3.1 Parse trees 1. Derivation V.S. Structure Derivations do not uniquely represent the structure of the strings

More information

CS 314 Principles of Programming Languages

CS 314 Principles of Programming Languages CS 314 Principles of Programming Languages Lecture 5: Syntax Analysis (Parsing) Zheng (Eddy) Zhang Rutgers University January 31, 2018 Class Information Homework 1 is being graded now. The sample solution

More information

CSCI312 Principles of Programming Languages

CSCI312 Principles of Programming Languages Copyright 2006 The McGraw-Hill Companies, Inc. CSCI312 Principles of Programming Languages! LL Parsing!! Xu Liu Derived from Keith Cooper s COMP 412 at Rice University Recap Copyright 2006 The McGraw-Hill

More information

Parsing III. (Top-down parsing: recursive descent & LL(1) )

Parsing III. (Top-down parsing: recursive descent & LL(1) ) Parsing III (Top-down parsing: recursive descent & LL(1) ) Roadmap (Where are we?) Previously We set out to study parsing Specifying syntax Context-free grammars Ambiguity Top-down parsers Algorithm &

More information

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions:

Solution printed. Do not start the test until instructed to do so! CS 2604 Data Structures Midterm Spring Instructions: VIRG INIA POLYTECHNIC INSTITUTE AND STATE U T PROSI M UNI VERSI TY Instructions: Print your name in the space provided below. This examination is closed book and closed notes, aside from the permitted

More information

Syntax-Directed Translation. Lecture 14

Syntax-Directed Translation. Lecture 14 Syntax-Directed Translation Lecture 14 (adapted from slides by R. Bodik) 9/27/2006 Prof. Hilfinger, Lecture 14 1 Motivation: parser as a translator syntax-directed translation stream of tokens parser ASTs,

More information

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program. COMPILER DESIGN 1. What is a compiler? A compiler is a program that reads a program written in one language the source language and translates it into an equivalent program in another language-the target

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

THE COMPILATION PROCESS EXAMPLE OF TOKENS AND ATTRIBUTES

THE COMPILATION PROCESS EXAMPLE OF TOKENS AND ATTRIBUTES THE COMPILATION PROCESS Character stream CS 403: Scanning and Parsing Stefan D. Bruda Fall 207 Token stream Parse tree Abstract syntax tree Modified intermediate form Target language Modified target language

More information

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing Roadmap > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing The role of the parser > performs context-free syntax analysis > guides

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

Lecture 8: Deterministic Bottom-Up Parsing

Lecture 8: Deterministic Bottom-Up Parsing Lecture 8: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Fri Feb 12 13:02:57 2010 CS164: Lecture #8 1 Avoiding nondeterministic choice: LR We ve been looking at general

More information

Topic 3: Syntax Analysis I

Topic 3: Syntax Analysis I Topic 3: Syntax Analysis I Compiler Design Prof. Hanjun Kim CoreLab (Compiler Research Lab) POSTECH 1 Back-End Front-End The Front End Source Program Lexical Analysis Syntax Analysis Semantic Analysis

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

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis

CSE 130 Programming Language Principles & Paradigms Lecture # 5. Chapter 4 Lexical and Syntax Analysis Chapter 4 Lexical and Syntax Analysis Introduction - Language implementation systems must analyze source code, regardless of the specific implementation approach - Nearly all syntax analysis is based on

More information

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Lexical Analysis Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast! Compiler Passes Analysis of input program (front-end) character stream

More information

CS 403: Scanning and Parsing

CS 403: Scanning and Parsing CS 403: Scanning and Parsing Stefan D. Bruda Fall 2017 THE COMPILATION PROCESS Character stream Scanner (lexical analysis) Token stream Parser (syntax analysis) Parse tree Semantic analysis Abstract syntax

More information

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7

Top-Down Parsing and Intro to Bottom-Up Parsing. Lecture 7 Top-Down Parsing and Intro to Bottom-Up Parsing Lecture 7 1 Predictive Parsers Like recursive-descent but parser can predict which production to use Predictive parsers are never wrong Always able to guess

More information

Chapter 4. Lexical and Syntax Analysis

Chapter 4. Lexical and Syntax Analysis Chapter 4 Lexical and Syntax Analysis Chapter 4 Topics Introduction Lexical Analysis The Parsing Problem Recursive-Descent Parsing Bottom-Up Parsing Copyright 2012 Addison-Wesley. All rights reserved.

More information

Lexical and Syntax Analysis (2)

Lexical and Syntax Analysis (2) Lexical and Syntax Analysis (2) In Text: Chapter 4 N. Meng, F. Poursardar Motivating Example Consider the grammar S -> cad A -> ab a Input string: w = cad How to build a parse tree top-down? 2 Recursive-Descent

More information

Habanero Extreme Scale Software Research Project

Habanero Extreme Scale Software Research Project Habanero Extreme Scale Software Research Project Comp215: Grammars Zoran Budimlić (Rice University) Grammar, which knows how to control even kings - Moliere So you know everything about regular expressions

More information

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler.

Briefly describe the purpose of the lexical and syntax analysis phases in a compiler. Name: Midterm Exam PID: This is a closed-book exam; you may not use any tools besides a pen. You have 75 minutes to answer all questions. There are a total of 75 points available. Please write legibly;

More information

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e

11. a b c d e. 12. a b c d e. 13. a b c d e. 14. a b c d e. 15. a b c d e CS-3160 Concepts of Programming Languages Spring 2015 EXAM #1 (Chapters 1-6) Name: SCORES MC: /75 PROB #1: /15 PROB #2: /10 TOTAL: /100 Multiple Choice Responses Each multiple choice question in the separate

More information

Lecture 7: Deterministic Bottom-Up Parsing

Lecture 7: Deterministic Bottom-Up Parsing Lecture 7: Deterministic Bottom-Up Parsing (From slides by G. Necula & R. Bodik) Last modified: Tue Sep 20 12:50:42 2011 CS164: Lecture #7 1 Avoiding nondeterministic choice: LR We ve been looking at general

More information

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous. Section A 1. What do you meant by parser and its types? A parser for grammar G is a program that takes as input a string w and produces as output either a parse tree for w, if w is a sentence of G, or

More information

CSE 582 Autumn 2002 Exam 11/26/02

CSE 582 Autumn 2002 Exam 11/26/02 Name There are 8 questions worth a total of 100 points. Please budget your time so you get to all of the questions. Keep your answers brief and to the point. You may refer to the following reference materials:

More information

2068 (I) Attempt all questions.

2068 (I) Attempt all questions. 2068 (I) 1. What do you mean by compiler? How source program analyzed? Explain in brief. 2. Discuss the role of symbol table in compiler design. 3. Convert the regular expression 0 + (1 + 0)* 00 first

More information

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised: EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 2017-09-11 This lecture Regular expressions Context-free grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)

More information

TML Language Reference Manual

TML Language Reference Manual TML Language Reference Manual Jiabin Hu (jh3240) Akash Sharma (as4122) Shuai Sun (ss4088) Yan Zou (yz2437) Columbia University October 31, 2011 1 Contents 1 Introduction 4 2 Lexical Conventions 4 2.1 Character

More information

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution Exam Facts Format Wednesday, July 20 th from 11:00 a.m. 1:00 p.m. in Gates B01 The exam is designed to take roughly 90

More information

CSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1

CSE 401 Compilers. LR Parsing Hal Perkins Autumn /10/ Hal Perkins & UW CSE D-1 CSE 401 Compilers LR Parsing Hal Perkins Autumn 2011 10/10/2011 2002-11 Hal Perkins & UW CSE D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts 10/10/2011

More information

Unit 13. Compiler Design

Unit 13. Compiler Design Unit 13. Compiler Design Computers are a balanced mix of software and hardware. Hardware is just a piece of mechanical device and its functions are being controlled by a compatible software. Hardware understands

More information

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation Concepts Introduced in Chapter 2 A more detailed overview of the compilation process. Parsing Scanning Semantic Analysis Syntax-Directed Translation Intermediate Code Generation Context-Free Grammar A

More information

Compiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6

Compiler Design 1. Bottom-UP Parsing. Goutam Biswas. Lect 6 Compiler Design 1 Bottom-UP Parsing Compiler Design 2 The Process The parse tree is built starting from the leaf nodes labeled by the terminals (tokens). The parser tries to discover appropriate reductions,

More information

COP 3402 Systems Software Top Down Parsing (Recursive Descent)

COP 3402 Systems Software Top Down Parsing (Recursive Descent) COP 3402 Systems Software Top Down Parsing (Recursive Descent) Top Down Parsing 1 Outline 1. Top down parsing and LL(k) parsing 2. Recursive descent parsing 3. Example of recursive descent parsing of arithmetic

More information

CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1

CSE P 501 Compilers. LR Parsing Hal Perkins Spring UW CSE P 501 Spring 2018 D-1 CSE P 501 Compilers LR Parsing Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 D-1 Agenda LR Parsing Table-driven Parsers Parser States Shift-Reduce and Reduce-Reduce conflicts UW CSE P 501 Spring 2018

More information

CSE P 501 Exam 11/17/05 Sample Solution

CSE P 501 Exam 11/17/05 Sample Solution 1. (8 points) Write a regular expression or set of regular expressions that generate the following sets of strings. You can use abbreviations (i.e., name = regular expression) if it helps to make your

More information

CS 4120 Introduction to Compilers

CS 4120 Introduction to Compilers CS 4120 Introduction to Compilers Andrew Myers Cornell University Lecture 6: Bottom-Up Parsing 9/9/09 Bottom-up parsing A more powerful parsing technology LR grammars -- more expressive than LL can handle

More information

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309 PART 3 - SYNTAX ANALYSIS F. Wotawa (IST @ TU Graz) Compiler Construction Summer term 2016 64 / 309 Goals Definition of the syntax of a programming language using context free grammars Methods for parsing

More information