Quiz 1 for Organization of Programming Languages
Language Categories
- Imperative - Functional - Logic - Markup/programming Hybrid
Grammar Ambiguity
2 or more distinct parse trees
BNF equivalent to <ident_list> → <identifier> {, <identifier>} (Be able to convert either direction to/from BNF-EBNF)
<ident_list> → <identifier> | <identifier> , <ident_list>
BNF equivalent to <proc_call> → ident [(<expr_list>)]
<proc_call> → <ident> | <ident> <expr_lists>
BNF equivalent to <term> → <term> (+|-) const (Be able to convert either direction to/from BNF-EBNF)
<term> → <term> + const | <term> - const
optomization
A collection of techniques that compilers may use to decrease the size and/or increase the execution speed of code
Hybrid Implementation Systems
A compromise between compilers and pure interpreters Use: Small and medium systems when efficiency is not the first concern
Blocks
A method for creating static scopes inside program units
Explicit Declaration
A program statement used for declaring the types of values
Portability
A property of a program that can run on more than one kind of computer.
<if_stmt> → if <logic_expr> then <stmt> if <logic_expr> then <stmt> else <stmt>
An Unambiguous Grammar for if-then-else
Byte code instructions
Are read and interpreted by the JVM
Binding
Association between an attribute and an entity, such as between a variable and its type or value, or between an operation and a symbol.
Why is type checking the parameters of a subprogram important?
Because run-time type checking is expensive.
Why is it useful for a programmer to have some background in language design, even though he or she may never actually design a programming language?
Because understanding the basic makes it easier ti learn and adopt new languages. it also helps to design and develop more better software. programmer's need to understand how their code will work to ensure it is fault tolerant and high performing.
Load Time
Bind a C or ++ static variable to a memory cell
Global Scope
C and C++ have both declarations and definitions of global data
what are the three general methods of implementing a programming language?
Compilation,pure interpretation, hybrid implementation systems
What produces faster program execution, a compiler or a pure interpreter?
Compiler.
Backus-Naur Form (BNF) is equivalent to
Context-Free Grammars
What are the three fundamental features of an object oriented programming language
Data abstraction,inheritance and dynamic (run-time) metho
Plankalkul
Designed by Konrad Zuse
attribute grammar
Device used to describe more of the structure of a programming language than can be described with a context-free grammar.
regular language
Finite automaton can be designed to recognize members of a class of regular language. The tokens of a programming language are regular language and a lexical analyzer is a finite automaton
A device that generates sentences of a language (one can determine if the syntax of a particular sentence is syntactically correct by comparing it to the structure of the generator
Generators
Context Free Grammar syntax
Grammar = (Start symbol, set of Non-terminals, set of Terminals, set of Production Rules)
What is aliasing?
Having two or more distinct referencing methods, or names, for the same memory cell
Type Binding
How is the type specified? When does the binding take place? IF static, specified by either an explicit or an implicit declaration.
Dynamic Binding
IF it occurs during execution or can change during execution of the program
Static Binding
If it occurs before run time and remains unchanged throughout program execution
What does it mean for a program to be reliable?
If it performs to its specifications under all conditions.
What is the disadvantage of having too many features in a language?
If you have multiple ways to accomplish a task, it makes it harder to learn a language and makes it less readable
How can user-defined operator overloading harm the readability of a program?
It could end up confusing the author or someone reading the code later on.
How can knowledge of programming language characteristics benefit the whole computing community?
It will provide insight on what functionally that certain languages provide works well, and what doesn't work well. this also will allow programmers design languages that contain the great characteristics of languages.
which language has grammar based on predicate logic
LOGLAN (logical languages, also include Lojban and Ceqli)
On what branch of mathematics is axiomatic semantics based?
Logic (logical description)
Are internal nodes terminal or nonterminal
Nonterminal
Three approaches to Dynamic Semantics:
Operational, Denotational and Axiomatic Semantics
what is operational semantics based on ?
Platform specific description
___ device reads input strings over the alphabet of the language and decides whether the input strings belong to the language (i.e.syntax analysis part of a compiler)
Recognition device
On what branch of mathematics is denotational semantics based?
Recursive Function Theory (mathematical description)
what is an example of two language design criteria that are in direct conflict with each other?
Reliability and cost of execution
What role does the symbol table play in a compiler?
Serves as a database for the compilation process in a compiler.
State Diagram
Shows the ways that a program could progress from each state to other states.
Are leafs terminal or nonterminal
Terminal
What is exception handling?
The ability of a program to intercept run time errors
How is the cost of compilers for a given language related to the design of the language?
The design of the language coulf affect how a program is executed. A program that requires many run time type check might require a higher quality compiler
Why is readability important to writability?
The easier it is to read, the easier it is to write, and the more reliable it is.
Linking and loading
The process of collecting system programs and linking them to user programs
What primitive control statement is used to build more complicated control statements in languages that lack them?
The selection statement plus GOTO is used to build more complicated control statements such as FOR loop
Why is the von Neumann bottleneck important?
The separation between the CPU and memory leads to the von Neumann bottleneck, the limited throughput(data transfer rate) between the CPU and memory compared to the amount of memory. Since CPU speed and memory size have increased much faster than the throughput between them, the bottleneck is an important problem.
Syntax Analysis
The stage in compilation where language statements are checked against the rules of the language, errors being reported if a statement is not valid.
Binding Time
Time at which binding takes place.
Let Construct
Two Parts 1. binds names to values 2. uses the names defined in the first part
What is the primary use of attribute grammars?
Type compatibility
Poor readability Poor modifiability Expression coding tedious Machine deficiencies
What's wrong with machine code?
Operator Precidence
When certain operation have precidence over others
Exception Handling
When there's an error, the program makes an error object and passes it off to the runtime system, which looks for a method in the call stack to handle it.
parse tree
a data structure that shows how a statement in a language is derived from the context-free grammar of the language; it may be annotated with additional information, e.g. for compilation purposes.
Implicit Declaration
a default mechanism for specifying types of variables through default conventions, rather than declaration statements
preprocessor
a program that processes a program immediately before the program is compiled
valid sentence
a sentential form that as only terminal symbols
define language
a set of sentences (characterized by the set of all valid statements / strings in that language. The cardinality of this set is potentially infinite)
define sentence
a string of characters over some alphabet
What is an example of a lack of orthogonality in the design of C?
a+b. If the data types are different, it affects the result
define non-terminal symbols
abstractions are used to represent classes of syntactic structures; they act like syntactic variables (often enclosed in angle brackets <>)
Dynamic Scope
based on the calling sequence of subprograms, not on their spatial relationship to each other. Thus the scope can be determined at run time.
Be able to use recursive BNF rules to describe lists of arbitrary length means:
be able to describe the list of potential sentences in the language generated by a particular grammar
Runtime
bind a non-static local variable to a memory cell
Compile Time
bind a variable to a type in C or Java
Language Implementation Time
bind floating point type to a representation
Language Design Time
bind operator symbols to operations
extended BNF rules: repetitions (0 to many occurrences) are placed inside ____
braces { }
extended BNF rules: optional parts (0 or 1) are placed in ___
brackets [ ]
define token
category of lexemes (i.e. noun, verb; descriptions of lexeme etc.)
What have been the strongest influences on programming language design over the past 60 years?
computer architecture, von neumann
define leftmost derivation
derivation in which the leftmost nonterminal in each sentential form is the one that is expanded (expand leftmost nonterminal first)
define derivation (given a set of grammar rules know how to give derivation)
determines the order that nodes of a parse tree are built (repeated application of rules, starting with the start symbol and ending with a sentence with all terminal symbol)
define recursion (syntactic lists are described using recursion)
determines the shape of the parse tree
define sentential form
every string of symbols in a derivation
define rightmost derivation
expand rightmost nonterminal first
Top-down parser
expands nonterminals to match incoming tokens and directly construct a derivation
define attribute grammar (also called Static Semantics)
extension to a CFG (context-free grammar; includes for each grammar symbol x there is a set A(x) of attribute values; each rule has a set of functions that define certain attributes of the nonterminals in the rule; each rule has a set of predicates to check for attribute consistency)
Extended BNF
few simple extensions to BNF which make expressing grammars more convenient; adds "syntactic sugar"
define grammar
formal description of a Language (must a have a finite non-empty set of rules)
what is the formal language-generation mechanism commonly used to describe the syntax of programming languages?
grammars
define parse tree (Be able to draw a parse tree to visualize a derivation)
hierarchical representation of a derivation
how can we eliminate ambiguity? (Be able to define or modify operator precedence in a BNF grammar)
if we use the parse tree to indicate precedence levels of the operators (operator precedence)
What is the name of the category of programming languages whose structure is dictated by the von Neumann computer architecture?
imperative
What two programming language deficiencies were discovered as a result of the research in software development in the 1970s?
incompleteness of type checking inadequacy of control statements
semantic functions of the form I(Xj) = f(A(X0), ..., A(Xn)), for 1 ≤ j ≤ n, define ___ attributes of the ___ (top-down)
inherited; RHS
a grammar is ambiguous if and only if: (Be able to prove ambiguity in a grammar, with Proof By Contradiction)
it generates a sentential form that has two or more distinct parse tree
Metalanguage
language that is used to describe another language
define lexeme
lowest level syntactic unit of a language (for example a word; i.e. ?, variableName, dog)
is it true that an abstraction (or nonterminal symbol) can have only one RHS
no
What are the advantages in implementing a language with a pure interpreter?
one of the advantages of implementing a language with a pure interpreter is easy implementation of many source-level debugging operations, because all run-time errors can refer to the source-level units. An example of this is an array index is found to be out of range.
which semantics is to describe the meaning of a statement or program by specifying the effects of running it on a machine
operational semantics
extended BNF rules: alternative part of RHSs are placed inside ___ and separted via ___ ___
parentheses; vertical bars
grammars can be formally utilized in two distinct ways: for ____ and for ___. (two approaches to describing syntax)
recognizers; generators
left associativity
rule that orders from the left operations that include multiple operators from the same precedence level.
Right associativity
rule that orders from the right operations that include multiple operators from the same precedence level.
operator associativity
rules determining the order in which operations of the same precedence are performed.
Each Production Rule has: •a left-hand side (LHS), which is a ___ ___, and •a right-hand side (RHS), which is a ___ of ___ and/or ___
single non-terminal; string of terminals and/or non-terminals
What language was the first to support the three fundamental features of object oriented programming?
smalltalk
what are the primary values of attribute grammars
static semantics specification and compiler design (static semantics checking)
find weakest precondition by
substitute sequence with the variable in the postcondition: (single statement ex. a = b+1 {a >1} b+1 > 1 b > 0 is precondition) (multiple statement ex. y=3*x+1; x=y+3 {x < 10} y+3 < 10 y < 7 3*x+1 < 7 3x < 6 x < 2 is precondition)
semantic functions of the form S(X0) = f(A(X1), ..., A(Xn)) define ___ attributes of the ___ (bottom-up)
synthesized; LHS
what does a linker do?
takes one or more object files generated by a compiler and combines them into a single executable file
define syntax
the form or structure of the expressions, statements and program units (formal method to describe how to determine a statement's set membership in a Language)
define semantics
the meaning of the expressions, statements, and program units
Scope
the range of statements over which it is visible, the cope rules of a language determine how references to names are associated with variables
load module
the user and system code together
define terminal symbols
they are lexemes
Be able to define or modify operator associativity in a BNF grammar. Associativity is affected by ___ __ ___, i.e. left associative operators are implemented using ___ recursion, right associative operators are implemented using ___ recursion.
type of recursion; left; right
Be able to "decorate" attributes on a parse tree given: (a) a set of BNF syntax rules, (b) a set of Semantic Rules, and (c) a set of predicates. Use Figures 3.6, 3.7, and 3.8 as a guide.
use of actual_type vs expected_type (type as in int or real)
compiler implementation
when programs are translated into machine language
is it true that these are recent variation in EBNF include: in place of arrow, a colon; in place of a vertical bar, separate lines; instead of (a|b), one of a b
yes
Reasons for Studying Concepts of Programming Languages
•Increased ability to express ideas •Improved background for choosing appropriate languages •Increased ability to learn new languages •Better understanding of significance of implementation •Better use of languages that are already known •Overall advancement of computing
Pure Interpretation
•No translation •Easier implementation of programs (run-time errors can easily and immediately be displayed) •Slower execution (10 to 100 times slower than compiled programs) •Often requires more space •Significant comeback with some Web scripting languages (e.g., JavaScript, PHP)
Readability
•Overall simplicity •Minimal operator overloading •Orthogonality •Data types •Syntax considerations
Language Evaluation Criteria
•Readability: the ease with which programs can be read and understood •Writability: the ease with which a language can be used to create programs •Reliability: conformance to specifications (i.e., performs to its specifications) •Cost: the ultimate total cost
Language Design Trade-Offs
•Reliability vs. cost of execution •Readability vs. writability •Writability (flexibility) vs. reliability
Programming Domains
•Scientific applications •Business applications •Artificial intelligence •Systems programming •Web software
Writability
•Simplicity and orthogonality •Expressivity
finite automaton
•Start state •Accepting state •A state •A transition edge from state to another
bottom-up pa
•Starts by the input string and ends with the start symbol •Reduces the string to the start symbol by inverting productions •Bottom up parsing traces a right most derivation in reverse
Cost
•Training programmers to use the language •Writing programs (closeness to particular applications) •Compiling programs •Executing programs •Language implementation system: availability of free compilers •Reliability: poor reliability leads to high costs •Maintaining programs
Reliability
•Type checking •Exception handling •Aliasing •Readability and writability
•Syntax analysis
•large-scale constructs expressions, statements, program units
•Lexical analysis
•small scale language constructs names and numeric literals •A pattern matcher •serves as the front end of a syntax analyzer •performs syntax analysis at the lowest level of program structure