{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

n2 - Operational Semantics Specify semantics of a language...

Info icon This preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Operational Semantics: Specify semantics of a language by specifying how each command in the language is to be executed. One possible approach for O.S. of L : Define an interpreter for L . Metacircular interpreter for L : The interpreter is defined in L . Example: LISP. Scheme Scheme is a version of LISP . Main differences: Scope rule , elimination of some imperative features. References: McCarthy; Kurtz (Ch. 6); Pagan (Ch. 5). (The CIS 655 book by Sebesta has an intro to Scheme.) 17
Image of page 1

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Data Types : Atoms and S-expressions . Atoms : Numbers, strings, symbols S-expressions : Atoms are S-expressions. If s1, s2 are S-exp., so is (s1 . s2) . Important functions cons[ s1, s2 ] = (s1 . s2) car[ (s1 . s2) ] = s1 cdr[ (s1 . s2) ] = s2 Important atoms : T, NIL [NIL also written ( )]. T is used for ‘true’, NIL for ‘false’ as well as for an empty ‘list’. (Scheme48 uses #t for ‘true’, #f for ‘false’, and () for NIL.) List notation : ( s ) denotes (s . NIL) ( s t ) denotes (s . (t . NIL)) 18
Image of page 2
Lisp runs in an ‘eval-print’ mode. You type in a Lisp expression, it evaluates it, prints the result, and waits for the next expression. Lisp expressions: 1. Constants: 4, T, “xyz” 2. Function application: (F a1 a2 . . . ) f is the function to be applied, a1, a2, . . . are expressions that are arguments to F. Lisp evaluates each argument, then applies f to the resulting values. 3. Quoted values: eg.: (QUOTE (3 4 5)) [also ’(3 4 5)] This will evaluate to (3 4 5) [Just typing (3 4 5) will give an error message such as “3 is not applicable”.] 19
Image of page 3

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4. Conditional expression: (COND (b1 e1) (b2 e2) . . . (bn en)) Lisp will first evaluate b1. If it evaluates to a value other than NIL, it will evaluate e1, and that is the value of the expression. If b1 eval- uates to NIL, it will evaluate b2, etc. If all the
Image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern