ProgrammingLanguageFinalExam

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

Definition and significance of data type. Give examples

- A collection of data objects and a predefined operations on those objects - Must match the objects in the real world

Convert an ambiguous grammar into an unambiguous grammar

- A semantics issue is the order of evaluation of two operators

Different between terminal and non-terminal symbols. Give example

- A terminal symbol represents a single element of the language, and a non-terminal symbol represents several elements

Reliability criteria

- Able to develop crash proof code in a language - Type Checking: type-error, compile-time type error (less expensive) - Exception handling - Aliasing (VERY BAD) - Readability and writability influence Reliability

What are lexical and syntax analyzers usually used for? (Select all that apply)

- As an application of grammars - compiler design - program formatters - interpreter design

Describe and give examples of BNF and EBNF

- BNF: abstractions used to represent syntactic structures. Also multiple rules and single rules - EBNF: used to make a formal description of a formal language such as a computer programming language. EX: like a list

Pattern matching in different languages

- C++, Java, python, C#, and F#: use class libraries - Pear, JavaScript, Ruby, and PHP: use Java Regex

Difference between a regular grammar and context free grammar. Give an example

- CFG: describe syntax of programming languages - Regular grammar: it can be described in terms of regular expressions

Explain different language implementation methods and state the difference

- Compilation - Pure interpretation - Hybrid implementation system - JIT implementation system

Problem with an ambiguous grammar

- Compiler often base the semantics of those structures on their syntactic form - Compiler chooses code to be generated for a statement by examining its parse tree - cannot be determined uniquely

Difference between Decimal data type and Integer data type

- Decimal: stores a fixed number of decimal digits - Integer: whole numbers

Writability criteria

- Ease with which a language can be used to create programs - Simplicity and orthogonality - Expressivity - EX: C, count++ more convenient than count = count + 1

Readability criteria

- Ease with which programs can be read and understood and must be considered in the context of the problem domain - Overall simplicity - minimal feature multiplicity - minimal operator overloading - Orthogonality - Data types - Syntax design - EX: IBM main frames, VAX

Types of languages

- Imperative - Declarative - Functional: applying functions to a given parameter - Logic: Rule-based

Difference between imperative and declarative programming language

- Imperative: Statements to change a programs state. how a program operates. Variables, assignment statements, and iteration - Declarative: Focus on accomplishing goal without specifying how

Users of a language definition are (Select all that apply)

- Implementers of the language - Other language designers - Programmers - Compiler and interpreter creators

The study of programming languages is valuable for a number of reasons: (select all that apply)

- Increase our ability to use different constructs - Enable us to choose languages more intelligently - Makes learning new languages easier

Some reasons for studying concepts of programming languages are

- Increased ability to learn new languages - Better use of languages that are already known

Who are the different people who must understand the description of a programming language? What are their roles

- Initial evaluators: (evaluate a design as it develops) - Implementors: (determine how a language structure is formed, and also their intended effect when executed) - Users (write programs using reference manuals)

Common data types, and definition and structure of each data type

- Integer, Floating point, complex, decimal, boolean, character, string, ordinal, enumeration

Describe a parse tree

- Is a hierarchical representation of a derivation - Every internal node of a parse tree is labeled with a nonterminal symbol - Every leaf is labeled with a terminal symbol

What are binding and different binding times? Give examples

- Is an association between an entity and an attribute EX: between a variable and its type or value EX: Or, between an operation and its symbol - Language design time: bind operator symbols to corresponding operations - Language implementation time: bind floating point type to a representation - Compile time: bind a variable to a type - Load time: bind a C or C++ static variable to a memory cell -Runtime: bind a nonstatic local variable to a memory cell

Difference between rightmost and leftmost derivation

- LMD: leftmost nonterminal in each sentential form is expanded - RMD: rightmost nonterminal in each sentential form is expanded

define the terms: language, lexeme and token. Give an example of each

- Language: set of sentances - lexeme: lowest level syntactic unit of a language (sum, begin) - token: category of a lexeme (identifier)

Phases of compilation process

- Lexical analysis: converts char into lexical units - Syntax analysis: lex units into parse tree - Semantics analysis: generate immediate code - code generation: machine code is generated

Different types of parsers

- Recursive decent parser - Back-tracking - Predictive Parser

Different approaches to building lexical analyzers

- Regular Expressions: formal description of the token patterns. use this description as input to a software tool that automatically generates a lexical analyzer - State transition: state transition diagram to describe the token patterns - Table-driven implementations of the state transition diagram:

Describe language design trade-off

- Reliability vs cost - Reliability vs writability - writability vs flexibility

Programming domains

- Scientific application: Fortran, large numbers of floating point computation - Business application: COBOL, Produce reports - AI: Symbols rather than numbers manipulated; use of linked lists - Systems programming: C, efficiency - Web software: java etc..., common sense

Why should we keep lexical analyzer and parser separate

- Simplicity, Efficiency, Portability - Lexical analysis: small-scale language constructs (names, numeric literals) - Syntax analysis (parser): large-scale constructs (expressions, statements, and program units)

A language implementer usually uses any of the following approaches to represent dynamic-length strings in memory. (select the correct answers)

- Store characters of the string in adjacent storage cells - Use arrays of pointers to individual characters of the string - Use a linked list of characters

character coding systems

- Stored as numeric coding system - ASCII (8bits), UCS-2 (16bits), UCS-4 (32bits)

What is the difference between syntax and semantics of a programming language? Give an example

- Syntax: the form or structure of the expression, statements, and program units - Semantics: the meaning of the expressions, statements, and programming units

Difference between terminal and nonterminal symbols in BNF. Give example

- Terminals have an end - Non-terminals don't have an end

Definition of character strings, character string operations, and representation of character strings in different programming language

- Values: a sequence of characters - Operations: Assignment and copying, Comparison, Catenation, Substring reference, pattern matching - Representation: C and C++ -> use char arrays and library functions. String are terminated by null character Java -> Primitive via string class

Definition and structure of variable

- Variable: abstraction of a memory cell of collection of cells - names, address, type, value, lifetime, scope

How do computer architecture and program design methodologies influence the design of a programming language

- Von Neuman or Stored Program architecture

Difference between compilation, linking, loading and execution

- compilation: Convert the source code to object or machine code - linking: Convert object code to executable code by linking multiple units of object codes together - loading: Load the executable code into memory for execution - execution: Retrieve the instructions from the memory and execute them

What is a recursive descent parser? Why is it recursive?

- consists of a collection of sub-programs, many of which are recursive, and it produces a parse tree in top-down order - There is a subprogram for each non-terminal of the grammer

Determine if a given grammar is ambiguous

- if and only if it generates a sentence that has two or more distinct parse trees - more than one leftmost derivation - more than one rightmost derivation

Reason for studying concepts of programming language

- increase ability to express ideas - Improved background for choosing appropriate languages - Increased ability to learn new languages

The TIOBE programming community index

- indicator of the popularity of programming language - updated once a month - rating based on number of skilled engineers

Criteria used to evaluate programming languages

- readability - writability - reliability - cost

implementation of character strings

- static length string: Needs a compile time descriptor - limited dynamic length string: May need a run-time descriptor (but not for C and C++) - dynamic length string: Need run-time descriptor

Different ways of determining lengths of the character strings

- static length: string length is set when the string is created EX: Java - Limited Dynamic Length: string variables can be stored between 0 and a fixed maximum set by the variables definition (one with the null character C or C++) - Dynamic Length: strings can have varying lengths with no maximum

Difference between static binding and dynamic binding. Give examples

- static: first occurs before run time - dynamic: first occurs during execution

Cost criteria

- ultimate total cost - Training programs - Writing programs - Compiling programs - Execution - Language implementation - Reliability - Maintenance - Development, maintenance, reliability

When is type checking done in a programming language

- usually done at compile time

Difference between left-and right-recursive rules. Give example

-right recursive: specify right associativity. EX: Non-terminal symbol in LHS also appears at the right end of its RHS - opposite of above

What is a rule in BNF

<assign> -> <var> = <expression>

Which EBNF rule is equivalent to the following BNF rule? (Select all that apply) <term> → <term> + <factor> | <term> - <factor>

<term> -> <term> (+/-) <factor> <term> -> <term> (-/+) <factor>

Difference between a sentential form and a sentence

A sentence is a sentential form that has only terminal symbols

The following pattern matches a string which consists of/​[A-Z\d]+/

A sequence of one or more digits an upper-case letters

Type checking in a programming language can be done during: (select all that apply)

Compilation and Execution

The following characteristics increase reliability of a program: (select all that apply)

Exception handling, Compile-time type checking, Run-time checking

in a dynamic length string, the string length is fixed when the string is created. (true/false)

False

How are the instructions executed on Von Neumann computers ?

Fetch-execute cycle

What is a grammar and how is it formally described?

Formal language-generation mechanism that are commonly used to describe the syntax of programming languages

What is derivation? Give an example

It is a repeated application of rules, starting with the start symbol and ending with a sentence <program> => <begin> <stmt_list> end etc...

The task of analyzing syntax is separated into the following parts (Select all that apply)

Lexical analysis, syntax analysis, parsing

The following help achieve simplicity in a language:

Minimal operator overloading

What is a preprocessor? Give an example

Preprocesses a program immediately before the program is compiled to expand embedded preprocessor macros EX: C -> #include "myLib.h"

The statemnet "if (Boolean_expr) statement" (Select all that apply)

Shows syntax and statement of the if-expression

definition and examples of signed and unsigned integer types

Shows that a number is pos or negative. Usually 1 bit represents this

A --> <B> + C is a valid BNF rule. (true/false)

false

All the real numbers can be represented precisely using floating point data types. (true/false)

false

C and C++ require a compile-time descriptor instead of a run-time descriptor (true/false)

false

Characteristics of readability are the same as those of writability (true/false)

false

Context-free grammars were initially developed to describe programming languages. They were later used to describe natural languages such as English. (true/false)

false

Dynamic Binding occurs at compile time and stays unchanged throughout program execution. (true/false)

false

One of the approaches to building a parser vs. a lexical analyzer is use of a state diagram (true/false)

false

Strings are primitive types in all programming languages. (false/true)

false

The integer literal 368 is a data type, which refers to all whole numbers on a computer. (true/false)

false

The term variable refers to only a name which identifies a memory cell or collection of cells. (true/false)

false

An example of binding is association between a variable named counter, and its type, int. (true/false)

true

Associativity rules are used to express precedence among arithmetic operators. (true/false)

true

BNF can be used to specify the grammar of a programming language (true/false)

true

Binding of an entity such a variable to an attribute such as its type can happen during compile time. (true/false)

true

Dynamic length strings are usually more costly in terms of efficiency and memory than the static length strings. (true/false)

true

In an arithmetic expression, an operator, which is generated lower in the parse tree indicate that it has precedence over an operator produced higher up in the tree. (true/false)

true

Integer data types represent a set of whole numbers (vs. decimal numbers) and corresponding operations. (true/false)

true

Orthogonality is one of the characteristics contributing to the readability of a language. Orthogonality refers to having a small number of primitive constructs, which can be combined in a small number of ways to build the structures of a language. (true/false)

true

Syntax analyzer receives a token from the lexical analyzer (true/false)

true

The address attribute of a variable refers to the memory address to which the variable is associated with. (true/false)

true

Use of a Boolean data type (e.g., Boolean finished = true) instead of an integer data type (e.g., integer finished = 1) in defining variables, which can store only one of two values usually help the readability of a program. (true/false)

true

User-defined operator overloading may harm the readability of a program? (true/false)

true

Von Neumann computer architecture was the basis of design of imperative languages (true/false)

true

What is an associativity rule?

used to express precedence among arithmetic operators


Set pelajaran terkait

Careers, Salaries, and Lifetime Income

View Set

electrical signaling by neurons part 1

View Set

Great Depression/New Deal Review

View Set

Writing and Evaluating Expression

View Set

Chapter 12: Health Promotion of the Toddler and Family

View Set

Chapter 18 cost accy dynamic study module

View Set

Unlv Kin 223 Chapter 1 study guide

View Set