CSC 254 Final (Sean Levin)
Structured Programming
"Hot trend" of the 70's where code was top-down and modularized
4 functions of Types
1) implicit context 2) prevent invalid actions in an otherwise valid program 3) provide key details about the code that make the compilation process easier 4) used to handle certain optimization processes
Reasons for Initialization
1. A static variable needs an initial value to be useful 2. For a statically initialized variable, an initial value can be preallocated by the compiler; thus, avoiding the cost of run-time initialization 3. Not having an error in your code
Disadvantages to CGI scripts
1. web server must launch every script as a separate program, with potentially significant overhead 2. Name of script appears in the URI, so static and dynamic pages look different to end users 3. Each script must not only generate dynamic content, but also the HTML tags that are needed to format and display it
Retinterpret Cast
Allow you to cast one pointer type to another pointer type. Not type safe, no runtime checks
LL(1) Grammar
Also called predictive, is a top-down parser, parses from left to right, performing left-most derivation
Ad Hoc Polymorphism
Also known as function/operation OVERLOADING, it's when you change the number or type of parameters to elicit a function that behaves differently
"Explicit" languages
C++, Java, C#, Ada, ... (generics)
Dynamic Cast
Cast where you convert from a base class to a derived class (general --> specific). Type safe, runtime checks
Syntax Error
Character or string incorrectly placed in a command or instruction that causes a failure in execution
Dynamic Scope
Look back to the previous function that called you and look in their environment for the variable you need. Recursively do this until your variable you're looking for is found
"Implicit" languages
ML, functional
Precedence
Specifies parentheses for unparenthesized expression with different operators
Associativity
Specifies parentheses for unparenthesized expression with similar operators
Static Links
Static linking is the result of the linker copying all library routines used in the program into the executable image.
generational garbage collection
The partition of objects into different generations (time intervals) based on time of allocation, and giving them different GC policies depending on age
Many shell and scripting languages allow strings to be delimited with either single (') or double (") quotes. Why both?
Variable names are inserted inside double-quoted strings, but not inside single-quoted strings
Short-Circuit Evaluation
When a compiler skips parts of a boolean expression because the first evaluation predicts the rest of it (first segment in an AND statement is false, or first segment in an OR statement is true)
Side Effect
When a function does something that is significant, other than returning a value (Usually assignment)
Assignment Operators - Postfix
When an assignment operator is used after the variable itself. That way, the variable is changed after it is used in its surrounding context
Assignment Operators - Prefix
When an assignment operator is used before the variable itself. That way, the variable is changed before it is used in its surrounding context
Which of the following errors will always be caught by a correct implementation of C?
a. array reference out of bounds b. use of uninitialized variable c. use of pointer to data that has already been freed (deleted) d. none of the above - ANSWER
Which of the following is not commonly found in a stack frame (activation record)?
a. return address b. static variables - ANSWER c. saved registers d. parameters
Which of the following is a checked dynamic semantic error in C (one the language implementation is required to catch at run time)?
a. use of an uninitialized variable b. access off the end of an array c. wrong number of parameters passed to a function d. divide by zero - ANSWER
backtracking
allows for the different pieces of Java code, both generic and non-generic, to be more easily integrated into each other. Idea not limited to Java.
condition synchronization
any mechanism that protects areas of memory from being modified by two different threads at the same time
Synthesized Attributes
attributes are derived only from children with no inheritance
Shallow binding
binds the environment at the time a procedure is actually called.
Deep binding
binds the environment at the time a procedure is passed as an argument. most languages use
call by name parameter
can change the value of a passed in parameter
Erasure
checks code, make sure type-safe, erases type parameters, replaces w/ Object
Currying
is the technique of translating the evaluation of a function that takes multiple arguments (or a tuple of arguments) into evaluating a sequence of functions, each with a single argument.
Type Conformance: Invariant
lists are not comparable
A higher-order function is...
one that takes a function as a parameter, or returns a function as a result
discrete types
pre-defined, specific domains, clear succession from 1 element to the next ex) ints, bools, and chars
strongly typed
prohibits actions when they are applied to the wrong type of object, like using math operators on chars
embedded scripts
require server to look inside page source
Scalar Types
simple types; composed of discrete, rational, real and complete types
statically typed
strongly typed, and type checking performed at compile time
duck typing
style of type checking that, at run-time, examines variables to make sure they are compatible with the operations performed on them
type compatibility: conversion
takes a value of one type, and turns it into a value of another type
type erasure
the act of replacing generic functions and their arguments with the Object class and other equivalents. This is useful because it uses implicit casts, which reduces the strain on the programmer.
Type Conformance: Contravariant
the conformity of the lists is inverted ex: Can use print<person> as print<student>
The static link of a subroutine is
the frame pointer of the lexically surrounding subroutine
Referencing Environment
the set of active bindings. Corresponds to a collection of scopes that are examined (in order) to find a binding.
type compatibility: coercion
value is automatically converted to the type required for a given operation, an implicit conversion
What is the defining difference between a compiler and a preprocessor?
A compiler performs full syntactic and semantic analysis; a preprocessor does not
Virtual Functions
A function that is created and known to be changed in later derived classes of the original class
Imperative Language ~ Expressions
A function that may or may not include a side effect but always produces a value
Imperative Language ~ Statements
A function that may or may not produce a value, but always has a side effect
Orthogonality
A language design where anything can be put together and it still makes sense (Algo 68)
data races
A semantic error. Occurs when 2 instructions from different threads access the same memory location, at least one of these accesses is a write and there is no synchronization that is mandating any particular order among these accesses.
signal handlers
A signal is a software interrupt delivered to a process. The operating system uses signals to report exceptional situations to an executing program. Some signals report errors such as references to invalid memory addresses;
Continuations
A way that allows the structure of flow to back track to a previous environment where the address is saved in memory, along with the environment status and a reference to another continuation in the event that we need to go back again
Assignment Operators
Assignment operators are a way to avoid unintended side effects
Why don't you need a static link in C?
Because C doesn't have nested subroutines
Why, in the general case, must local variables in OCaml be allocated in the heap instead of on the stack?
Because local variables in OCaml can have unlimited extent
Stop and Copy
Divides the head into 2 parts. Then it goes through all the ones in the first half and sends all the reachable ones to the second half. This means that the second one is the "valid" half
Dynamic Links
Dynamic linking is accomplished by placing the name of a sharable library in the executable image.
Static semantic error
Error detected at compile-time by semantic analysis
Dynamic semantic error
Error detected at run-time by code generated by compiler
Static Cast
Conventional cast where there are defined rules for casting from the original type to the next one. Not type safe, no runtime checks
Enumeration-Controlled Loop
Executed once for every value in a given set of values. Note that the number of iterations is known before the first iteration begins
Logically Controlled Loop
Executed until some boolean expression changes value
l-Value
Expressions that denote locations (e.g. [variable a] => a = b + c)
r-Value
Expressions that denote values (e.g. [variable a] => b = a)
Which of the following is considered a pure functional language?
Haskell
Reference Model
Instead of containers, a reference model uses variables as a way to point to the containers that hold the actual value
L-attributed
LL parsers (inheritance)
S-attributed
LR parsers (no inheritance)
Common Subexpressions
Languages can reorder mathematical expressions to make evaluation easier. One way of doing this is by recognizing common subexpressions and using them in a multitude of instances to more easily compute values
Smart Pointers
Objects that act like pointers. Often used for reference counting, and thus to improve garbage collection. Also used to check bounds, debug, and track references to external objects
What is a sentential form?
One line of a derivation
Which of the following mechanisms is intrinsic to context-free languages but not regular languages?
Recursion
Lexical Error
Results from token recognition falling off end of the rules you've defined Ex: errors are going to be input strings that don't reach an accepting state
Definite Assignment
Some languages like Java and C# make sure than every way of getting to a specific variable has had each variable being used in the context already been initialized. This can rule out perfectly okay codes, but it is a way of being conservative to avoid errors
Subtype Polymorphism
Super-class and sub-classes. You can generalize the class to overarch and get any sub-class
Language implementations based on interpretation are almost always slower than implementations based on compilation. Why, then, do people still use interpreters?
a. Interpreters tend to produce more helpful error messages b. Interpreter-based implementation tend to require less memory than compiler-based implementations c. Interpreters accommodate late binding d. All of the above - ANSWER
Boxing
The value model has a drawback that when using a typed parameter, you must sometimes use a wrapper class to uphold the correct syntax
Value Model
The variable is an actual container for the value
The grammars used in many production compilers contain error productions, which allow the parser to accept certain input programs that are, according to the manual, syntactically invalid. What purpose do these error productions serve?
They provide more helpful error messages than a general-purpose error recovery scheme would
Many compilers are divided into two largely independent passes: a front end, responsible for analyzing source code, and a back end, responsible for generating target code. (They may also include a third, intermediate pass, responsible for code improvement.) What is the most important motivation for this division into passes?
To provide multiple combination of front ends and back ends in a compiler family
Memory Leak Error
When no references point to data that is not null
Mark and Sweep
When the collector uses pointers and other links to traverse the program and determine which objects to keep
Dangling Reference
When the object a pointer points at is removed, but the pointer is not
Code Improvement
When we reorder the sequence in which things are computed ex: a := B[i] c := a * 2 + d * 2 - In this example, d * 2 is going to be computed first because doing a * 2 means doing a laod which would take more time
Dereferencing
When you take the pointer out and have the actual value
Explicit Parametric Polymorphism
When you use a specific class for parametrizing something
Implicit Parametric Polymorphism
When you use the generics thang (T in Java) for a typed parameter to have an object's parameter be specified at a later time (Generic programming)
Lexical Scope
Your immediate scope, all the variables that are immediately available to you
Action Routine
a semantic function that we tell the compiler to execute at a particular point in the parse.
enum type
come with a set of pre-defined functions that make value manipulation easier.
CGI scripts
common gateway interface script output is displayed in browser
client-side scripts
don't pay Internet overhead; can be much more interactive; also reduce load on server (even, e.g., for checking of input parameters)
call by need parameter
expected way of implementing laziness. The first time you "really" need the value, you computed it and you make a cache of the computed value for future access
Unlimited Extent
functional languages mostly. usually variables are save in the heap
Limited Extent
how long a binding is valid. can't have limited extent with dynamic scope. when it drops out of scope, the variable can no longer be accessed
Type Conformance: Covariant
if 1 class can be used in any context of the other, then lists are the same ex: Can use create<student> as create<person>
volatile variable in java
in Java, you can have java volatile variable, which will instruct JVM threads to read value of volatile variable from main memory and don't cache it locally. If a variable is not shared between multiple threads no need to use volatile keyword with that variable.
Inherited Attributes
information is passed to F from it's parent