Extending Tiny - PowerPoint PPT Presentation

1 / 19
About This Presentation
Title:

Extending Tiny

Description:

Extending Tiny. Prefix auto-increment. Problematic. ... Tiny's AG. To save time (and space), we'll track only code, next, top ... – PowerPoint PPT presentation

Number of Views:244
Avg rating:3.0/5.0
Slides: 20
Provided by: manuelb9
Category:
Tags: extending | tiny

less

Transcript and Presenter's Notes

Title: Extending Tiny


1
Extending Tiny
Programming Language Principles Lecture 19
  • Prepared by
  • Manuel E. Bermúdez, Ph.D.
  • Associate Professor
  • University of Florida

2
Extending Tiny
  • Let's add a few more constructs to Tiny.
  • The repeat statement (a la Pascal).
  • Code
  • n E1
  • E2
  • iffalse n

3
The Repeat Statement (a la Pascal)
  • E ?
  • code ?(?) gen(code ?(2), "iffalse",next ?(?))
  • next ?(?) next ?(2) 1
  • top ?(?) top ?(2) - 1
  • error ?(?) if type ?(2)"bool"
  • then error ?(2)
  • else gen(error ?(2), "non-bool
    exp")
  • type ?(?) "statement"

4
(No Transcript)
5
Extending Tiny (contd)
  • The one-armed "if".
  • Code
  • E1
  • iffalse n
  • E2
  • n

6
The One-Armed "if"
  • E ?
  • code ?(2) gen(code ?(1), "iffalse",next ?(2))
  • next ?(2) next ?(1) 1
  • top ?(2) top ?(1) - 1
  • error ?(2) if type ?(1)"bool"
  • then error ?(1)
  • else gen(error ?(1), "non-bool exp")
  • type ?(?) "statement

7
(No Transcript)
8
Extending Tiny (contd)
  • Conditional Expression
  • Code
  • E1
  • iffalse n
  • E2
  • goto m
  • n E3
  • m

9
Conditional Expression
  • E ?
  • code ?(2) gen(code ?(1), "iffalse",next
    ?(2)1)
  • next ?(2) next ?(1) 1
  • top ?(2) top ?(1) - 1
  • error ?(2) if type ?(1)"bool"
  • then error ?(1)
  • else gen(error ?(1), "non-bool exp")

10
Conditional Expression (contd)
  • code ?(3) gen(code ?(2), goto",next ?(3))
  • next ?(3) next ?(2) 1
  • error ?(?) if type ?(2) type ?(3)
  • then error ?(3)
  • else gen(error ?(3), type
    mismatch")
  • top ?(?) top ?(3) - 1
  • type ?(?) type ?(2) ??? type ?(3) ???

11
(No Transcript)
12
Extending Tiny
  • Prefix auto-increment.
  • Problematic. If x has not been defined, what
    location do we reserve for it on the stack ?
  • Code
  • load n
  • lit 1
  • add
  • save n
  • load n n lookup(x)

13
Prefix Auto-Increment
  • E ?
  • code ?(?)
  • if lookup(x)0 then code ?(?)
  • else gen(
  • gen(
  • gen(
  • gen(
  • gen(code ?(?), "load", lookup(x)),
  • "lit", 1),
  • "add"),
  • "save", lookup(x)),
  • "load", lookup(x))

14
Prefix Auto-Increment (contd)
  • error ?(?) if lookup(x) !0
  • then error ?(?)
  • else gen(error ?(?), "var
    undefined")
  • next ?(?) next ?(?) 5
  • top ?(?) top ?(?) 1 ???
  • type ?(?) ???

15
(No Transcript)
16
A Sample "Compilation" Using Tiny's AG
  • To save time (and space), we'll track only code,
    next, top

17
A Sample "Compilation" Using Tiny's AG (contd)
  • Tiny program
  • program teeny
  • assign x read
  • if x1
  • then assign x0
  • else output x end
  • teeny.
  • Code file
  • read
  • load 1
  • lit 1
  • equal
  • iffalse 9
  • lit 0
  • save 1
  • goto 11
  • load 1
  • print
  • stop.

18
(No Transcript)
19
Extending Tiny
Programming Language Principles Lecture 19
  • Prepared by
  • Manuel E. Bermúdez, Ph.D.
  • Associate Professor
  • University of Florida
Write a Comment
User Comments (0)
About PowerShow.com