section 7 n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Section 7 PowerPoint Presentation
Download Presentation
Section 7

Loading in 2 Seconds...

play fullscreen
1 / 11

Section 7 - PowerPoint PPT Presentation


  • 85 Views
  • Uploaded on

Section 7. Patrick Larson CSE341 – Spring 2013. Abstract Syntax Trees. (add 2 2 ) (add ( const 2) ( const 2)) (add ( const 2) ( bool #t)). Abstract Syntax Trees. (add 2 2 ) Incorrect Syntax (add ( const 2) ( const 2)) Correct Syntax, Correct Semantics

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Section 7' - marlee


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
section 7

Section 7

Patrick Larson

CSE341 – Spring 2013

abstract syntax trees
Abstract Syntax Trees

(add 2 2)

(add (const 2) (const 2))

(add (const 2) (bool #t))

abstract syntax trees1
Abstract Syntax Trees

(add 2 2)

Incorrect Syntax

(add (const 2) (const 2))

Correct Syntax, Correct Semantics

(add (const 2) (bool #t))

Correct Syntax, Incorrect Semantics

abstract syntax trees2
Abstract Syntax Trees

When evaluating an AST, we are not required to check for bad syntax

But we ARE required to check for bad semantics

abstract syntax trees3
Abstract Syntax Trees

Evaluation can assume a legal syntax tree

If the input is illegal the evaluation may crash

(But this is okay!)

We DO need to check that the return types of sub-expressions are correct

abstract syntax trees4
Abstract Syntax Trees

Interpreter should return expression, but only expressions that evaluate to themselves.

Otherwise we haven’t interpreted far enough

mupl macros
MUPL “macros”

We are interpreting MUPL with Racket

And MUPL is just Racket data

So why not write a Racket function that returns a MUPL AST?

quote
Quote

Racket statements can be thought of as lists of tokens

We can use the built in quote operation to turn a racket program into a list of tokens

We can use an apostrophe as syntactic sugar.

quasiquote
Quasiquote

Useful for inserting expressions into a quote

Use unquote to escape a quote and evaluate it

Quasiquote and quote are the same unless we have an unquote expression

Can use the back tick for quasiquote and , for unquote

slide10
Eval

Treat the input data as a program and run it!

This means we need a language implementation at runtime

(This is useful, but there is typically a better way to do things)