1 / 11

Section 7

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

marlee
Download Presentation

Section 7

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Section 7 Patrick Larson CSE341 – Spring 2013

  2. Abstract Syntax Trees (add 2 2) (add (const 2) (const 2)) (add (const 2) (bool #t))

  3. 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

  4. 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

  5. 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

  6. Abstract Syntax Trees Interpreter should return expression, but only expressions that evaluate to themselves. Otherwise we haven’t interpreted far enough

  7. 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?

  8. 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.

  9. 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

  10. 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)

  11. Eval

More Related