Test 1 Tips--Theory of Programming Language.pdf
Document Details
Full Transcript
Celine Gordon, Christina Reed Study Guide → Theory of Programming Languages 1. You should know facts about the basic languages, mostly based on the homework questions from chapter 2. a. COBOL – language developed by Dr. Grace Hopper, was used for busi...
Celine Gordon, Christina Reed Study Guide → Theory of Programming Languages 1. You should know facts about the basic languages, mostly based on the homework questions from chapter 2. a. COBOL – language developed by Dr. Grace Hopper, was used for businesses and defense b. ALGOL – First language whose syntax was formally defined (BNF) c. Fortran – was the first high level languages d. LISP/Scheme – Language used for AI e. Ada – first widely used language named after Ada Lovelace f. BASIC – language that prefers user time over computer time and is easy to learn for non-science students g. Java – high level, class based, object oriented language h. Python – high level, easy to learn programming language 2. Questions on grammar a. Four parts of a grammar i. Terminal: ii. Non-terminal: iii. Start Symbol iv. Result b. Syntax tree or left derivation based on a grammar i. When you are doing left hand derivation, make sure that you derive ONE AT A TIME c. Are some phrases legal in a given grammar (like Textbook 11 and 12) i. If a phrase is legal, then it can be found in the grammar. If a phrase is not legal, then it cannot be found in the grammar and is deemed as ILLEGAL. 3. Example of finding precondition (Axiomatic Semantics). a. (insert picture here) b. Finding a precondition, first you have to look at the post condition, and determine if this statement will make the whole thing true before proceeding. you can use the post condition to find the precondition. 4. Definition of 3 types of semantics. a. Operational Semantics → Operational semantics looks at the program as a whole, and prints it out and sees what is going on. b. Denotational Semantics → This is where you are going line by line, and you are checking to see if each line complies with the language. c. Axiomatic Semantics → Axiomatic semantics is when you are checking for the post conditional statements that need to be true for everything to work. 5. Define/describe or compare/contrast and/or give an example: a. Syntax and semantics → rules for a language; meaning of a language b. Lexer and parser → Part of a compiler that finds lexemes; part of a compiler that creates syntax trees c. Compiler → Translate high-level program (source language) into machine code (machine language) slow translation, fast execution d. interpreter → No translation easier implementation of programs (run-time errors can easily and immediately be displayed) e. Token —> a way to categorize lexemes f. Lexemes —> smallest unit of a language 6. Evaluating languages. Discuss the criteria and/or use the criteria to evaluate a language or compare 2 languages. When you are evaluating language, you need to look at different things: a. Readability: how easy programs can be read b. Writability:how easy a program can create programs c. Reliability: conform to specifications d. Cost: total cost Chapter 5 and 6: 7. Attributes of a variable a. Type b. Value c. Address d. Scope e. Lifetime f. Name 8.Types of Scope Static: determines a variables value based on what encloses it Dynamic:determines a variable's value based on the call stack at runtime 9. Primitive data types 1. Int 2. Char 3. Boolean 4. Float 5. Double 6. String 10. 2 problems with memory 1. pointers that point to nothing 2. garbage 11. 2 types of reclaiming garbage 1. Mark-sweep: unused cells are reclaimed only when available space is empty 2. Reference counter: reclaims cells whenever a cell stops being accessible Access function: mapping of its base address and a set of index values to set address Aggregate constant: vector constant that isn't changed at all whilst the program is being executed Array: homogenous aggregate (something.. but it was on the last quiz!) Alias: multiple variables have the same address 11. Types of ranges 1. Ordinal: range of all possible values that can be easily associated with the set of positive integers 2. Enumeration: all possible values are provided in definition 3. Subrange: contiguous subsequence of an ordinal type 12. Define lifetime, scope, static scope, and dynamic scope. Lifetime scope: time which the variable is bound to a specific memory location Static Scope: binding names to non-local variable Dynamic Scope: based on the calling sequence of subprograms 13. What is the referencing environment of a statement? The referencing environment of a statement is the collection of names that are visible in the statement. 14. What is a static ancestor of a subprogram? What is a dynamic ancestor of a subprogram? Static ancestor: The static parent of a subprogram, and its static parent and so forth up to and including the largest enclosing program, are called static ancestors. Dynamic ancestor: The dynamic parent of a subprogram, known as the calling function of the subprograms and so forth up to the largest calling function doing the calling 15. 4 times binding can happen 1. Load time 2. Compile 3. Runtime 4. Link time In programming, the stack and heap are two types of memory that differ in how they allocate memory, how they're managed, and their speed and flexibility: Stack A region of memory that uses Last In First Out (LIFO) or First In Last Out (FILO) to allocate memory for local variables and function calls. The stack is faster than the heap, but it's limited in size. The stack is automatically managed, and when a method completes execution, the stack memory is automatically released. Heap A region of memory that allows for dynamic memory allocation for data with longer lifespans. The heap is slower than the stack, but it's more flexible and doesn't follow a strict structure. The heap requires manual management, and the programmer is responsible for de-allocating the memory space. Chapter 12: Object-Oriented Programming (OOP) – A programming paradigm based on the concept of "objects", which contain data and methods. ○ 3 Characteristics of OOP (A.I.P): Abstract data types –what the program creates Inheritance – you get things (traits) that you acquire from a parent class Polymorphism – you inherit things, but you change their “function” Objects – class instances A class that inherits something is a DERIVED class or a SUBCLASS (child) The class that another class is inherited from is the SUPERCLASS (parent) Subprograms that define operations on the objects are methods ○ Call to a method → message Dynamic Binding ○ Polymorphic variable – a variable that can reference objects of the class and any of its descendants (remember that dynamic can access what called it!) ○ Abstract method – won't include a definition “Is-a” relationships: ○ BASICALLY.. the connection between two entities where one entity can be considered a type of the other, essentially meaning "A is a type of B" - like saying "a cat is a type of animal" - signifying that every cat is also an animal Single and Multiple Inheritance ○ Single Inheritance – A class inherits from one and only one superclass. ○ Multiple Inheritance – A class can inherit from more than one superclass (supported by languages like C++ but not Java).