PLC Flashcards
Learn PLC
In terms of variables, what is aliasing
Aliasing is the name given when two variables point to the same location in memory, it is something we aim to avoid
What are the 6 attributes of variables
+ Name
+ Address (L-Value)
+ Value (R-Value)
+ Type
+ Extent
+ Scope
What does the “Extent” of a variable refer to?
The extent of a variable is also known as the lifetime
It refers to the amount of time in the programs execution in which the variable will be assigned a meaningful value
What is a binding
Binding is the name given to associating attributes with variables. i.e.
+ Binding type
+ Binding address
+ Binding scope
What are the two types of binding and what is the difference
Static Binding - Where variables are bound during compile time and do not change during execution
Dynamic binding - Where variables are bound for the first time during execution OR when the binding can change during runtime
What is the name given to the process of binding a variable to its address
Allocation
What process does Deallocation refer to
Deallocation refers to the process of unbinding a variable from an address
This is largely dynamic as it cannot be done at compile time
What is the difference between static allocation and dynamic allocation
Static allocation refers to binding an address to a variable at compile time
Dynamic allocation refers to binding an address to a variable at runtime
What are the four kinds of variables
+ Static Variables
+ Stack Dynamic Variables
+ Explicit Heap Dynamic Variables
+ Implicit Head Dynamic Variables
What is a Static Variable
Static variables are bound to memory at initialisation time, and are also known as global variables.
In Java these are referred to by their class
What is a
Stack Dynamic Variable
Stack Dynamic Variables are allocated when some declaration is executed, they are then deallocated when that procedural block returns
What “kind” of variables are local variables
Stack Dynamic variables
What is an Explicit Heap Dynamic Variable
These are nameless, abstract memory locations. They are allocated and deallocated explicitly by the programmer with commands such as malloc
or new
What is an Implicit Heap Dynamic Variable
This is a form of variable where memory is allocated from the heap when the variable is assigned to a value.
They are deallocated and reallocated when the need to be re-assigned
What is static type binding
Static type binding is the name given when a variable is assigned a type at compile time
What is Dynamic type binding
Dynamic type binding occurs when the variable is assigned a type at runtime
It is commonly used in scripting languages
What are the two types of static type binding
+ Type Declaration - this is the most common approach and is where the variable is given an explicit type when its introduced
+ Type Inference - this approach does not require explicit typing, instead, it works out the type from the usage of the variable or from following naming conventions
What is the extent of a Static variable
The whole program
What is the extent of Stack Dynamic Variables
A particular stack frame or procedure call
What is the extent of Explicit heap dynamic variables
Explicit allocation to explicit deallocation (malloc
to free
)
What is the extent of Implicit Heap Dynamic Variables
Implicit allocation to implicit deallocation, meaning variables may persist in memory even once the addresses have been freed
What does Lexical Scope refer to
Lexical Scope is refers to when the scope of variables is aligned to statically determined areas of the code file such as class definitions or the method body
What does Dynamic Scope refer to
Dynamic scope is determined at runtime by control flow, variables are only made to be meaningful within the context of the current call stack, aka when its been used before.
What is a recursive descent parser
Recursive decent parse build parse trees from the root down, this makes them good for LL Grammars, as it reads Left to Right and forms Leftmost derivations
What are the two common types of parsers
+ Top-down, or recursive descent parsers
+ Bottom-up
What is a bottom-up parser
Bottom-up parsers build the parse tree from the leaves up, this makes them good for LR parsers as they read the rightmost derivation.
This makes them more complicated but they can handle a wider range of grammars than LL grammars can
What is a LL Grammar
A LL grammar is a CFG which parces the input Left to Right and forms Leftmost derivations
What is a LR Grammar
A LR Grammar is a CFG which parses the input Left to Right and forms Rightmost derivations
When implementing a LR Parser with shift-reduce parsing, what does shifting do
Shift reads the next input token producing a new single node parse subtree
When implementing a LR Parser with shift-reduce parsing, what does shifting do
Reduce applies a completed grammar rule to join subtrees to make a larger subtree
When do ambiguity’s arise when parsing a grammar
Ambiguities arise when it is possible for the grammar to Shift AND it is possible for the grammar to reduce, this can be avoided by specifying precedence, or by layering non terminal operations
What is precedence when parsing a grammar
Precedence is a method specifying the associativity of operators and removing ambiguity
What are the 4 approaches to typing and which are oposites
Strongly Typed & Weakly Typed
Static Typed & Dynamic Typed
What does it mean for a language to be Strongly Typed
The language checks the use of data to prevent program errors such as accessing private data, corrupting memory or crashing the machine
What does it mean for a language to be Weakly Typed
This means that the language does not always prevent errors but uses types for other compilation purposes such as memory layout
What does it mean for a language to use Static typing
If a language is statically typed the typed checking is performed at compile time
What does it mean for a language to use Dynamic typing
Dynamic typing means that type checking is delayed until run time
What does Γ represent when performing type derivation
Γ, or gamma, represents the type of environment. A type environment is the set of assumptions we have made about the free variables in the expression E
What is a free variable
A free variable is a variable which is not locally declared or parsed as a parameter
For example, in let (x: Int) = 8 in x + y
, y would be a free variable
What is the syntax to enlarge the type environment Γ, to include that a variable x is of type T
Γ,x: T ⊢