• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/39

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

39 Cards in this Set

  • Front
  • Back

pascal indicates pass by reference with word

var

pascal default parameter passing mode

value

what do we assume about a pascal compiler?

required each symbol to be declared prior (in lexical order) to any other use of the symbol and assume that such a compiler makes just one-pass through the program

pascal symbol tables stores

for each constant: name, type value




for each type: name, number of bytes per instance, some structure info




for each variable: name, type, snl, number of bytes needed for the previously declared parameters/ variables in current block




for each subprogram: name, kind (procedure or function), snl, return type (functions only), address of its first machine code instruction, and access to info in its parameter list




for each parameter: same as for variable but plus mode (value or reference)

when is a forward declaration of a subprogram required?

when a program uses indirect recursion


machine code calls on that subprogram generated prior (during the one time pass) to the instructions for that subprogram can't contain the needed address of that subprogram's first machine language instruction, the one-pass compiler simply backpatches that address into the already generated machine code using some extra bookeeping.

where does the design of pascal lack regular rules?

use of var, declare variables and indicate pass by reference

static mother

subprogram's immediately enclosing program unit


defined by text of the program regardless of nature of input data

dynamic program

subprogram's caller(s)


depends on the nature of the input data and can change during the execution of the program, need to talk about at a particular point in time during program execution

syntax of pascal forces us to put the four declaration sections in a program unit in exactly the order:

const, type, var, subprograms


can omit one or all of decl sections

syntax of pascal forces us to put the block of (executable) statements...

after all the declarations in that program unit

why can pascal support recursion?

memory locations for parameters and variables defined in a program unit are not stored in the block for tat program unit. Pascal distinguishes between the code block for a program unit (which never changes from one activation of that program unit to another) and the data the program unit uses that can be different for different activations of the program unit, the data is stored in activation records for the program unit.




in the pascal memory map each program unit can have as many activation records as the space for the run time stack permits and those activation records are set up dynamically after run time begins and the main memory space for an activation record of a program unit is reused by other activation records after that program unit returns control to its caller

arrays in pascal are stored in ___

row major order

records in pascal

the info in a record is stored in the order the fields of the record are declared, space is also reserved for the tag field is the record is a variant record

case statements

labeled case statement


tony hoare


high level and efficiently implementable


control structure not data structure but a jump table is often stored in the code block for a program unit to represent a case statement in the program unit


run time no longer depends on order (if implemented with ifs)

high level and efficiently implementable construct in pascal

labeled case statement

algorithm to determine static distance

1.compiler access var with current snl


2.compiler access var's snl from declaration


subtract 1 from 2

how compiler can keep track of current snl

keep var current snl, add 1 when enter program unit, subtract 1 when exit

why should run time stack be a stack rather than some other structure?

need to be ale to pop off subprograms AR after return control to caller and pop on when control is passed from caller to callee

why does the code block for the main program unit occur last among the code blocks in the memory map?

last to be popped off stack

in what sense are heap and runtime stack not static

dynamic mother can change during execution based on nature of input data have to speak about it at certain point in time


nature of data structures can vary based on nature of input

how well does jump table support a one-pass compiler?

otherwises have to be backpatched


all other cases machine code doesn't have to be backpatched

when would translating a case statement into if statements in assembly language be more efficient than a jump table ?

array could be a billion values but only take on 3 values , huge number of otherwise

major design goals of pascal, which one related to one pass compiler? how does that design goal compromise the other design goal?

1.The language should be suitable for teaching programming in a systematic way


2. The implementation of the language should be reliable and efficient, at compile time and run-time, on available computers.


efficient-> one pass compiler-> each use of symbol must be earlier declared->


main has to be at bottom but top level logic is given by main. same with subprograms. hard for students to understand step-wise refinement

Give three strategic decisions related to arrays that Wirth made in designing Pascal. How do these three decisions interact in an unreasonable way?

1. all types must be determined at compile-time, types are static


2. the dimensions are part of an array type


3. pascal enforces strong typing; therefore types of actuals must agrees with types of formals




1 and 2 -> dimension of array is static, determined at compile time


2 and 3-> formal and actual parameters must both be arrays since pascal enforces strong typing, dim is a type so arrays have to have same dimension


1,2,3 -> not reasonable have to define methods for every array size since actual and formal parameters must match and im is part of type, could use max size and have every array be same size




Since dimensions of an array are part of its type this means the dimensions of an actual array parameter must agree with the dimensions of the corresponding formal array parameter.

What does MacLennan think were the disadvantages of PL/1 of Algol-68?

PL/1 was so large as to be unmanageable and too complicated to be mastered by most programmers


algol is large and excessively complex

What were disadvantages of extensible languages?

Necessity of handling variable syntax made extensible compilers large and unreliable




All source constructs were ultimately reduced to kernel language constructs meant that minor inefficiencies in the kernel implementation became magnified at the application language level




Most of the error checking was done by the kernel language compiler, most diagnostics were issued in terms of kernel language constructs

strong typing

“A strongly typed language is one that may permit coercions but prohibits any operation on a piece of data that is incompatible with the type of the data.”

advantages and disadvantages of strongly typed language

Prevents users from making errors that would compromise program security


Makes code more complicated


Less flexibility




Strongly typed and static: Compiler can complain about things, find out about errors more quickly at compile time vs run time




Disadvantage: difficult to draw memory maps, linker has to work with bit patterns regardless of what they mean,

Give two huge ways in which Fortran fails to be a strongly typed language.

Labeled common and Parameter passing, actuals and formals don’t have to match, don’t have to match across program units

Give two huge ways in which Pascal fails to be a strongly typed language.

You can pass a function subprogram as a parameter to another subprogram. Functional parameter, actual and formal correspondence, types for function don’t have to be clear (what does function return), function could expect that function will return integer but may return characters




Variant records, tags all share same memory address and no type check when tag is changed

Did the designer of Pascal intentionally want Pascal to be less than a fully strongly typed language.

Variant records, intentional for systems programming

How are Pascal arrays and records fundamentally different and how are they implemented?

Arrays store homogeneous elements and have dynamic selectors. Records store heterogeneous data and have static selectors. Because records have static selectors we cannot write a loop to process all the elements of records like with arrays. Because Pascal is statically typed and all elements of arrays are the same type, the compiler knows the type of every element in the array even if it does not know what element is selected. This is not the case with records.




Arrays subscripts, records use dots


Arrays row major order storage


You can compute the selector to be used with arrays

Pointers (vs. PL/1 pointers)

Pascal pointers are strong typed so the compiler can enforce strong typing even when pointers are used. PL/1 pointers types allow the type system to be subverted.

Subranges

Allow compiler to economize on storage utilization. For example, DaysOfMonth can take on 31 values, stored in 5 bits rather than 16 or 32 required for integers. Enables checking to be done at compile time rather than run time because an invalid value can’t be held if a variable is subranged.

Enumerated types (vs. using integer constants)

Static checks are possiblePrevents programmer errors and makes code more clear to the reader. Can have an enumerated type called days of the week and list the names of the days of the week vs using 0-6.

Constants

Yes? Allow implicit dependencies to be made explicit, all dependent constants are abstracted out of the program and are given a name.

variant records

Memory efficient. Allows data to be grouped according to the status with which they are associated: certain attributes are possessed by all objects regardless of their status but other attributes only have meaning when an object is in a certain status. But Pascal does not require the programmer to initialize the fields of a variant after changing the value of the tag field so the values found here will be whatever was left there from the previous variant record.

sets

Sets are very high level, they allow the programmer to write algorithms in a natural notation. They are also very efficient in terms of space, a set of 10 integers can be represented using 10 bits. Set operations are also very simple to implement and very fast (ex. and operation). Disadvantage: homogeneous?

name equivalence (over structural equivalence)

Name equivalence is generally safer since it is more restrictive. If a type is declared twice, they probably have a reason for doing it (represent different things). Considering these types different protects the security of the program by preventing the programmer from doing something meaningless. Name equivalence is simpler to implement; the compiler has to compare only the character strings representing the names of types. For structural equivalence it is necessary to write a recursive function that compares the data structures representing the types of the two objects which also slows down the compiler. Less flexible, could have same structure but different names and can’t assign