331 Final Spring 2011. Details 6-8 pm next Monday Comprehensive with more emphasis on material since the midterm Study example finals and midterm exams.

Slides:



Advertisements
Similar presentations
Lisp. Versions of LISP Lisp is an old language with many variants Lisp is alive and well today Most modern versions are based on Common Lisp LispWorks.
Advertisements

1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
CSE 341 Lecture 16 More Scheme: lists; helpers; let/let*; higher-order functions; lambdas slides created by Marty Stepp
Lambda Calculus and Lisp PZ03J. Lambda Calculus The lambda calculus is a model for functional programming like Turing machines are models for imperative.
Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
CS 355 – PROGRAMMING LANGUAGES Dr. X. Apply-to-all A functional form that takes a single function as a parameter and yields a list of values obtained.
331 Final Fall Details 3:30-5:30 Monday, December 16 ITE 229 (this room!) Comprehensive with more emphasis on material since the midterm Look at.
1-1 An Introduction to Scheme March Introduction A mid-1970s dialect of LISP, designed to be a cleaner, more modern, and simpler version than.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
176 Formal Languages and Applications: We know that Pascal programming language is defined in terms of a CFG. All the other programming languages are context-free.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Lisp. Versions of LISP Lisp is an old language with many variants –LISP is an acronym for List Processing language Lisp is alive and well today Most modern.
Chapter 15 Functional Programming Languages. Copyright © 2007 Addison-Wesley. All rights reserved. 1–2 Introduction Design of imperative languages is.
CS 330 Programming Languages 11 / 18 / 2008 Instructor: Michael Eckmann.
Snick  snack CPSC 121: Models of Computation 2010 Winter Term 2 DFAs in Depth Benjamin Israel Notes heavily borrowed from Steve Wolfman’s,
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester, 2010
Normal forms for Context-Free Grammars
Functional programming: LISP Originally developed for symbolic computing First interactive, interpreted language Dynamic typing: values have types, variables.
Chapter 3: Formal Translation Models
Introduction to Finite Automata Adapted from the slides of Stanford CS154.
CPSC 388 – Compiler Design and Construction Scanners – Finite State Automata.
CSC3315 (Spring 2009)1 CSC 3315 Programming Paradigms Scheme Language Hamid Harroud School of Science and Engineering, Akhawayn University
ISBN Chapter 15 Functional Programming Languages.
Functional Programming in Scheme and Lisp. Overview In a functional programming language, functions are first class objects. You can create them, put.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 7.
Lecture # 3 Chapter #3: Lexical Analysis. Role of Lexical Analyzer It is the first phase of compiler Its main task is to read the input characters and.
Functional Programming and Lisp. Overview In a functional programming language, functions are first class objects. In a functional programming language,
Automating Construction of Lexers. Example in javacc TOKEN: { ( | | "_")* > | ( )* > | } SKIP: { " " | "\n" | "\t" } --> get automatically generated code.
Grammars CPSC 5135.
CS 403: Programming Languages Lecture 6 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture of a compiler PART II:
Functional Programming in Scheme and Lisp.
Regular Expressions and Languages A regular expression is a notation to represent languages, i.e. a set of strings, where the set is either finite or contains.
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 11 Midterm Exam 2 -Context-Free Languages Mälardalen University 2005.
331 Final Fall Details 3:30-5:30 Friday December 17 th LH4 Comprehensive with more emphasis on material since the midterm Study example finals and.
Regular Expressions (RE's)– Review A means of describing a possibly infinite language in finite terms. We aim to turn a RE into a Deterministic Finite.
UMBC CMSC Common Lisp II. UMBC CMSC Input and Output Print is the most primitive output function > (print (list 'foo 'bar)) (FOO BAR) The.
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
Integers are… Positive whole numbers (Eg: 1, 2, 3, 4, ….)
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
Exercise Solution for Exercise (a) {1,2} {3,4} a b {6} a {5,6,1} {6,2} {4} {3} {5,6} { } b a b a a b b a a b a,b b b a.
CS 330 Programming Languages 11 / 28 / 2006 Instructor: Michael Eckmann.
1 FP Foundations, Scheme In Text: Chapter Chapter 14: FP Foundations, Scheme Mathematical Functions Def: A mathematical function is a mapping of.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Finding Regular Simple Paths Sept. 2013Yangjun Chen ACS Finding Regular Simple Paths in Graph Databases Basic definitions Regular paths Regular simple.
1.2 Three Basic Concepts Languages start variables Grammars Let us see a grammar for English. Typically, we are told “a sentence can Consist.
Chapter 5 Finite Automata Finite State Automata n Capable of recognizing numerous symbol patterns, the class of regular languages n Suitable for.
1 Language Recognition (11.4) Longin Jan Latecki Temple University Based on slides by Costas Busch from the courseCostas Busch
Forms Writing your own procedures CS 480/680 – Comparative Languages.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
Department of Software & Media Technology
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
Functional Programming Languages
CS 326 Programming Languages, Concepts and Implementation
Classification of Languages
Chapter 15 – Functional Programming Languages
Lists in Lisp and Scheme
Deterministic Finite Automata
COP4020 Programming Languages
Finite Automata & Regular Languages
Deterministic Finite Automata
REGULAR LANGUAGES AND REGULAR GRAMMARS
FP Foundations, Scheme In Text: Chapter 14.
Introduction to Finite Automata
Deterministic Finite Automaton (DFA)
Common Lisp II.
Lisp.
Presentation transcript:

331 Final Spring 2011

Details 6-8 pm next Monday Comprehensive with more emphasis on material since the midterm Study example finals and midterm exams from earlier semesters Read assigned material from book and schedule

Example Problem For each of the following grammars, briefly describe the language it defines in a sentence or two. Assume that the start symbol is S for each and that any symbol found only on the right hand side of a production is a terminal symbol. (1b) 5 points. S -> B A S -> a B -> S A A -> a

Example Problem For each of the following grammars, briefly describe the language it defines in a sentence or two. Assume that the start symbol is S for each and that any symbol found only on the right hand side of a production is a terminal symbol. (1c) 5 points. S -> a | aa S -> a X S -> b S b S -> b | bb X -> S a

Example Problem (a) Draw a DFA for a real number that satisfies the following description, using the conventions above. A real number can start with an optional sign which can be "-" or "+" and consists of an integer part followed by a decimal point followed by a fractional part. The integer part can be a single zero or a non-empty sequence of digits that does not start with a zero. The fractional part is a non-empty sequence of digits. Positive examples include 0.0, +0.0, 0.12, 12.3 and Negative examples are: 0, 01.2, -01.2, 3. and 42. Identify the start state and all accepting states and label every arc. Since this is a deterministic and not a non-deterministic finite automaton, every arc must have a label which can not be epsilon. (b) Write a regular expression that corresponds to the DFA, making it as simple as possible. Use parentheses to ensure proper scope or for clarity. (15 points)

Example Problem Assuming that we’ve done (define x '((1 (2)) (3))) give a Scheme expression using only the functions car and cdr and variable x that returns the second symbol in the list

Example Problem Common Lisp has a built-in function maplist. The Scheme counterpart could be written as follows: (define (maplist f l) (if (null? l) null (append (f l) (maplist f (cdr l))))) [10] What will (maplist list '(1 2 3)) return? [10] What will (maplist (lambda (x) x) '(1 2 3)) return? [10] What will (maplist (lambda (x) (list (length x))) '(1 2 3))

Example Problem Consider a function insert with three arguments: an arbitrary s-expression, a proper list, and a positive integer. The function returns a new list that is the result of inserting the expression into the list at the position specified by the third argument. Note that positions begin with zero. For example, > > (insert 'X '(a b c) 3) (a b c X) > > (insert '(X) '(a b c) 1) (a (X) b c) > > insert 'X '(a b c) 0) (X a b c) Here is an incomplete definition of the function. Give code expressions for, and that will complete it. (define (insert expr lst pos) ;; Returns a list like proper list lst but with expr inserted at ;; the position given by positive integer pos. e.g.: (insert 'X ;; '(a b c) 2) => (a b X c) (cond ( (cons expr lst)) ((null? lst) ) (else )))

Perl (or Lisp) Write a function weight that takes a single argument and returns its weight, where the weight of a non-list is 1 and the weight of a list of N elements is N plus the sum of the weights of the elements.