CS441 Fall 04 Internet Section

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

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

Moving from CS 61A Scheme to CS 61B Java

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

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

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

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

PL / SQL Basics. Chapter 3

Some Scanner Class Methods

MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.

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

Compiler Construction

Using SQL Queries in Crystal Reports

3 SOFTWARE AND PROGRAMMING LANGUAGES

Database Programming with PL/SQL: Learning Objectives

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

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

C Compiler Targeting the Java Virtual Machine

An Introduction to the WEB Style of Literate Programming

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

Lecture 1: Introduction

6.170 Tutorial 3 - Ruby Basics

Realization of the High-density SaaS Infrastructure with a Fine-grained Multitenant Framework

Pseudo code Tutorial and Exercises Teacher s Version

Computer Programming C++ Classes and Objects 15 th Lecture

Generalizing Overloading for C++2000

Proxy Services: Good Practice Guidelines

Volume I, Section 4 Table of Contents

Textual Modeling Languages

JavaScript: Introduction to Scripting Pearson Education, Inc. All rights reserved.

Functional Programming

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

10CS73:Web Programming

Install Java Development Kit (JDK) 1.8

Example of a Java program

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

CSCI 3136 Principles of Programming Languages

Slide 1 Welcome to Installation and Maintenance of Health IT Systems, Elements of a Typical EHR system.

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

The C Programming Language course syllabus associate level

Programming Project 1: Lexical Analyzer (Scanner)

Unicode Support in Enterprise COBOL. Nick Tindall Stephen Miller Sam Horiguchi August 13, 2003

Semantic Analysis: Types and Type Checking

ESPResSo Summer School 2012

programming languages, programming language standards and compiler validation

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Unit Storage Structures 1. Storage Structures. Unit 4.3

Comp 411 Principles of Programming Languages Lecture 34 Semantics of OO Languages. Corky Cartwright Swarat Chaudhuri November 30, 20111

CSC Software II: Principles of Programming Languages

2. Basic Relational Data Model

McGraw-Hill The McGraw-Hill Companies, Inc.,

Week 1 Part 1: An Introduction to Database Systems. Databases and DBMSs. Why Use a DBMS? Why Study Databases??

ECE 341 Coding Standard

Semester Thesis Traffic Monitoring in Sensor Networks

An Eclipse Plug-In for Visualizing Java Code Dependencies on Relational Databases

What is a programming language?

Writing a Scientific/Technical Report

AppendixA1A1. Java Language Coding Guidelines. A1.1 Introduction

Dinopolis Java Coding Convention

The Design Maintenance System (DMS ) A Tool for Automating Software Quality Enhancement

Consulting. Personal Attention, Expert Assistance

IBM. REXX/400 Programmer s Guide. AS/400 Advanced Series. Version 4 SC

Chapter 13 Storage classes

3 Data Properties and Validation Rules

Context free grammars and predictive parsing

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

Symbol Tables. Introduction

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

Python, C++ and SWIG

Operating Systems Introduction

1. Domain Name System

Perl in a nutshell. First CGI Script and Perl. Creating a Link to a Script. print Function. Parsing Data 4/27/2009. First CGI Script and Perl

Software Engineering and Service Design: courses in ITMO University

Information and Computer Science Department ICS 324 Database Systems Lab#11 SQL-Basic Query

Fundamentals of Programming and Software Development Lesson Objectives

Access Tutorial 5: Basic Queries using SQL

What You re Missing About Missing Values

ERserver. DB2 Universal Database for iseries SQL Programming with Host Languages. iseries. Version 5

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

Parameter passing in LISP

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

AIMMS User s Guide - Advanced Data Management

THE UNIVERSITY OF AUCKLAND

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Bloomberg 1 Database Extension for EViews

CSE 130 Programming Language Principles & Paradigms

Ad Hoc Advanced Table of Contents

Last Week. XML (extensible Markup Language) HTML Deficiencies. XML Advantages. Syntax of XML DHTML. Applets. Modifying DOM Event bubbling

ANTLR - Introduction. Overview of Lecture 4. ANTLR Introduction (1) ANTLR Introduction (2) Introduction

Ligero Content Delivery Server. Documentum Content Integration with

Software: Systems and Application Software

Hypercosm. Studio.

Chapter 3.2 C++, Java, and Scripting Languages. The major programming languages used in game development.

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

Guide for Documenting and Sharing Best Practices. in Health Programmes

Radius Maps and Notification Mailing Lists

How To Interface With A Database Language With A Programming Language (Apl) And A Programming Program (Sql)

Design Patterns in Parsing

Transcription:

Solutions for hw #1 CS441 Fall 04 Internet Section Chapter 1 Q4. What arguments can you make against the idea of a single language for all programming domains? ( 2) Some arguments against having a single language for all programming domains are: The language would necessarily be huge and complex; compilers would be expensive and costly to maintain; the language would probably not be very good for any programming domain, either in compiler efficiency or in the efficiency of the code it generated. Q5. Name and explain another criterion by which languages can be judged (in addition to those discussed in this chapter). (2) One possibility is wordiness. In some languages, a great deal of text is required for even simple complete programs. For example, COBOL is a very wordy language. In Ada, programs require a lot of duplication of declarations. Wordiness is usually considered a disadvantage, because it slows program creation, takes more file space for the source programs, and can cause programs to be more difficult to read. Q8. Many languages distinguish between uppercase and lowercase in user-defined names. What are the pros and cons of this design decision? (2) The reasons why a language would distinguish between uppercase and lowercase in its identifiers are: (1) So that variable identifiers may look different than identifiers that are names for constants, such as the convention of using uppercase for constant names and using lowercase for variable names in C, and (2) So that catenated words as names can have their first letter distinguished, as in Total Words. (I think it is better to include a connector, such as underscore.) The primary reason why a language would not distinguish between uppercase and lowercase in identifiers is it makes programs less readable, because words that look very similar are actually completely different, such as SUM and Sum. Q.10 What are the arguments for writing efficient programs even though hardware is relatively inexpensive?(2) One of the main arguments is that regardless of the cost of hardware, it is not free. Why write a program that executes slower than is necessary. Furthermore, the difference between a well-written efficient program and one that is poorly written can be a factor of two or three. In many other fields of endeavor, the difference between a good job and a poor job may be 10 or 20 percent. In programming, the difference is much greater.

Q.15 How do type declaration statements for simple variables affect the readability of a language, considering that some languages do not require them? (2) The use of type declaration statements for simple scalar variables may have very little effect on the readability of programs. If a language has no type declarations at all, it may be an aid to readability, because regardless of where a variable is seen in the program text, its type can be determined without looking elsewhere. Unfortunately, most languages that allow implicitly declared variables also include explicit declarations. In a program in such a language, the declaration of a variable must be found before the reader can determine the type of that variable when it is used in the program. Q.18 Many contemporary languages allow two kinds of comments, one in which delimiters are used on both ends (for multiple-line comments), and one in which a delimiter marks only the beginning of the comment (for one-line comments). Discuss the advantages and disadvantages of each of these with respect to our criteria. (2) The main disadvantage of using paired delimiters for comments is that it results in diminished reliability. It is easy to inadvertently leave off the final delimiter, which extends the comment to the end of the next comment, effectively removing code from the program. The advantage of paired delimiters is that you can comment out areas of a program. The disadvantage of using only beginning delimiters is that they must be repeated on every line of a block of comments. This can be tedious and therefore errorprone. The advantage is that you cannot make the mistake of forgetting the closing delimiter.

Chapter 2 Q.10 Outline the major motivation of IBM in developing PL/I. (2) The main motivation for the development of PL/I was to provide a single tool for computer centers that must support both scientific and commercial applications. IBM believed that the needs of the two classes of applications were merging, at least to some degree. They felt that the simplest solution for a provider of systems, both hardware and software, was to furnish a single hardware system running a single programming language that served both scientific and commercial applications Q.11 Was IBM s major motivation for developing PL/I correct, given that history of computers and language developments since 1964? (2) IBM was, for the most part, incorrect in its view of the future of the uses of computers, at least as far as languages are concerned. Commercial applications are nearly all done in languages that are specifically designed for them. Likewise for scientific applications. On the other hand, the IBM design of the 360 lines of computers was a great success--it still dominates the area of computers between supercomputers and minicomputers. Furthermore, 360 series computers and their descendants have been widely used for both scientific and commercial applications. These applications have been done, in large part, in FORTRAN and COBOL. Q.14 What are the arguments both for and against the idea of a type less language?(2) The argument for type less languages is their great flexibility for the programmer. Literally any storage location can be used to store any type value. This is useful for very low-level languages used for systems programming. The drawback is that type checking is impossible, so that it is entirely the programmer's responsibility to insure that expressions and assignments are correct. Q.18 Languages continually evolve. What sort of restrictions do you think are appropriate for changes in programming languages? Compare your answer with the evolution of Fortran.(2) A good deal of restraint must be used in revising programming languages. The greatest danger is that the revision process will continually add new features, so that the language grows more and more complex. Compounding the problem is the reluctance, because of existing software, to remove obsolete features.

Chapter 3 Q.2 Write EBNF descriptions for the following: a. A Java class definition header statement (2 each) 2a. <class_head> {<modifier>} class <id> [extends class_name] [implements <interface_name> {, <interface_name>}] <modifier> public abstract final 2c. <switch_stmt> switch ( <expr> ) {case <literal> : <stmt_list> {case <literal> : <stmt_list> } [default : <stmt_list>] } Q.3 Rewrite the BNF of Example 3.4 to give + precedence over * and force + to be right associative. (2 each) <assign> <id> = <expr> <id> A B C <expr> <expr> * <term> <term> <term> <factor> + <term> <factor> <factor> ( <expr> ) <id> Q.6 Using the grammar in Example 3.2, show a parse tree derivation for each of the following statements: ( 2 each) a. A = A * (B + (C * A)) (a) <assign> => <id> = <expr> => A = <expr> => A = <id> * <expr> => A = A * <expr>

=> A = A * ( <expr> ) => A = A * ( <id> + <expr> ) => A = A * ( B + <expr> ) => A = A * ( B + ( <expr> ) ) => A = A * ( B + ( <id> * <expr> ) ) => A = A * ( B + ( C * <expr> ) ) => A = A * ( B + ( C * <id> ) ) => A = A * ( B + ( C * A ) ) <assign> <id> := <expr> <id> * <expr> A ( (expr) ) <id> + <expr> B ( <expr> ) <id> * <expr> C <id> A

Q.7 Using the grammar in Example 3.4, show a parse tree derivation for each of the following statements: (2 each) a. A = (A + B) * C (a) <assign> => <id> = <expr> => A = <expr> => A = <term> => A = <factor> * <term> => A = ( <expr> ) * <term> => A = ( <expr> + <term> ) * <term> => A = ( <term> + <term> ) * <term> => A = ( <factor> + <term> ) * <term> => A = ( <id> + <term> ) * <term> => A = ( A + <term> ) * <term> => A = ( A + <factor> ) * <term> => A = ( A + <id> ) * <term> => A = ( A + B ) * <term> => A = ( A + B ) * <factor> => A = ( A + B ) * <id> => A = ( A + B ) * C

<assign> <id> := <expr> A <term> <factor> * <term> ( <expr> ) <factor> <expr> + <term> <id> <term> <factor> C <factor> <id> <id> B A Q.8 Prove that the following grammar is ambiguous: <S> <A> <A> <A>+<A> <id> <id> a b c (2 each) The following two distinct parse trees for the same string, which proves that the grammar is ambiguous.