Name 3 of the most important domain areas that have historically driven the design of programming language, and name one such language for each area.
Scientific Computation - Fortran
AI - Lisp python
Enterprise - Java Cobalt
Systems programming - C Pearl
Web applications - Javascript, Typescript, PHP
Describe how computer architecture can affect the design of programming languages.
languages that follow the designed of a computer’s architecture can be followed easily, while languages that use abstractions are harder to translate. This is why early languages followed computer architecture.
Describe the different ways in which a programming language may be implemented.
compiler: take source code and turns it into machine code
interpreter: program that reads source code and executes it
virtual machine: code is compiled into byte code, instructions are simulated in software
Describe the two components of a programming language.
syntax: rules to write valid words in the language
semantics: the meaning of sentences within the language
What is the alphabet of a programming language?
set of all valid symbols in the language
What is the difference between reserved words and keywords?
reserve words: words that may or may not be used by the language (could be used in future updates)
key words: reserved words with functionality in the language
What does it mean for a language to be Case Sensitive? Give an example.
keywords, variables, function names, and other identifiers must always be typed with a constant capitalization of letters
EX:
“while” != “While”
What does it mean for a language to be Case Insensitive? Give an example.
the language can ignore the differences between upper and lowercase letters
EX:
“while” = “WHILE”
What are the stages of a compiler?
LSSTOT
Lexical analysis
Syntax analysis
Semantic analysis
Translation
Optimization
Transcription
What is a variable?
a name for memory location that holds a value of a particular data type that can be destructively updated
What is the difference between L-values and R-values?
L-value: value of memory location that holds the value you are storing in the variable
R-value: the actual value you are storing in the location
Describe the phenomenon known as memory aliasing.
when a memory location can be accessed through more than one name (when 2 or more variable have the same L)
What is name binding?
the associating of a name with a specific value/property (memory, type, scope)
What is Static Binding?
when a name is connected to a property before execution
What is Dynamic Binding?
when a name is connected to a property during exection
Describe static allocation.
when memory is allocated before execution, typically done by the compiler
Where is the data placed when allocated statically?
the .data section / segment
Describe Dynamic Allocation.
when memory is allocated during execution, usually incurs overhead
Where is data placed when allocated dynamically?
the .heap section / segment
Describe static typing.
name is assigned a type before execution
Describe dynamic typing.
name is assigned a type during execution
What is the difference between Explicit and Implicit typing?
if the language requires the use to explicitly specify the type of an element with a syntactic feature the it has explicitly typing, otherwise it is implicit
Describe Static Scoping.
(lexical scoping) when the scope of a name is defined at programming / writing time with lexical features
Describe Dynamic Scoping.
The scope of a name is defined while the program is run by looking at the current state of the stack of activation records.
Give a list of 5 primitive data types and their typical sizes.
(all in bytes)
int - 4
long - 8
char - 1-4
float - 4
short - 2
boolean - 1
byte - 1
what is a constant size string?
can be implemented with arrays and may or may not be immutable, these are very fast to access and travers. modifying it may involve allocating a new string which is expensive
what is a dynamic size string?
can be implemented with buffered arrays or linked-lists, these are slower to read (not so much if buffered array is used)
Why must the elements of an array be all of the same type?
in order to iterate though an array all elements must be the same type and size in terms of bits
Why must the size of an array be immutable?
arrays are usually stored in contiguous blocks of memory, once the block of memory is allocates it is hard to iterate though is you want to add more space
What are associative arrays?
arrays where the subscript is not an integer, but a string or some other type, these are maps in which a string is a key that must be unique for every element that it is mapping.
Describe array-of-arrays implementation of multi-dimensional arrays.
array is stored in an array, which allows for contiguous allocation which is fast since it is all in one block.
EX:
Array [ref1, ref2]
Ref1 = [2,3]
Ref2 = [4,6]
Describe sequential-allocation implementation of multi-dimensional arrays.
array is stored all in one block, the first element tells where to jump to and the second tells which element is implemented
EX:
Array[[1,2][4,6]]
What are jagged arrays?
arrays in which at least one dimension is variable instead of constant
List the different kind of expressions in a programming language.
relational expression
logical expression
What is the arity of an operator?
the number of operands in which an operator operates.
what is prefix
operator is placed before the operand (+3,4)
what is infix
operator is placed between the operands (3+4)
what is suffix
operator is placed after the operand (x++)
what is left to right evaluation
when evaluation happens starting from the left reading to the right
EX:
x + 3 - 2 = (x+3)-2
what is right to left evaluation
when evaluation happens starting from the right reading to the left
EX:
x + 3 - 2 = x+(3-2)
Describe precedence.
a mechanism to sort ambiguous expressions by creating a hierarchy of operators where the position of the hierarchy determines the binding strength
What does it mean for the evaluation of an expression to have a side-effect?
the evaluation results in a visual change or destructive update of memory
What does it mean for an expression to be pure?
when an expression is side effect free
What is Referential Transparency?
if the substation of the expression by the value it yields results in a program with the same semantics
What are mixed-mode expressions?
and expression with more than one type of operand
what is type coercion?
the conversion is implicit / automatic
what is type casting?
the conversion is explicit and performed with some syntactic feature in the language
Describe short-circuit of logical expressions.
a form of lazy evaluation given a binary operation, is the evaluation of the first operand is enough to determine a value, the second is not evaluated
What is an assignment?
the cornerstone of imperative languages since they are used to perform destructive updates
List the different kinds of assignments and provide examples.
simple: x=e
parallel: x,y = 1,2
multiple: x,y,z=42
compound: x+=1
unary: x++
conditional: x=if b then E1, else E2
What is a restricted-unconditional jump? Provide an example.
similar to goto, it allows one to jump unconditionally to a target instruction
EX:
(i) x=y+1
Goto (i+j)
…
(i+j) z=42
what is pass by value copy?
when you make a copy of the value and pass it, this does not affect the original value
what is pass by reference?
when you pass the memory location of the value, this will change the original value even outside the function
what are formal parameters?
variables that are defined when the function is declared
EX:
func int x: {}
what are arguments?
variables that are declared when the function is called
EX:
number(12)
what is the difference between formal parameters and arguments?
arguments are passed into the function and parameters are what the function takes in as an argument
what is positional parameter?
arguments bind to the parameter according to the position
EX:
int f(x,y,z)
return x,y,z
int r call f(1,2,3) //x=1,y=2,z=3)
what is keyword parameter?
arguments binding is explicitly specified using the name of the parameter
EX:
s = call f(y=2, x=1, z=3)
What are default parameters?
when the language allows you to specify default values for the parameters
EX:
fun int f(x,y=2,z)
int t = call f(x=1, z=3)
name the main evaluation criteria for programming language design.
simplicity
orthogonality
lv of abstraction
portability
cost
expressivity
simplicity
language with minimal set of features with rules on how to apply them and combine them as simply and clearly as possible
orthogonality
the way different constructs can be combined, and how simple these combinations are to understand
lv of abstraction
the features provided to create abstraction
portability
how easy it is for a program to be created in the language can be moved from one system to another
cost
cost of using language in a project (development, maintenance, execution)
what are the 3 paradigms of programming languages
function
imperative
logical