Semantics - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Semantics

Description:

(5) (goto,-,-,L3) (6) (label,-,-,L2) (7) (:=,b,-,q) (8) (label,-,-,L3) February 17, 2000 ... (4) (goto,-,-,Q1) (5) . . . using relative quadruple labels (1) ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 14
Provided by: francesl
Category:
Tags: goto | semantics

less

Transcript and Presenter's Notes

Title: Semantics


1
Semantics
  • CS 236 - Lecture 11
  • West Virginia University
  • February 17, 2000
  • Frances L. Van Scoy
  • fvanscoy_at_wvu.edu

2
Overview
  • Intermediate Code
  • Examples of Intermediate Code Generated from
    Program Fragments

3
Intermediate Code
  • generated by Intermediate Code Generator
  • is a notation intermediate in complexity between
    high level programming language and assembly
    language

4
Some Forms of Intermediate Code
  • post fix notation
  • trees
  • triples
  • quadruples

5
Post fix notation examples
  • x a - b c d
  • x a b c - d
  • x a b - c d
  • x a b c d -

6
Syntax tree examples
x a - b c d
x a b - c d


x
-
x



-
d
a
b
c
d
a

c
b
7
Triple examples
  • x a - b c d
  • (1) (, b, c)
  • (2) (-, a, (1))
  • (3) (, (2), d)
  • (4) (, (3), x)
  • x a b - c d
  • (1) (, a, b)
  • (2) (, c, d)
  • (3) (-, (1), (2))
  • (4) (, (3), x)

8
Quadruple examples
  • x a - b c d
  • (1) (, b, c, temp1)
  • (2) (-, a, temp1, temp2)
  • (3) (, temp2, d)
  • (4) (, temp3, -, x)
  • x a b - c d
  • (1) (, a, b, temp1)
  • (2) (, c, d, temp2)
  • (3) (-, temp1, temp2, temp3)
  • (4) (, temp3, -, x)

9
Quadruples from If Statement
  • if x gt y then w a else w b
  • using absolute quadruple numbers
  • (1) (-,x,y,temp1)
  • (2) (gt0,temp1,Q3,Q5)
  • (3) (,a,-,w)
  • (4) (goto,-,-,Q6)
  • (5) (,b,-,q)
  • (6) . . .
  • using relative quadruple labels
  • (1) (-,x,y,temp1)
  • (2) (gt0,temp1,L1,L2)
  • (3) (label,-,-,L1)
  • (4) (,a,-,w)
  • (5) (goto,-,-,L3)
  • (6) (label,-,-,L2)
  • (7) (,b,-,q)
  • (8) (label,-,-,L3)

10
Quadruples from While statement
  • while x gt y loop z z 3
  • using absolute quadruple numbers
  • (1) (-,x,y,temp1)
  • (2) (gt0,temp1,Q3,Q5)
  • (3) (,z,3,temp2)
  • (4) (,temp2,-,z)
  • (4) (goto,-,-,Q1)
  • (5) . . .
  • using relative quadruple labels
  • (1) (label,-,-,L1)
  • (1) (-,x,y,temp1)
  • (2) (gt0,temp1,L2,L3)
  • (3) (label,-,-,L2)
  • (4) (,z,3,temp2)
  • (5) (,temp2,-,z)
  • (6) (goto,-,-,L1)
  • (7) (label,-,-,L3)
  • (8) (label,-,-,L3)

11
Quadruples from Procedure or Function Calls
  • assume procedure P(x,y)
  • and procedure Q(a,b,c).
  • P(10,result)
  • (1) (param,-,-,10)
  • (2) (param,-,-,result)
  • (3) (call,P,2,-)
  • Q(x,y,z)
  • (1) (param,-,-,x)
  • (2) (param,-,-,y)
  • (3) (param,-,-,z)
  • (4) call (Q,3,-)
  • assume function f(x,y) and function g(a,b,c)
  • z g(10n,f(p,q),w)
  • (1) (,10,n,temp1)
  • (2) (param,-,-,temp1)
  • (3) (param,-,-,p)
  • (4) (param,-,-,q)
  • (5) (call,F,2,temp2)
  • (6) (param,-,-,temp2)
  • (7) (param,-,-,w)
  • (8) (call,g,3,temp3)
  • (9) (,temp3,-,z)

12
Summary
13
Quiz
Write a Comment
User Comments (0)
About PowerShow.com