Name ( ) Person Number ( )

Similar documents
Assignment 1 (Lexical Analyzer)

Assignment 1 (Lexical Analyzer)

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

Midterm I (Solutions) CS164, Spring 2002

CS 536 Midterm Exam Spring 2013

UVa ID: NAME (print): CS 4501 LDI Midterm 1

Midterm I - Solution CS164, Spring 2014

Midterm II CS164, Spring 2006

MIT Specifying Languages with Regular Expressions and Context-Free Grammars. Martin Rinard Massachusetts Institute of Technology

MIT Specifying Languages with Regular Expressions and Context-Free Grammars

CMSC330 Spring 2017 Midterm 2

CS143 Midterm Sample Solution Fall 2010

CSE 582 Autumn 2002 Exam 11/26/02

University of Washington CSE 140 Data Programming Winter Final exam. March 11, 2013

CS164: Midterm I. Fall 2003

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

CMSC330 Fall 2016 Midterm #2 2:00pm/3:30pm

MIDTERM EXAM (Solutions)

WARNING for Autumn 2004:

Syntax Intro and Overview. Syntax

CSE 332 Spring 2014: Midterm Exam (closed book, closed notes, no calculators)

CSE 373 Spring 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CS3 Midterm 2 Summer 2008

CSE 373 Autumn 2010: Midterm #1 (closed book, closed notes, NO calculators allowed)

CS 101 Fall 2006 Midterm 1 Name: ID:

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring 2015

CS 415 Midterm Exam Spring SOLUTION

Intro. Scheme Basics. scm> 5 5. scm>

CS1100 Introduction to Programming

CS 415 Midterm Exam Spring 2002

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

CIT 3136 Lecture 7. Top-Down Parsing

Problem Score Max Score 1 Syntax directed translation & type

Exam 1 Practice CSE 232 Summer 2018 (1) DO NOT OPEN YOUR EXAM BOOKLET UNTIL YOU HAVE BEEN TOLD TO BEGIN.

CS 315 Programming Languages Syntax. Parser. (Alternatively hand-built) (Alternatively hand-built)

Syntax. Syntax. We will study three levels of syntax Lexical Defines the rules for tokens: literals, identifiers, etc.

CS164 First Midterm Exam Fall 2014

CMSC330 Fall 2009 Final Exam

#101 Page: 1 Name: CS32 Midterm Exam. E01, W15, Phill Conrad, UC Santa Barbara

CSE 332 Spring 2013: Midterm Exam (closed book, closed notes, no calculators)

KU Compilerbau - Programming Assignment

cs173: Programming Languages Midterm Exam

YOU ARE ALLOWED TO HAVE ONLY THE FOLLOWING ON YOUR DESK OR WORKTABLE:

CSE 131 Introduction to Computer Science Fall Exam II

United States Naval Academy Electrical and Computer Engineering Department EC310-6 Week Midterm Spring AY2017

CSE413 Midterm. Question Max Points Total 100

This exam is worth 24 points, or 24% of your total course grade. The exam contains six

Final Exam. COMP Summer I June 26, points

Projects for Compilers

Introduction to Java Applications

CSE 341, Spring 2011, Final Examination 9 June Please do not turn the page until everyone is ready.

MIDTERM EXAMINATION - CS130 - Spring 2005

Project 2 Interpreter for Snail. 2 The Snail Programming Language

Introduction to Lexing and Parsing

Tail Calls. CMSC 330: Organization of Programming Languages. Tail Recursion. Tail Recursion (cont d) Names and Binding. Tail Recursion (cont d)

Discussion section number. a b c d e f g h i j k l m n o p q r s t u v w x y z a b c d e f g h i j k l m n o p q r s t u v w x y z

CS 164 Handout 16. Final Examination. There are nine questions on the exam, some in multiple parts. You have 3 hours to work on the

Computer Science Spring 98 Midterm Examination Professor L. Rowe

Qualifying Exam in Programming Languages and Compilers

CS143 Midterm Spring 2014

CSE331 Winter 2014, Midterm Examination February 12, 2014

CSE505, Fall 2012, Midterm Examination October 30, 2012

GE U111 Engineering Problem Solving & Computation Lecture 6 February 2, 2004

l Determine if a number is odd or even l Determine if a number/character is in a range - 1 to 10 (inclusive) - between a and z (inclusive)

CS143 Midterm Fall 2008

CSE 332 Winter 2015: Midterm Exam (closed book, closed notes, no calculators)

CMSC330 Spring 2016 Midterm #1 9:30am/12:30pm/3:30pm

LECTURE 3. Compiler Phases

CMSC330 Spring 2016 Midterm #2 9:30am/12:30pm/3:30pm

Section 1: True / False (2 points each, 30 pts total)

CSE331 Winter 2014, Midterm Examination February 12, 2014

YOUR NAME PLEASE: *** SOLUTIONS ***

CSE 340 Fall 2014 Project 4

Programming with Arrays Intro to Pointers CS 16: Solving Problems with Computers I Lecture #11

Chapter 2: Data and Expressions

CSE 332 Autumn 2013: Midterm Exam (closed book, closed notes, no calculators)

COMP 524 Spring 2018 Midterm Thursday, March 1

Department of Computer Science Purdue University, West Lafayette

CSE wi: Practice Midterm

Computer Science Foundation Exam

Data Structure (CS301)

Computer Science Foundation Exam

CS143 Final Fall 2009

CS113: Lecture 3. Topics: Variables. Data types. Arithmetic and Bitwise Operators. Order of Evaluation

CS /534 Compiler Construction University of Massachusetts Lowell. NOTHING: A Language for Practice Implementation

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

Largest Online Community of VU Students

CMSC330 Spring 2018 Midterm 2 9:30am/ 11:00am/ 3:30pm

More on Arrays CS 16: Solving Problems with Computers I Lecture #13

CSEN202: Introduction to Computer Science Spring Semester 2017 Midterm Exam

CSE 401 Final Exam. March 14, 2017 Happy π Day! (3/14) This exam is closed book, closed notes, closed electronics, closed neighbors, open mind,...

Contents. Jairo Pava COMS W4115 June 28, 2013 LEARN: Language Reference Manual

Project Compiler. CS031 TA Help Session November 28, 2011

Practice Midterm Exam Solutions

Programming Languages & Translators. XML Document Manipulation Language (XDML) Language Reference Manual

Parsing Scheme (+ (* 2 3) 1) * 1

MIDTERM EXAMINATION. CSE 130: Principles of Programming Languages. Professor Goguen. February 16, points total

University of Washington CSE 140 Data Programming Winter Final exam. March 11, 2013

EECS 373 Practice Midterm / Homework #3 Fall 2014

CS164: Programming Assignment 2 Dlex Lexer Generator and Decaf Lexer

Transcription:

CSE 305 Introduction to Programming Languages 1 Midterm Exam Duration 150 minutes (2.5 hours) June 27, 2013 Please read all instructions (including these) carefully. There are 5 questions on the exam, each worth between 10 and 30 points, you have 2.5 hours to work on the exam. You may not discuss the exam with anyone who has not taken the exam until 4:00 pm Monday. This exam is closed book, and you may need to use a calculator and if you don t have one, you can ask for help. Please write all of your answers in the space of blue book, and clearly mark your solutions. You may use the backs of the exam pages as scratch paper. If you have difficulties in finding scratch paper or you don t have enough space in your blue book, you can ask for help. Solutions will be graded on correctness and clarity. Each problem has a relatively simple and straightforward solution. You may get as few as 0 points for a question if your solution is far more complicated than necessary. Partial solutions will be graded for partial credit. Name ( ) Person Number ( ) Problem 1 2 3 4 5 Total Max points 24 20 24 20 12 100 Actual Points 1

CSE 305 Introduction to Programming Languages 2 Question 1: Calculation/Number/Storage Systems (total 24pts) EMC corporation remains the largest providers of data storage platforms in the world, competing with IBM, NetApp, Hewlett-Packard, and Hitachi Data Systems. The company started to ship its flagship product, the Symmetrix in 1990 and, the newest Symmetrix VMAX 40K was launched on May12, 2012, which implements MIRROED, RAID-5 3+1, RAID-5 7+1, RAID-6 6+2, RAID-6 14+2 architectures. 2

CSE 305 Introduction to Programming Languages 3 1 ) Above figure shows a small cluster, Symmetrix VMAX 40K frames, Iomega internal hard drive. Assume Symmetrix VMAX 40K is implemented using Iomega ( now LenovoEMC) internal hard drives, which has following parameters: 255 heads, 45600 cylinders/head, and 63 sectors/track, 4096 bytes/sector, please calculate capacity of the hard drive in terms of TB (8pts). 2) Now assume a Symmetrix VMAX 40K system is implemented using 2400 internal hard drives, and each hard drive has 2TB capacity. Please use Egyptian Hieroglyphics to calculate capacity of the system in terms of TB (8pts). 3) Do a calculation 456 nine! 567 nine using one s complement number (8pts) 3

CSE 305 Introduction to Programming Languages 4 Question 2: Lexical System/Regular Expression (total 20pts) Please refer to following Perl Regular Expression table. Notice: Escaping characters like $, #, (, ), need to add a backslash or \ in front of them. 1) Answer following questions by writing down required patterns in Perl (8pts): (a) Assume we want to represent any number of dollars greater than or equal to 1 dollar, dealing with fractions with a decimal point and two digits(2pts). (b) We need a pattern to represent processor s speed, matching one of the following four words: megahertz, MHz, gigahertz or GHz (2pts) (c ) Assume we are processing source code of a C program, by reading each line and storing the line in $sentence variables, please write down a pattern, matching all if keyword (Tip: assume all if keywords always start with one or more space and end with either a space or a left parenthesis) (2pts) (d) Assume we have following string: #!/usr/bin/perl $string = "The time is: 12:31:02 on 6/27/13"; Please write down two patterns matching time(12:31:02) and date(6/27/13) respectively (2pts) 4

CSE 305 Introduction to Programming Languages 5 2) Many OS requires user password conform to certain rules to reduce the odds that an attacker can guess a password. Consider following rules: A password consists of upper and lower case letters and digits. A password has at least four characters. At least one character of a password is digit. We define: Letter = [A-za-z] Digit = [0-9] Char = Digit Letter Please write down the password regular expression pattern, using our definition of Letter, Digit and Char (6pts). 3) Think about rules of Context Free Grammars (left-hand side -> right-hand side). Give a regular expression, representing all rules of Context-Free Grammars with non-terminals A,B,..Z, and terminals 0,1,2,,epslon. A production may not have alternatives on the right-hand side(i.e. no productions have on the right hand side). Productions are terminated by a space \s. Your solution may generate rules with useless or duplicate productions. Don t worry about which non-terminal is the start symbol. NonTerm = [A-Z] Term = [0-9] All = NonTerm Term epslon Please use our definition of NonTerm, Term, and All, to write down your regular expression(6pts). 5

CSE 305 Introduction to Programming Languages 6 Question 3: Context-Free-Grammars(CFG)/Push Down Automata(PDA) / Grammars (total 24pts) Please refer to the following C program and C grammar #include<stdio.h> int add(int); //------------------------------------- void main() { int i,num; int sum; scanf("%d\n",&num); sum=add(num); printf("d\n",sum); } //--------------------------------------- int add(int m) { int sum; if(m==1) return(1); else sum=m+add(m-1); return(sum); } 6

CSE 305 Introduction to Programming Languages 7 program declaration-list declaration-list declaration-list declaration declaration declaration var-declaration fun-declaration var-declaration type-specifier ID ; type-specifier ID [ NUM ] ; type-specifier int void fun-declaration type-specifier ID ( params ) compound-stmt params param-list void param-list param-list, param param param type-specifier ID type-specifier ID [ ] compound-stmt { local-declarations statement-list } local-declarations local-declarations var-declarations empty statement-list statement-list statement empty statement expression-stmt compound-stmt selection-stmt iteration-stmt return-stmt expression-stmt expression ; ; selection-stmt if ( expression ) statement if ( expression ) statement else statement iteration-stmt while ( expression ) statement return-stmt return ; return expression ; expression var = expression simple-expression var ID ID [ expression ] simple-expression additive-expression relop additive-expression additive-expression relop <= < > >= ==!= additive-expression additive-expression addop term term addop + - term term mulop factor factor mulop * / factor ( expression ) var call NUM call ID ( args ) args arg-list empty arg-list arg-list, expression expression Keywords: else if int return void while Special symbols: + - * / < <= > >= ==!= = ;, ( ) [ ] { } /* */ ID = letter letter * NUM = digit digit * letter = a.. z A.. Z digit = 0.. 9 Comments: /*... */ 1) Please parse following statement using a parse-tree. sum=add(num) Notice: semi-colon is not required(8pts). 7

CSE 305 Introduction to Programming Languages 8 2) Please show how the tree is parsed using leftmost-derivation in Push-Down Automata (Stack) (8pts). 3) Notice in above C grammars, there are two rules: simple-expression! additive-expression relop additive-expression (1) additive-expression additive-expression! additive-expression addop term term (2) If we define: simple-expression := S additive-expression := A relop := x addop := y term := B Then we have: S! AxA A (Formula 1) A! AyB B (Formula 2) Please write down the language generating Formula1 and Formular2, which is also the language S stands for, in terms of A, B, x, y (8pts). 8

CSE 305 Introduction to Programming Languages 9 Question 4: Lambda-Calculus/Application of Lambda-Calculus (total 20pts) Notice, in Scheme function body, set! means to redefine variable. 1) Please reduce following lambda expression as much as possible(8pts). (((λx.λy.λz.((x y) z) λf.λa.(f a)) λi.i) λj.j) 2) What is the result of following Scheme expressions? (6pts) (a) (define k (let ((a 3)) (lambda (x) (+ x a)))) (k 5) (b) (define m (lambda (x) (let ((a 3)) (+ x a)))) (m 5) (c ) (define p (let ((a 3)) (lambda (x) (if (equal? x new) (set! a (+ a 1)) (+ x a))))) (p 5) 9

CSE 305 Introduction to Programming Languages 10 3) Please evaluate following list operations using Lisp(Notice here x means: the value is not evaluated by the value assigned to x, but by the symbol x itself) (6pts). (a) (append (list a b) (c d)) (b) (list (list a b) (append (c) (d))) (c) (cdar ((1 2) (3 4))) 10

CSE 305 Introduction to Programming Languages 11 Question 5: Code Generation/Miscellaneous Short Answers (total 12pts) Please refer C program in Question 3. 1) Recall add function in the C program, and please rewrite the function add in Scheme (3pts) 2) Convert your Scheme add program into MIPS assembly language (3pts) 3) Briefly sketch stack trace of your MIPS program (3pts) 4) Please briefly show in C, Scheme, Fortran programming languages, how parameterlist (or argument-list) of function calls are implemented. Please explain similarities and difference(3pts). 11