Programming Languages Exam 1
In what version of ALGOL did block structure appear
60
In what language is most of UNIX written in
C
On what laguage was COBOL based
FLOW-MATIC
what kind of grammar can you put into flex/bison
LR(1) or LALR(1)
How does computer architecture influence language design?
Language can take advantage of features of an architecture von Neumann architecture is best suited for imperative languages. -data and programs in memory separate from CPU (needs "pipelining") -Variables name memory cells -Instruction cycle is fetch and execute
What role does the symbol table play in a compiler
Serves as a database during the compilation process, stores type and attribute information about variables specified by the user
What two common data structures were included in Plankalkül
int and float
Give an example lexeme and token pair
lexeme: >= token: comparison
What are the components used to describe language syntax?
lexemes, tokens, recognizers, generators Meyer says, "Languages, sentences - Language is the set of sentences the language allows"
Before syntax analysis, the individual characters or symbols that make up a token, such as int in C++ or a ; or an identifier, are determined. This is done in _____________ analysis.
lexical
Describe the operation of a general language generator
setup which can be used to generate sentences of a language
Which version of Fortran was the first to have any sort of dynamic variables?
90
Describe the syntax for a list in BNF
<ident_list> --> identifier | identifier, <ident_list>
Describe the syntax for an if statement in BNF
<if_stmt> --> if (<logic_expr>) <stmt> <if_stmt> --> if (<logic_expr>) <stmt> else <stmt> Also valid: <if_stmt> --> if (<logic_expr>) <stmt> | if (<logic_expr>) <stmt> else <stmt>
What is a state transition diagram
A directed graph where the nodes represent states and the edges represent an input symbol which can cause a transition among states
What is the difference between a sentence and a sentential form
A sentence is a sentential form that only has terminal symbols. A sentential form is every string of symbols in the derivation
What language introduced the case statement
ALGOL 68
What is aliasing?
Aliasing is having two different names for one memory location
What make a language writable?
All of the readability stuff applies support for abstraction - C++ class, for example expressivity - ways of specifying control and operators; this clashes somewhat with orthogonality
What makes a programming language orthogonal?
An orthogonal language should be able to combine any data type with any operator, for example
bottom-up parsing
Assembling a parse tree by beginning at the leaves and progressing upward toward the root.
top-down parsing
Assume that the input string matches the definition, and build a parse tree from the root down to the leaves. Branches from a particular node are followed in left-to-right order. Corresponds to leftmost derivation. see p. 196 global ed and https://qntm.org/top
In C++, which of the following are valid (compiles and executed)? There can be more than one answer -- choose all that are valid. A. x = --4; B. x = -+-4; C. x = 4++; D. x = +4;
B,D
Give an example of a context-free grammar
Backus-Naur Form (BNF) ex: <S> --> a <T> | a <T> b <T> --> x | y
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
By understanding the philosophy behind a programming language we can better utilize the features of a language.
Which of the following includes use of a n intermediate code? [Note: in general, each of the following translation approaches can use an intermediate code. Which approach, though, is an intermediate code fundamental?] A. Compiler B. Interpreter C. Combined (compiler + interpreter)
C. Combined (compiler + interpreter)
Cobol
Common business orented language Used for business use and commerce
What are the three general methods of implementing a programming language
Compiler Implementation, Interpreted Implementation and the combination of both
What are the three fundamental features of an object-oriented programming language?
Data Abstraction, Inheritance, Dynamic Method Binding or Polymorphism
What are two characteristics of C that make it less safe than Pascal
Every object belongs to one type, type conversion occurs by converting a value from one type to another
What programming language has dominated scientific computing over the past 50 years.
FORTRAN
Lexical analysis
Front-end to syntax analysis Separates sequence of characters into lexemes and tokens How to write one Input a regular grammar into a lexical-analyzer generator Develop a state transition diagram (or finite state automata), implement the diagram Develop a state transition diagram, create table, implement table-driven code ~ can be most efficient
List some programming domains/paradigms
Functional Programming Object-Oriented Programming Imperative Programming Logic Programming
parsing ambiguity
In computer science, an ambiguous grammar is a context-free grammar for which there exists a string that can have more than one leftmost derivation or parse tree, while an unambiguous grammar is a context-free grammar for which every valid string has a unique leftmost derivation or parse tree.
How do programming design methodologies influence programming language design?
In the past, machine efficiency was critical Now, languages are designed with "people efficiency" in mind, where they support features that make it easier to organize large projects, large amounts of code Data abstraction, i.e. OOP, is important again
Where was LISP developed? By Whom?
John McCarthy in 1958 at MIT
What programming language has dominated AI over the past 50 years.
LISP
What's a language definition made of?
Language definition = syntax + semantics
Explain the three reasons why lexical analysis is separated from syntax analysis
Lexical analysis does the analysis of small language constructs like names and numeric literals Syntax analysis does the analysis of large constructs like expressions and program units
Token
Lexical analyzer assigns some numeric codes to the lexemes according to their structure called tokens
What makes a language readable?
Overall simplicity - has a straightforward set of constructs orthogonality data types - enough data types to cover needs control structures - enough, not too many, easy-to-use syntax issues - upper/lowercase, meaningful keywords, use of delimiters
How does one deal with parsing ambiguity in the statement B = B * C + C?
Place precedence in the parsing rules Augment grammar rules with attributes. Synthesized (actual) and inherited (expected) attributes describe expressions in an unambiguous way, for example: <expr> → <expr> op <expr> | <id> is ambiguous <expr> → <expr> op <id> | <id> is not ambiguous
What are factors in the cost of programming language use?
Programmer training Writing programs Compiling programs Executing programs Maintaining programs Available translators Reliability
Prolog
Programming in logic (an example of logic programming)
What are the primary tasks of a lexical analyzer
Scan the program file, recognize the lexemes in the program and categorize them into associated tokens
What was the primary application area of computers at the time Fortran was designed
Scientific Computations
What language was the first to support the three fundamental features of object-oriented programming
Smalltalk
Fortan
Stands for Formula Translation. It was developed for scientific and engineering applications, and for easy translation of formulas into code. Supported floating-point arithmetic
What is exception handeling
The ability of a program to intercept unusual conditions at the runtime, take corrective measures and then continue without crashing
How can user-defined operator overloading harm the readability of a program?
You can overload things that have a common meaning like '+'
Describe the operation of a general language recognizer
aid compiler by helping analyze the syntax of the program code
What is one example of a lack of orthogonality in the design of C
arrays can contain data of any type but not void or functions
What is the relationship between Javascript and PHP
both scripting languages and used for web programming
What primitive control statement is used to build more complicated statements in languages that lack them
branch or jump statements
What are factors that influence language design?
computer architecture programming design methodologies
Pros and cons of program translation
ease of constructing the translator runtime execution of program (Python is slow) tracking program behavior, debugging (more difficult without a statically typed language)
Why was BASIC an important language in the early 1980s?
easy for beginners and non science oriented people
What innovation of data structuring was introduced in ALGOL 68 but is often credited to PASCAL
enumerated types
Why does C++ include the features of C that are known to be unsafe?
evolved from C but OO
Draw the compilation process (pic)
https://i.imgur.com/PlF8zv6.png source program -> lexical analyzer -> syntax analyzer -> intermediate code generator -> code generator -> computer (this is missing things that the picture has)
Lexeme
input to the lexical analyzer from which the analyzer collects the characters and groups them into logical groups according to the pattern matching rules
The picture of a derivation is a __________ tree
parse
Syntax
structure of its statements, expressions, and program components
Semantics
the meaning or definition of statements, expressions, and program components
type
the range of values and the allowed operations
Why is the von Neumann bottleneck important?
transfer speed of data between memory and processor