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

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 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 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 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 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 bi’s evaluate to NIL, that is an error.bi’s evaluate to NIL, that is an error....
View Full Document

This note was uploaded on 04/10/2008 for the course CSE 755 taught by Professor Neelamsoundarajan during the Winter '05 term at Ohio State.

Page1 / 16

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

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online