CS 4337 - Midterm

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

What types of attributes are used when checking type rules on an assignment statement? <assign> -> <var> = <expr> <expr> -> <var> + <var> | <var> <var> -> A | B | C

(1) actual_type (synthesized attribute associated with non-terminals <var> and <expr>) => in case of variable, actual_type is intrinsic => in case of expression, actual_type determined by types of child/children nodes (2) expected_type (inherited attribute associated with non-terminals <var> and <expr>, stores expected type determined by type on left side of assignment)

What do the following functions do? (A) add1 (B) sub1

(A) (B)

What do the following functions do? (A) even? (B) odd?

(A) (B)

What do the following functions do? (A) list? (B) pair?

(A) (B)

What do the following functions do? (A) string? (B) char?

(A) (B)

What do the following functions do? (A) list (B) quote (C) eval

(A) (B) (C)

What do the following functions do? (A) null? (B) empty? (C) zero?

(A) (B) (C)

What do the following functions do? (A) quotient (B) remainder (C) modulo

(A) (B) (C)

What do the following functions do? (A) integer? (B) real? (C) rational? (D) complex?

(A) (B) (C) (D)

Give examples of ambiguous grammars.

(A) <expr> -> <expr> <op> <expr> | const <op> -> / | - (B) <expr> -> <expr> + <expr> | const

(A) What is the von Neumann bottleneck? (B) Why is it the primary limiting factor in the speed of computers?

(A) Connection speed between computer's memory and processor (B) Program instructions are usually executed much faster than the connection

(A) Define the Right-Hand Side of a BNF definition (B) What is the RHS of <assign> -> <var> = <expression>

(A) Consists of tokens, lexemes, and references to other abstractions (B) <var> = <expression>

(A) What are the characteristics of programming languages in web software? (B) Give an example of a language in the web software domain.

(A) Eclectic collection of languages (B) HTML (markup), PHP (scripting), Java (general purpose)

(A) What version of Fortran was first implemented? (B) What computer was it designed for?

(A) Fortran 1, in 1957 (B) The IBM 704

(A) What does the LISP programming language stand for? (B) Who designed it?

(A) LISt Processing language (B) McCarthy, at MIT

(A) What are the characteristics of programming languages in systems programming? (B) Give an example of a language in the systems programming domain.

(A) Need efficiency due to continuous use (B) C

(A) What does a preprocessor do? (B) When is this done?

(A) Processes a program to expand preprocessor macros. (B) Immediately before the program is compiled.

(A) What are the characteristics of programming languages in business applications? (B) Give an example of a language in the business applications domain.

(A) Producing reports, use of decimal numbers and characters (B) COBOL

(A) A language is characterized by what set? (B) What is the cardinality of this set?

(A) Set of all valid statements (strings) for that language. (B) Potentially infinite

(A) What was the first "pseudocode" language? (B) Who developed this language, and when? (C) What computer was this language designed for? (D) What computer was this language transferred to?

(A) Short Code (B) John Mauchly, in 1949 (C) The BINAC computer (D) The UNIVAC I computer

(A) What are the characteristics of programming languages in artificial intelligence? (B) Give an example of a language in the artificial intelligence domain.

(A) Symbols are manipulated instead of numbers, use of linked lists (B) LISP

What are the two components of a grammar?

(A) Syntax (B) Semantics

(A) Define the Left-Hand Side of a BNF definition (B) What is the LHS of <assign> -> <var> = <expression>?

(A) The abstraction being defined (B) <assign>

(A) What are abstractions in BNF used to represent? (B) What do they act like?

(A) classes of syntactic structures (B) syntactic variables

(A) What are the characteristics of programming languages in scientific applications? (B) Give an example of a language in the scientific applications domain

(A) large amounts of floating-point computations and the use of arrays (B) FORTRAN

Describe the Denotational Semantics approach to dynamic semantics?

- Based on recursive function theory, very complex - Denotational semantics requires one to define for each language entity both a mathematical object and a function that maps instances of the language entity onto instances of the mathematical object - Domain/Syntactic Domain: collection of values that are legitimate parameters to that function - Range/Semantic Domain: collection of objects to which the parameters are mapped

Give an example of an attribute grammar?

- In Ada, the string following "procedure" must match the string following "end" - Syntax rule: <proc_def> -> procedure <proc_name>[1] <proc_body> end <proc_name>[2] - Predicate: <proc_name>[1].string == <proc_name>[2].string

Give a mathematical definition of an attribute grammar.

- Let Grammar = (Start_symbol, Non_terminals, Terminals, Production_rules) - For each grammar symbol x, there is set A(x) of attribute values - each rule has set of functions that define certain attributes of non-ternimals in that rule - each rule has a (possibly empty) set of predicates to check for attribute consistency

Describe the semantic functions of attribute grammar.

- Let x0 -> x1...xN be a BNF rule - Semantic functions of the form S(x0) = f(A(x1), ... , A(xN)) define SYNTHESIZED ATTRIBUTES OF THE LHS (bottom-up) - Semantic functions of the form I(xJ) = f(A(x0), ..., A(xj-1)) define INHERITED ATTRIBUTES OF THE RHS (top-down)

Describe the Axiomatic Semantics approach to dynamic semantics?

- Specifies what can be proven about the program, not the actual meaning - Recall one use of semantics specifications is proving the correctness of a program

Describe the Operational Semantics approach to dynamic semantics?

- describe the meaning of a statement or program by specifying the effects of running it on a machine - The effects on the machine are viewed as the sequence of changes in its state (state = collection of values in storage) - ex: executing compiled version of program

What is an attribute grammar?

1. A device used to describe more of the structure of a programming language than can be described using a context-free grammar 2. An extension to context-free grammar

Give an example of a static semantic rule of a language.

1. A static semantic rule might specify type constraints (context-free, but cumbersome) 2. All variables must be declared before referenced (non context-free)

Describe the Python web scripting language.

1. An OO interpreted scripting language 2. Dynamically typed, but type checked 3. Used for CGI programming and form processing 4. Supports lists, tuples, and hashes

What did plankalkül include, in addition to scalar types?

1. Arrays 2. Records/structs (could include nested records)

What were the two data types in LISP?

1. Atom 2. List (could contain sublists)

What are some examples of imperative programming languages?

1. C 2. C++ 3. C# 4. Objective-C 5. Java 6. Perl 7. Python 8. Ruby 9. JavaScript 10. Visual BASIC .NET

Which two languages did C++ evolve from?

1. C 2. SIMULA 67

What are two uses for the Perl web scripting language?

1. CGI programming on the web 2. Replacement for UNIX system administration language

Describe the JavaScript web scripting language.

1. Client-side HTML-embedded scripting language, used to create dynamic HTML documents 2. Purely interpreted

Describe the environment in which Fortran 1 was designed.

1. Computers were small and unreliable 2. Applications were scientific 3. No programming methodology or tools 4. Machine efficiency was the most important concern

What are some features of von Neumann computers?

1. Data and programs stored in memory 2. Memory is separate from CPU 3. Instructions and data are piped from memory to CPU

What did the Java language contribute to the field of computing?

1. Eliminated many unsafe features of C++ 2. Supports concurrency 3. Libraries for applets, GUI, database access 4. Portability (JVM, JIT compilers) 5. Widely used for web programming

Reasons for studying concepts of programming languages?

1. Increased capacity to express ideas 2. Improved background for choosing appropriate languages 3. Increased ability to learn new languages 4. Better understanding of the significance of implementation 5. Better use of languages that are already known 6. Overall advancement of computing

What were two features of the IBM 704?

1. Index Registers 2. Floating-Point Hardware

What is Backus-Naur Form?

1. Invented by John Backus to describe syntax of ALGOL 58 2. EQUIVALENT TO CONTEXT-FREE GRAMMARS 3. A Metalanguage (language to describe other languages)

What are some examples of functional programming languages?

1. LISP 2. Haskell 3. Racket (PLT Scheme) 4. Clojure 5. Scala 6. ML 7. F#

What is a context-free grammar?

1. Language generators, meant to describe the syntax of natural languages 2. Define a class of languages called context-free-languages

What are the central features to functional programming languages?

1. Main means of making computations is by applying functions to given parameters 2. Functions are "first class citizens" 3. "Variables", functions, and names 4. Lambda Calculus

What were the design goals of the COBOL programming language?

1. Must look like simple English 2. Must be easy to use, even if less powerful 3. Must broaden the base of computer users 4. Must not be biased by current compiler problems

How did its environment impact the design of Fortran 1?

1. No need for dynamic storage 2. Need good array handling and counting loops 3. No string handling, decimal arithmetic, or powerful input/output (for business software)

How did LISP pioneer functional programming?

1. No need for variables or assignments 2. Control via recursion and control expressions

Which two features did Smalltalk heavily promote?

1. Object-Oriented Programming 2. Graphical User Interface

What are three approaches to dynamic semantics?

1. Operational Semantics (platform specific description) 2. Denotational Semantics (mathematical description) 3. Axiomatic Semantics (logical description)

What does EBNF add to BNF?

1. Optional parts (0 or 1 occurrences) <proc_call> -> ident [<expr_list>] (may or may not be list) 2. Repetitions (0 to many occurrences) <ident_list> -> <identifier> { , <identifier> } 3. When a single item must be chosen from a group, these items are placed in parentheses and separated by or bars <term> -> <term> (* | / | %) <factor>

What contributions did the Ada language make?

1. Packages (support for data abstraction) 2. Exception handling (elaborate) 3. Generic program units 4. Concurrency (through the tasking model)

Describe the C# language.

1. Part of .NET development platform 2. Based on C++, Java, and Delphi 3. Includes pointers, delegates, properties, enumeration types, limited dynamic typing, anonymous types 4. Is evolving rapidly.

The Ruby scripting language was originally intended to replace what two languages?

1. Perl 2. Python

What are the drawbacks of using machine code (instead of a higher-level language)?

1. Poor readability 2. Poor modifiability 3. Expression coding was tedious 4. Machine deficiencies (no indexing or floating point)

What are the two distinct applications of axiomatic semantics?

1. Program verification 2. Program semantics specification

Describe the Ruby web scripting language.

1. Pure OO scripting language (all data are objects) 2. Most operators implemented as methods, which can be redefined by user code 3. Purely interpreted

What criteria is used to evaluate a programming language?

1. Readability 2. Writability 3. Reliability

Grammars can be formally utilized in what two ways?

1. Recognition 2. Generation

What are the central features to logical programming languages?

1. Rule-based (rules are specified in no particular order) 2. First order logic 3. Boolean expressions

Five programming domains?

1. Scientific Applications 2. Business Applications 3. Artificial Intelligence 4. Systems Programming 5. Web Software

What criteria is used to evaluate the readability of a programming language?

1. Simplicity 2. Orthogonality 3. Data Types 4. Syntax Design

What criteria is used to evaluate the writability of a programming language?

1. Simplicity 2. Orthogonality 3. Data Types 4. Syntax Design 5. Support for Abstraction 6. Expressivity

What criteria is used to evaluate the reliability of a programming language?

1. Simplicity 2. Orthogonality 3. Data Types 4. Syntax Design 5. Support for Abstraction 6. Expressivity 7. Type Checking 8. Exception Handling 9. Restricted Aliasing

Give some situations for which the pure interpretation implementation method is well-suited.

1. Small Programs 2. When efficiency is not an issue

Give examples of language rules that can be described by attribute grammars.

1. Type compatibility

Describe the Perl language (scripting web language)?

1. Variables are statically typed but implicitly declared 2. Three distinctive namespaces, denoted by first character of a variable's name 3. Powerful, but somewhat dangerous

Which features of C++ did Java choose not to implement?

1. struct, union, enum, half the assignment coercions of C++ 2. Supports only OOP 3. Has references, but not pointers 4. Includes support for applets and a form of concurrency

Remove the ambiguity of this grammar: <expr> -> <expr> + <expr> | const

<expr> -> <expr> + const | const

Remove the ambiguity of this grammar: <expr> -> <expr> <op> <expr> | const <op> -> / | -

<expr> -> <expr> - <term> <term> -> <term> / const | const

Convert the following EBNF rule to BNF <ident_list> -> <identifier> {, <identifier> }

<ident_list> -> <identifier> | <identifier>, <ident_list>

Describe a syntactic list using recursion.

<ident_list> -> ident, <ident_list> | ident

Convert the following BNF rule to EBNF <if_stmt> -> if (<expr>) <stmt> | if (<expr>) <stmt> else <stmt>

<if_stmt> -> if (<expr>) <stmt> [else <stmt>]

Convert the following EBNF rule to BNF <proc_call> -> ident [<expr_list>]

<proc_call> -> ident | ident (<expr_list>)

Combine these two abstractions into a single abstraction: <stmt> -> <single_stmt> <stmt> -> begin <stmt_list> end

<stmt> -> <single_stmt> | begin <stmt_list> end

Convert the following BNF rule to EBNF <term> -> <term> * <factor> | <term> / <factor> | <term> % <factor>

<term> -> <term> (* | / | %) <factor>

What was the simplest data type in plankalkül?

A bit (integer and floating point numeric types were built from the bit).

What is a token?

A category of lexemes ("identifier", etc.)

Describe the hybrid method of implementing programming languages.

A compromise between compilers and pure interpreters.

What is a language generator?

A device that generates sentences of a language.

What is a grammar?

A formal description of a language. It must have a finite set of rules.

What conditions must be met in order for a grammar to be ambiguous?

A grammar is ambiguous iff it generates a sentence that has two or more parse trees.

Suppose a grammar G is used to generate language L. Given G, what can be constructed?

A recognizer for language L

What was the SNOBOL language originally designed for?

A string manipulation language (powerful operators for string pattern matching)

Understand basic functional recursion, including the use of accumulators.

ANS

Understand control flow using if and cond keywords

ANS

Understand define and let syntax.

ANS

What do the following function do? filter

ANS

What do the following function do? length

ANS

What do the following function do? list-ref

ANS

What do the following function do? map

ANS

What do the following function do? range

ANS

What do the following function do? reverse

ANS

What does the cons function do?

ANS

(A) What does the car function do? (B) What is another name for this function?

ANS (B) first

(A) What does the cdr function do? (B) What is another name for this function?

ANS (B) rest

Be able to "decorate" attributes attributes of a parse tree given: (A) a set of BNF syntax rules (B) a set of semantic rules (C) a set of predicates

ANSWER FIGURE 3.6, 3.7, 3.8

Which programming language included all that was known (at the time) about software engineering?

Ada

Which programming language is the result of the most extensive and expensive language design effort ever undertaken?

Ada

Describe the Prolog programming language.

An intelligent database system that uses an inferencing process to infer the truth of given queries. It is non-procedural, and was comparatively inefficient

What programming domain was LISP developed for?

Artificial Intelligence

Define an attribute grammar, in English.

Associated with each grammar rule is: 1. A set of semantic functions (synthesized and/or inherited) 2. A possibly empty set of predicate functions over the attributes of the symbols in the grammar rule

Where and when was the Scheme language developed?

At MIT, in the mid 1970's

How does optimization improve a program?

By making them smaller, faster, or both.

Why was the Java language developed?

C and C++ were not satisfactory for embedded electronic devices.

How can one determine the syntactic correctness of a particular sentence?

Compare it to the structure of a language generator.

What are the three implementation methods of programming languages?

Compilation Pure interpretation Hybrid

Who is Ada Lovelace?

Created the first programming language, to be used with Charles Babbage's analytical engine.

Who is John von Neumann?

Creator of the von Neumann computer architecture, which is still the prevalent architecture today.

A grammar is a generative device for defining languages. The sentences of the language are generated through a sequence of applications of the rules, starting at the start symbol. What is this sequence of rule applications called?

Derivation.

Who is Donald Knuth?

Designed the original LR algorithm (canonical LR) for LR parsers and attribute grammars

What is the sequential form of a grammar?

Each of the strings in the derivation.

Why was plankalkül hard to read?

Each statement contained 2-3 lines of code Line 1: expression Line 2: subscripts Line 3: data types

Which language was COBOL based upon?

FLOW-MATIC.

How is a context-free grammar described?

G = (S, N, T, P) where: G => Grammar S => Start symbol N => Set of non-terminals T => Set of terminals P => Sets of production rules

Who is Charles Babbage?

He invented the analytical engine (the first mechanical computer). He is known as "the father of the computer."

What is another way to know if a grammar is ambiguous?

If the grammar generates the sentence with more than one leftmost or more than one rightmost derivation

What are languages designed around the von Neumann architecture called?

Imperative languages.

Why is improved background for choosing appropriate languages important?

It is preferable to use a feature whose design has been integrated into the language than to use a simulation of that feature. Many programmers have had little formal education in computer science, and many choose to use familiar languages inappropriate for certain projects.

Why is C++ such a large and complex language?

It supports both procedural and object-oriented programming.

What was the syntax of LISP based on?

Lambda Calculus.

Give a situation for which the compilation implementation method is well-suited.

Large commercial applications

When was structured programming prevalent?

Late 60's - Early 70's.

When was procedure-oriented programming prevalent?

Late 70's - Early 80's.

When was data-oriented software development (object-oriented design) prevalent?

Late 80's - Present

What type of recursion specifies left operator associativity?

Left-recursion.

What are the types of derivation?

Leftmost and Rightmost.

What is the static semantics of a program related to?

Legal forms of programs (syntax rather than semantics)

What is a lexeme?

Lowest level syntactic unit of a language (e.g. if, myVar)

How long did it take for Ada compilers to be released, after the languages completion?

Nearly five years.

Is derivation part of a grammar itself?

No, it is a method that determines the order of grammar rules when executing a parse.

Is the type of recursion of a rule determined by when that rule is applied in the order rules of derivation?

No.

How is JavaScript related to Java?

Only though similar syntax.

Grammars naturally describe the hierarchical syntactic structure of the sentences of the languages they define. What are these hierarchical structures called?

Parse trees.

Which programming language was designed by Niklaus Wirth for teaching structured programming?

Pascal

What was a drawback to the C language?

Poor type checking

What was a strength that the C language possessed?

Powerful set of operators

Describe the pure interpretation method of implementing programming languages.

Programs are interpreted by another program (the "interpreter")

Describe the compilation method of implementing programming languages.

Programs are translated into machine language before execution.

What is an example of a logical programming language?

Prolog

What is a language recognizer?

Reads input strings over the alphabet of the language and decides whether the input strings belong to the language.

What are the types of recursion?

Right Recursive and Left Recursive

What type of recursion specifies right operator associativity?

Right-recursion.

Give one performance tradeoff of the compilation implementation method.

Slow translation, fast execution.

Give a situation for which the hybrid implementation method is well-suited.

Small and medium systems when efficiency is not the first concern.

What was the first full implementation of an object-oriented language?

Smalltalk

What is another term for attribute grammars?

Static Semantics

Give an example of a language recognizer.

Syntax analysis part of a compiler.

What was the C programming language designed for?

Systems programming.

What is the name of the "pseudocode" system, developed by John Backus in 1954, that extended machine languages to include floating point calculations?

The Speedcoding System.

What is a defining characteristic of the von Neumann architecture?

The fetch-execute cycle.

What did "pseudocode" refer to in the 1940's and 1950's?

The first higher-level (relative to machine code) languages developed in response to machine code's deficiencies.

What is syntax?

The formal method to describe how to determine a statement's set membership (the form or structure of the expressions, statements, and program units)

Which non-terminal symbol is evaluated first in a leftmost derivation?

The furthest left non-terminal.

Which non-terminal symbol is evaluated first in a rightmost derivation?

The furthest right non-terminal.

Who is John Backus?

The inventor of the Backus-Naur Form, a notation used to define formal language syntax.

What is semantics?

The meaning of the expressions, statements, and program units

What are dynamic semantics?

The meaning of the expressions, statements, and program units in a programming language.

What does derivation determine?

The order that nodes of a parse tree are built (which non-terminal symbol is expanded at each derivation step).

What does the type of recursion determine?

The shape of the parse tree (recursion occurs on the left child node vs the right child node)

What affects operator associativity in a BNF grammar?

The type of recursion (left associative operators are implemented using left recursion, right associative operators are implemented using right recursion)

What does derivation not affect?

The ultimate shape of the parse tree.

Most of the popular languages of the past 50 years have been designed around which architecture?

The von Neumann architecture.

How did Fortran 1 and the IBM 704 lead to the idea of compiling programming languages?

There was no place to hide the cost of interpretation (no floating-point software).

How was the C language initially spread?

Through UNIX

What does a compiler do?

Translate a high-level program (source code) into machine code (machine language).

How can ambiguity be eliminated from a grammar?

Use the parse tree to indicate precedence levels of operators.

How do you know if a grammar rule is left recursive?

When the LHS appears at the left end of the RHS (per rule) ( <x> -> <x> + <y> AND <x> -> <y> | <x> + <z>)

How do you know if a grammar rule is right recursive?

When the LHS appears at the right end of the RHS (per rule) ( <x> -> <y> + <x> AND <x> -> <y> + <x> | <y>)

Is LISP still the dominant language for AI?

Yes.

Is type of recursion part of the structure of a grammar rule?

Yes.

Provide pseudocode for the fetch-execute cycle.

initialize the program counter repeat forever => fetch the instruction pointed to by the counter => increment the counter => decode the instruction => execute the instruction end repeat


Kaugnay na mga set ng pag-aaral

Ch. 12.3- Investing in Equities, Futures, and Options

View Set

A Level Geography - Hazardous Earth Continued

View Set

III (Infection, Inflammation, & Immunity)

View Set

2019 UNMC PCC 2 Clinical Judgment

View Set