1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Page 1

Similar documents
Chapter 5 Names, Bindings, Type Checking, and Scopes

Semester Review. CSC 301, Fall 2015

CS 106 Introduction to Computer Science I

CSCI 3136 Principles of Programming Languages

Organization of Programming Languages CS320/520N. Lecture 05. Razvan C. Bunescu School of Electrical Engineering and Computer Science

UNIT-I Preliminaries

Chapter 6: Programming Languages

03 - Lexical Analysis

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Semantic Analysis: Types and Type Checking

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Object-Oriented Design Lecture 4 CSU 370 Fall 2007 (Pucella) Tuesday, Sep 18, 2007

Ed. v1.0 PROGRAMMING LANGUAGES WORKING PAPER DRAFT PROGRAMMING LANGUAGES. Ed. v1.0

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

An Incomplete C++ Primer. University of Wyoming MA 5310

Introduction to Java

Compiler Construction

Computer Programming I

DATA STRUCTURES USING C

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

The C Programming Language course syllabus associate level

CA Compiler Construction

Introduction to Java. CS 3: Computer Programming in Java

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Parameter passing in LISP

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Instruction Set Architecture (ISA)

Lecture 9. Semantic Analysis Scoping and Symbol Table

Chapter 2: Elements of Java

AP Computer Science Java Subset

Memory management. Announcements. Safe user input. Function pointers. Uses of function pointers. Function pointer example

Lecture 11 Doubly Linked Lists & Array of Linked Lists. Doubly Linked Lists

Crash Course in Java

Compiler Construction

CSE 307: Principles of Programming Languages

Answers to Review Questions Chapter 7

VB.NET Programming Fundamentals

Implementation Aspects of OO-Languages

Memory Allocation. Static Allocation. Dynamic Allocation. Memory Management. Dynamic Allocation. Dynamic Storage Allocation

The programming language C. sws1 1

Stacks. Linear data structures

Compiling Object Oriented Languages. What is an Object-Oriented Programming Language? Implementation: Dynamic Binding

Context free grammars and predictive parsing

PART-A Questions. 2. How does an enumerated statement differ from a typedef statement?

Lecture 22: C Programming 4 Embedded Systems

Pemrograman Dasar. Basic Elements Of Java

CS 111 Classes I 1. Software Organization View to this point:

Performance Improvement In Java Application

C Compiler Targeting the Java Virtual Machine

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

Java Basics: Data Types, Variables, and Loops

Topics. Parts of a Java Program. Topics (2) CS 146. Introduction To Computers And Java Chapter Objectives To understand:

JDK 1.5 Updates for Introduction to Java Programming with SUN ONE Studio 4

Java Interview Questions and Answers

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Section of DBMS Selection & Evaluation Questionnaire

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

C++FA 5.1 PRACTICE MID-TERM EXAM

J a v a Quiz (Unit 3, Test 0 Practice)

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Stack Allocation. Run-Time Data Structures. Static Structures

5 Arrays and Pointers

Embedded SQL programming

java.util.scanner Here are some of the many features of Scanner objects. Some Features of java.util.scanner

PROBLEM SOLVING SEVENTH EDITION WALTER SAVITCH UNIVERSITY OF CALIFORNIA, SAN DIEGO CONTRIBUTOR KENRICK MOCK UNIVERSITY OF ALASKA, ANCHORAGE PEARSON

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Lecture 1: Introduction

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Sources: On the Web: Slides will be available on:

Programming Language Theory

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Number Representation

CS106A, Stanford Handout #38. Strings and Chars

Information technology Programming languages Fortran Enhanced data type facilities

Moving from CS 61A Scheme to CS 61B Java

Class 16: Function Parameters and Polymorphism

Generalizing Overloading for C++2000

Programming Languages

Introduction to Data Structures

Programming Language Inter-conversion

An Overview of Java. overview-1

A Grammar for the C- Programming Language (Version S16) March 12, 2016

Variables, Constants, and Data Types

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Departamento de Investigación. LaST: Language Study Tool. Nº 143 Edgard Lindner y Enrique Molinari Coordinación: Graciela Matich

Introduction to Object-Oriented Programming

Caml Virtual Machine File & data formats Document version: 1.4

Arrays. Atul Prakash Readings: Chapter 10, Downey Sun s Java tutorial on Arrays:

Technical paper review. Program visualization and explanation for novice C programmers by Matthew Heinsen Egan and Chris McDonald.

1. Relational database accesses data in a sequential form. (Figures 7.1, 7.2)

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Transcription:

CS 1621 MIDTERM EXAM 1 Name: Problem 1 (1x17 =17 points) 2 (21 points) 3 (5 points) 4 (3 points) 5 (4 points) Total ( 50points) Score Page 1

1. (1 x 17 = 17 points) Determine if each of the following statements is true (T) or false (F) : (1) The first widely used high-level programming language is Fortran. (2) COBOL was designed for business applications. (3) Java was designed mainly for web applications. (4) Aliasing means that a pointer may point to two or more memory places. (5) Today readability is becoming increasingly important in evaluating modern programming languages. (6) A type coercion example is that operator + can be redefined by the user to summarize two vector variables. (7) Given the following declaration, A: array of (1..10) of integer B, C: array of (1..10) of integer A, B and C are type compatible under name type compatibility. (8) For the declaration in (7), A and C are type compatible under name structure compatibility. (9) Type checking can only be performed at compile-time to find type errors. (10) The reason that decimal number type is sometimes included as a primitive data type is: it supports accurate computation within range while floating point numbers cannot. (11) Given the follow array declaration, (a) int func1(int LEN) { int arr1[len];.} (b) int func2(int LEN){ int*arr2; arr2=(int*)malloc(len*4); } Approach (a) is more efficient. (12) C programming language can be precisely defined using EBNF (extended BNF) formalism. (13) A BNF grammar is considered as ambiguous if every sentence in the corresponding language has two or more parse trees. (14) A heap-dynamic array is an array whose size can change --- shrink and expand, at runtime. (15) The use of enumeration type in C is safe since its value is mapped to integers such that type checking can be performed thereafter. (16) A dangling pointer refers to a data block in heap and there is no pointer pointing to the data block. (17) Garbage refers to a data block that is allocated in heap but is not accessible to the user program. Page 2

2. (21 points) Brief answer following questions: (1) (2 points) We use (what formalism) to describe tokens. We use (what formalism) to describe the syntax structure of C programming language. (2) (3 points) We usually use attributed grammar to describe static semantics, what are the names of two types of attributes? Give an example for each of them. You don t have to define. Filling at least three blankets. (a) example (b) example (3) (2 points) List the names of three commonly used approaches to define the dynamic semantics of a programming language. You don t have to explain each approach. List at least two. (a) (b) (c) (4) (2 points) Compute the weakest condition for the following assignments with given postcondition. Declaration of variables x, y, and z: int x, y, z; { } y = 10 + y; z=4; x= y + z; { x > 0 } (5) (4 points) Compare the advantages and disadvantages of compilation and interpretation approaches. Page 3

(6) (4 points) Explain or give an example to show that reference counting cannot handle circular linked garbage objects. (7) (4 points) Considering the following C program void fun1(void) { int a, b, c; /*definition 1*/ void fun2(void) { int a,c; /*definition 2*/ } void fun3 (void) { int a; /*definition 3*/ point X: use a, use c; } } When we have calling sequence fun1() fun2() fun3(), at point X, (1) According to static scoping, for use a, a is the one defined in (2) According to static scoping, for use c, c is the one defined in (3) According to dynamic scoping, for use a, a is the one defined in (4) According to dynamic scoping, for use c, c is the one defined in 3. (5 points) Given the following grammar, E E + F E F F F F * T T T a b Construct the parse tree for the sentence a + b * a. Page 4

4. (3 points) Compute array address. Assume (a) The array declaration defines an array with 100 row x 100 column integer elements char a[100][100]; (b) Each character value takes 1 byte; (c) The starting address of the array is 0, i.e. the first item has address 0; (d) The lower bound of the index range of each dimension is one (1). For the array element a[3][6] If we use row major to store the array elements in the memory, its address is OR write down the mapping function 5. (4 points. choose one(1) of the following two problems to solve. There are 3 extra points if you do both and both are correct.) Regular expression or BNF: (1) Write a regular expression to satisfy following requirements: (a) The alphabet contains two characters: 0 and 1 ; (b) The number of appeared 1 s is an even number; For example, 0100001, 00011, 0110 are legal strings while 000001, 01101101 are not. Page 5

(2) Write a BNF grammar for the following language to satisfy following requirements: (a) The alphabet contains two characters: [ and ] ; (b) [ s are NOT required to be next to each other. Neither do ] s; (c) A legal sentence in the language has matching number of [ and ]. For example, [[]], [[[]]], [[][[]]], [[]][][][] are legal sentences; but [[][ [][][[[ are not. Page 6