Getting to know decaf
This presentation is the property of its rightful owner.
Sponsored Links
1 / 8

Getting to Know Decaf PowerPoint PPT Presentation


  • 50 Views
  • Uploaded on
  • Presentation posted in: General

Getting to Know Decaf. Goals for Today: Get acquainted with the Decaf language Get experience with ASTs. The Decaf Language. Activity #1: With a partner: Using the Decaf language specification handout, and comparing with either Java or C++:

Download Presentation

Getting to Know Decaf

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Getting to know decaf

Getting to Know Decaf

Goals for Today:

Get acquainted with the Decaf language

Get experience with ASTs


The decaf language

The Decaf Language

Activity #1:

With a partner:

Using the Decaf language specification handout, and comparing with either Java or C++:

1. Create a list of similarities between Decaf and Java/C++

2. Create a list of differences between Decaf and Java/C++

Be ready to discuss your results, and also turn in your written listings with your names on it at the end of the activity.

Timing:

20 minutes – reading and list creation

15 minutes – reporting out – charts on the board, discussion


Abstract syntax trees

Abstract Syntax Trees

What are they?

Give example for some strings of the grammar:

E -> E + T | E – T | T

T -> T * a | T / a | a


Building an ast during parsing

4

num

S

state semantic value

Parsing Stack

Building an AST during Parsing

S -> E{ $$ = $1; root = $$; }

E -> E + T{ $$ = makenode(‘+’, $1, $3);} // E is $1, - is $2, T is $3

E -> E - T{ $$ = makenode(‘-’, $1, $3);}

E -> T{ $$ = $1;} // $$ is top of stack

T -> ( E ){ $$ = $2;}

T -> id{ $$ = makeleaf(‘idnode’, $1);}

T -> num{ $$ = makeleaf(‘numnode’, $1);}

Consider parsing 4 + ( x - y )

S


Getting to know the decaf compiler ast representation

Getting to know the Decaf Compiler AST Representation

Consider the Decaf program:

void main() {

Print("hello world");

}


The decaf parser output

The Decaf Parser Output

Program:

1 FnDecl:

(return type) Type: void

1 Identifier: main

(body) StmtBlock:

PrintStmt:

2 (args) StringConstant: "hello world"


Practice with decaf asts

Practice with Decaf ASTs

Activity 2: With a partner, draw an AST for the Decaf program using the grammar from the Decaf specification language handout:

class Cow {

int height;

boolisSpotted;

void Moo() {

Print ( this.height, " ", isSpotted, "\n" );

}

}

void main() {

Cow betsy;

betsy = New(Cow);

betsy.Moo();

}


The decaf parser output1

The Decaf Parser Output

Program:

1 ClassDecl:

1 Identifier: Cow

2 VarDecl:

Type: int

2 Identifier: height

3 VarDecl:

Type: bool

3 Identifier: isSpotted

4 FnDecl:

(returntype) Type: void

4 Identifier: Moo

(body) StmtBlock:

PrintStmt:

5 (args) FieldAccess:

5 This:

5 Identifier: height

5 (args) StringConstant: " "

5 (args) FieldAccess:

5 Identifier: isSpotted

5 (args) StringConstant: "\n"

10 FnDecl:

(returntype) Type: void

10 Identifier: main

(body) StmtBlock:

11 VarDecl:

11 NamedType:

11 Identifier: Cow

11 Identifier: betsy

12 AssignExpr:

12 FieldAccess:

12 Identifier: betsy

12 Operator: =

12 NewExpr:

12 NamedType:

12 Identifier: Cow

13 Call:

13 FieldAccess:

13 Identifier: betsy

13 Identifier: Moo


  • Login