Docsity

Slides on Implementing Block-Structured Language | CS 403, Study notes of Programming Languages

Toggle sidebar
bg1
1
Fall 2002 CS 403 Class Notes Page 1
CS 403 –10/17/2002
•Today
–Chapter 6: Implementing Block-Structured
Languages
•Reading Assignment for Tuesday
–Chapter 9, with 10 to follow, probably on Thursday
Fall 2002 CS 403 Class Notes Page 2
Association of Computing Machinery
“The First Society in Computing”
We will be having a meeting, Thursday, October 24, 2002
at 7:00 p.m. in EE 119.
Join us to find out more details about the upcoming
“HackOff” Programming Competition -Cash Prizes.
Also, find out what it’s like to ride the “Vomit Comet.”
Anne Thomas will be sharing her experiences in weightlessness.
For more info, visit us at www.acm.eng.ua.edu
ACM
Fall 2002 CS 403 Class Notes Page 3
Advising –This week and next!
•This semester, most advising will be done in groups
rather than individually, especially for the
lowerclassmen.
•Seniors who are close to graduation may sign up for
individual advising appointments.
•There will be (at least) one group advising session
for students already taking CS400 level classes,
Friday, Oct 18, 10-12 in EE 110.
•See the CS Dept web page for more details.
•Sign up for times, group or individual.
•If you know of any problems, see me!
pf3
pf4
pf5

Partial preview of the text

Download Slides on Implementing Block-Structured Language | CS 403 and more Study notes Programming Languages in PDF only on Docsity!

Fall 2002 CS 403 Class Notes (^) Page 1

CS 403 – 10/17/

  • Today
    • Chapter 6: Implementing Block-Structured Languages
  • Reading Assignment for Tuesday
    • Chapter 9, with 10 to follow, probably on Thursday

Fall 2002 CS 403 Class Notes (^) Page 2

Association of Computing Machinery “The First Society in Computing”

We will be having a meeting, Thursday, October 24, 2002 at 7:00 p.m. in EE 119. Join us to find out more details about the upcoming “HackOff” Programming Competition - Cash Prizes.

Also, find out what it’s like to ride the “ Vomit Comet .” Anne Thomas will be sharing her experiences in weightlessness. For more info, visit us at www.acm.eng.ua.edu

ACM

Fall 2002 CS 403 Class Notes (^) Page 3

Advising – This week and next!

  • This semester, most advising will be done in groups rather than individually, especially for the lowerclassmen.
  • Seniors who are close to graduation may sign up for individual advising appointments.
  • There will be (at least) one group advising session for students already taking CS400 level classes, Friday, Oct 18, 10-12 in EE 110.
  • See the CS Dept web page for more details.
  • Sign up for times, group or individual.
  • If you know of any problems, see me!

Fall 2002 CS 403 Class Notes (^) Page 4

Programming Journal

  • Most were good.
  • Many had only passing references to

language design issues.

  • begin-end vs. { }
  • Pipes: using array[1] for input, arrary[0] for output
    • One suggestion “I/O” ‡ “1/0”?
  • Why do you have to write “System.out.println”?

Fall 2002 CS 403 Class Notes (^) Page 5

Programming Journal

  • VHDL
    • Do device names have to be 20 characters long?
    • “WITH” and “CASE” … differences seem subtle
    • “ELSE IF” and “ELSIF” – any difference?
    • => and <=
    • To illuminate a section of the LED, use 0, not 1
    • “floorplan” report means nothing to me
    • “VHDL makes life easier” – How?

Fall 2002 CS 403 Class Notes (^) Page 6

Programming Journal

  • Only one paper received no credit.
  • It had about 10 bullets like
    • Uninitialized variables
    • Variables refuse to cooperate
    • Naming variables
    • Compiling on UNIX errors
    • Exec() has errors in PCGrasp
    • Visual has no fork
  • No explanation what any of it meant, or even

what language it applied to.

Fall 2002 CS 403 Class Notes (^) Page 10

Figure 6.

Fall 2002 CS 403 Class Notes (^) Page 11

Figure 6.2 – AR stack

  • Each AR has its

own EP.

  • To reach a variable

in the AR, you

need an offset from

the AR base.

  • Two coordinates
  • The global EP is

the current

environment/

procedure.

Fall 2002 CS 403 Class Notes (^) Page 12

Static Nesting Level

  • SNL [Not “Saturday Night …”]
  • Can be determined by compiler, never

changes.

  • Take the SNL of the current procedure.
  • Subtract the SNL of the environment that

defines the variable you’re looking for to

determine the “Static Distance” (SD)

  • SD ‡ the number of static links you have to follow to get to the right AR for your variable.

Fall 2002 CS 403 Class Notes (^) Page 13

Activation Record Stack

  • Every call to a procedure pushes another AR

on the AR stack. Each AR must have:

  • EP in that points down the stack to the procedure that is the enclosing context, the static link.
  • IP to save the next instruction – particularly important if the current instruction is a call to another procedure – this becomes the return address.
  • Dynamic Link to the AR of the calling procedure.

Fall 2002 CS 403 Class Notes (^) Page 14

Activating a Procedure

  • Save the caller’s state
    • Variables, etc. should already be right
    • Set the IP, EP to be ready for return
  • Create a new AR on top of the stack
    • Parameters (array?)
    • Static link
    • IP
    • Dynamic Link fl old external EP
    • External EP fl address of new AR
    • SP += size (callee’s new AR)
  • Transfer control from the caller to the callee
    • goto entry(callee)

Fall 2002 CS 403 Class Notes (^) Page 15

Procedure Exit

  • Reverse the procedure for activating:
  • Delete the old AR
    • SP -= size (callee’s AR)
  • Restore the state of the caller
    • External EP fl Caller’s AR (Callee’s Dynamic Link)
    • goto Caller’s IP

Fall 2002 CS 403 Class Notes (^) Page 19

Shallow Binding Method

  • Third alternative –
  • Keep one static AR for each procedure.
  • If you have a recursive call, save the contents

of the AR on a stack, then return it when the

called procedure returns.

  • You can’t have dynamic arrays in the AR. If

you really want them, you have to put them on

the heap or somewhere else in memory.

Fall 2002 CS 403 Class Notes (^) Page 20

Blocks – Degenerate Procedures

  • Algol, Ada & C allow you to declare variables

at the beginning of a new block.

  • So each block that declares variables must

have its own Activation Record!

  • Use the same procedures as for Static Chain

or Display Stack, but you can optimize them

somewhat.

Fall 2002 CS 403 Class Notes (^) Page 21

End of class

  • Read chapter 9 for Tuesday.
  • Check web page for Forum notices