CSE262

¡Supera tus tareas y exámenes ahora con Quizwiz!

List the principals of goto and the structured alternatives to each

- To jump to the end of a current subroutine. Alternative: explicit return statement - Escape from the middle of a loop. ALTERNATIVE?? - Propagate out of some surround context. Alternative: provide an exception handling mechanism - Return from a nested chain of subroutine calls (nonlocal goto). Alternative: provide a return from statement

Given the ability to assign a value into a variable, why is it useful to be able to specify an initial value?

- avoids some serious problems at runtime of the program including accidental use of an uninitialized variable - you need to initialize something for static variables - the initial value of a static variable can be allocated in global memory by the compiler at compile time, and avoids the cost of assigning a value at run-time - initialization only saves time for variables that are statically allocated - variables allocated in the stack or heap at run time must be initialized at runtime

Name 8 major categories of control flow mechanisms

1) sequencing (statements must be executed in a certain order), 2) selection (depending on the runtime condition a choice is to be made among 2 or more statements/expressions), 3) iteration (given frafment of code is to be executed repeatedly), 4) procedural abstraction (a potentially complex collection of control constructs encapsulated in a way allowing it to be treated as a single unit), 5) recursion (an expression defined in terms of a simpler version of itself - computer requires a stack on which to save info about partially evaluated instances) , 6) concurrency (2 or more program segments are executed or evaluated at the same time the execution may be in either parallel or on separate processors), 7) exception handling & speculation (a program segment is executed assuming SOMETHING), 8) non-determinancy (the ordering of statements or expressions is not specified. This is done to imply any of the alternatives will product correct results)

What are programming assertions? What is their purpose?

A statement that a specific condition is expected to be true when execution reaches a certain point in the code

What are aggregates? Why are they useful?

Aggregates are built up structured values of user defined composite types such as recors, sets, etc. They're useful for initialization of static data structures at compile time, thus avoiding the cost of initialization They are also useful b/c they are orthogonal and so they can have multiple data types within them They also allow you to eliminate non-orthogonality w/functions as they often take in multiple arguments and return only one

Why don't issues of associativity arise in postscript or forth?

B/c they use postfix notation. There's no ambiguity as to what numbers the function applies to

Why is it impossible to detect certain program errors at compile time even though they can be detected at runtime?

Certain errors such as division by 0 or attempting to index into an array w/an out of bounds subscript are impossible to detect b/c they only occur for certain input values, or certain behaviors of arbitrarily complex code

Linker

Compiler may rely on a library of subroutines that aren't part of the original program. The compiler will rely on a linker to merge the right libraries to the final program.

Target code generation

Compiler translates the intermediate form into the target language by traversing the symbol tree and assigning locations to variables and traversing intermediate rep of program, generating load stores for variable references interspersed with operations tests and branches

Semantic analysis and intermediate code generation

Discovery of the meaning in the program. Tracks types of identifiers and expressions. Build and maintains a symbol table. Enforces rules not captured by context free grammar. Input = parse tree. Output = abstract syntax tree or other intermediate form.

What are the advantages of updating a variable w/the assignment operator rather than w/a regular assignment in which the variable appears on both the left and right had sides?

Eliminates the run time cost of redundant address calculations, avoids the issue of repeated side effects. We do the assignment calculation once instead of twice

Why is it generally expensive to catch all uses of uninitialized variables at runtime?

Every possible bit pattern of the variable representation in memory designates some legitimate value, and extra space must be allocated somewhere to hold an initialized/uninitialized flag. This flag needs to also be checked or unchecked at every use and maintained

Difference between a statement and an expression? What does it mean for a language to be expression oriented?

Expression: somethhing that evaluates to a value (X = (9*7)+8) Statement: A line of code that performs some action (printf("hello")) Expression-oriented languages contain expressions only and all tasks can be done using expressions. Expression oriented languages use statements inside the expression itself and all statements can be written as expressions.

Explain the notion of definite assignment in Java and C#

Java and C# define a notion of assignment that prevents the use of uninitialized local variables and methods. Based on the control flow of the program and can be checked statically by the compiler.

What is an L-value? What is an R-value?

L-vale: expressions that denote locations. R-vale: expressions that denote values

Scanner

Lexical analysis. Principal purpose is to simplify the task of the parser by reducing the size of the input. Input = character stream. Output = token stream

Distinction between exceptions and multilevel returns

Multilevel returns and structured exceptions are very similar as they both involve a transfer of control from an inner, nested block back out to an outer block. The distinction is in where the computation occurs: - multilevel return: the inner context has all the information it requires for proper execution and hence it completes its computation and generates a possible return value and then transfers the control to the outer context - exceptions: the inner context is unable to complete the task assigned to it b/c of some error condition. It hus performs an abnormal return, which triggers the execution of an exception handler

What distinguishes operators from other sorts of functions?

Operator = built in function that uses simplex special syntax. In most commanding languages a function is called by using its name followed by parenthesized arguments separated by commas. An operator call is simple and takes mostly 1-2 operands and uses a blank space in place of commas

Define orthogonality in the context of programming language design

Orthogonality means that a feature of a language can be used w/other features of the language in any combination, each of these combinations make some programming sense. Also, the meaning of a given feature is the same or consistent in all of these combinations, regardless of the other feautres w/which it is combined

Explain the difference beetween prefix, infix, and postfix notations. What's Cambridge Polish notation?

Prefix = function name appears before its arguments. Infix = function name appears among its arguments . Postfix = operator appears after its arguments. Cambridge polish notation = function name is placed inside parentheses (AKA polish prefix notation)

What's an attribute grammar?

Provides a formal framework for the decoration of the parse tree. The context free grammar specifies the syntax of a programming language and will generate all the properly formed constant expressions over the basic arithmetic but says nothing about the meaning. Attribute grammar allows us to understand the meaning.

Interpreter

Reads and executes as it goes along. Because it does as it goes, allows for better flexibilitya nd diagnostic messages vs. a compiler. Phases: Scanner --> Parser --> Semantic analysis and intermediate coded generation --> tree-walk routines --> program output

What does it mean for an expression to be referentially transparent?

Referentially transparent = purely functional. If it gives the same results whenever the expression is evaluated, that is the value of the expression does not depend on the time at which the expression is evaluated

Phases of compilation

Scanner --> Parser --> Semantic analysis and intermediate code generation --> machine-independent code improvement (optional) --> target code generation --> machine specific code improvement (optional)

What is short circuit boolean evaluation? Why's it useful?

Short circuit boolean evaluation = skipping the evaluation of a part of a boolean expression when the overall value can be determined from the first part Useful b/c it can save significant amounts of time, it changes the semantics ofa . boolean expression, and it can be used to avoid out of bound subscripts (???)

Why is the distinction between mutable and immutable values important in the implementation of a language w/a reference model of variables?

Since a language that uses reference model of variables propagates references to the same object, different objects having similar values end up referring to the same memory location. If two immutable objects have the same value, they'll always refer to the same memory location. If they are mutable they need to refer to two different memory locations

Parser

Syntax analysis. Organizes tokens into a parse tree that reps higher level constructs in terms of their constituents. Root of the tree is simply the program, the leaves are tokens from the scanner. Scanning + parsing serves to recognize the structure of the program without regard to its meaning. Input = token stream. Output = parse tree (concrete syntax tree)

What determines whether a language rule is a matter of syntax or of static semantics?

Syntax governs the rules of a valid program and is the set of protocols to be followed while writing a program to avoid any compilation errors. Syntax = rules governing the statements. Semantics refer to the meaning conveyed by the statement of our program. Semantics = intentions of the program

Difference between synthesized and inherited attribtues

Synthesized attributes: in grammar, each symbol has at most one attribute, called the synthesized attribute. There are appearing symbols on left hand side just because in production only their values are synthesized. Inherited values = the calculated values of attributes when their symbol is on the right hand side of the current production. The rules of production can be applied in different ways depending upon the surrounding context. These attributes allow the information to flow into symbol either from side or above

Why do most languages leave unspecified the order in which arguments of an operator or function are evaluated?

This allows the compiler to rearrange the expressions involving operators whose mathematical abstrations are commutative, associative, and/or distributive in order to generate faster code

Compiler

Translates from one language to another with full analysis of the meaning of the input.

Preprocessor

Utilized by most interpreted languages. Removes keywords, comments, and white spaces and groups the characters into tokens to produce an intermediate form that mirrors the structure of the sources but is efficiently interpreted

Difference between value model of variables and reference model of variables. Why is the distinction important?

Value model of variables: a variable is a named container for a value. A given expression can either be an L value or an R value expression. Reference model of variables: a variable is a named reference to a value. Every variable is an L-value. When the value appears in a context that expects an R-value is must be dereferenced in order to obtain the value to which it refers. The distinction is important b/c it can affect the program's behaviors and hence its output. The distinction becomes particularly important in programs w/linked data structurs, as in these programs the value to which variables refer may change in place.

Why is it impossible to catch all uses of uninitialized variables at compile time?

Variables that are allocated in the stack or heap at run-time must be initialized at runtime and it is not possible to catch these values The value of a variable may be destroyed b/c of some programming operations like explicit deallocation of an object referenced through a pointer. These types of uninitialized variables can't be caught at compilation time.

Self-hosting compiler

Written in the language they compile. Need to use bootstrapping to do this: start with a simple implementation and then use that to build more sophisticated versions

Create NFA from a set of regular expressions

https://www.youtube.com/watch?v=dlH2pIndNrU

Create DFA from an NFA

https://www.youtube.com/watch?v=taClnxU-nao


Conjuntos de estudio relacionados

Chapter 40: Fluid, Electrolyte, and Acid-Base Balance

View Set

RH OpenShift I: Containers & Kubernetes 4.5

View Set

The Secret Life of Bees Chapters 6-7 Review

View Set

Saunders ch 5: Cultural Awareness and Health Practices

View Set

'The Day the World Almost Came to an End'~Literature

View Set

Obesity Pathophysiology and Dyslipidemia

View Set