331 Final Fall 2013. Details 3:30-5:30 Monday, December 16 ITE 229 (this room!) Comprehensive with more emphasis on material since the midterm Look at.

Slides:



Advertisements
Similar presentations
Functional Programming. Pure Functional Programming Computation is largely performed by applying functions to values. The value of an expression depends.
Advertisements

Chapter 3 Functional Programming. Outline Introduction to functional programming Scheme: an untyped functional programming language.
Grammars, constituency and order A grammar describes the legal strings of a language in terms of constituency and order. For example, a grammar for a fragment.
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
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.
ISBN Chapter 3 More Syntax –BNF –Derivations –Practice.
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.
CS 330 Programming Languages 09 / 18 / 2007 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,
Normal forms for Context-Free Grammars
Chapter 3: Formal Translation Models
1.Defs. a)Finite Automaton: A Finite Automaton ( FA ) has finite set of ‘states’ ( Q={q 0, q 1, q 2, ….. ) and its ‘control’ moves from state to state.
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
Fortran 1- Basics Chapters 1-2 in your Fortran book.
CPSC 388 – Compiler Design and Construction Scanners – Finite State Automata.
CS 2104 Prog. Lang. Concepts Dr. Abhik Roychoudhury School of Computing Introduction.
CS 152: Programming Language Paradigms February 24 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
331 Final Spring Details 6-8 pm next Monday Comprehensive with more emphasis on material since the midterm Study example finals and midterm exams.
1 Regular Expressions. 2 Regular expressions describe regular languages Example: describes the language.
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.
Chapter 1: Inductive Sets of Data Recall definition of list  '() is a list.  If l is a list and a is any object, then (cons a l ) is a list More generally:
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.
Languages, Grammars, and Regular Expressions Chuck Cusack Based partly on Chapter 11 of “Discrete Mathematics and its Applications,” 5 th edition, by Kenneth.
Grammars CPSC 5135.
LANGUAGE DESCRIPTION: SYNTACTIC STRUCTURE
C H A P T E R TWO Syntax and Semantic.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
Regular Grammars Chapter 7. Regular Grammars A regular grammar G is a quadruple (V, , R, S), where: ● V is the rule alphabet, which contains nonterminals.
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.
CPS 506 Comparative Programming Languages Syntax Specification.
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.
D Goforth COSC Translating High Level Languages.
Chapter 2 – Properties of Real Numbers 2.1 – The Real Number Line.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
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.
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.
David Evans CS200: Computer Science University of Virginia Computer Science Lecture 19: Environments.
Exercise 1 Consider a language with the following tokens and token classes: ID ::= letter (letter|digit)* LT ::= " " shiftL ::= " >" dot ::= "." LP ::=
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
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.
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.
C H A P T E R T W O Syntax and Semantic. 2 Introduction Who must use language definitions? Other language designers Implementors Programmers (the users.
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.
Real Numbers and the Number Line
Week 14 - Friday.  What did we talk about last time?  Simplifying FSAs  Quotient automata.
Syntax(1). 2 Syntax  The syntax of a programming language is a precise description of all its grammatically correct programs.  Levels of syntax Lexical.
Department of Software & Media Technology
Artificial Intelligence and Lisp Lecture 6 LiU Course TDDC65 Autumn Semester,
Chapter 1: Inductive Sets of Data
PROGRAMMING LANGUAGES
CS 326 Programming Languages, Concepts and Implementation
CS 153: Concepts of Compiler Design October 17 Class Meeting
Syntax (1).
Classification of Languages
CS314 – Section 5 Recitation 3
Deterministic Finite Automata
COP4020 Programming Languages
Lexical and Syntax Analysis
Deterministic Finite Automata
REGULAR LANGUAGES AND REGULAR GRAMMARS
Chapter 7 Regular Grammars
FP Foundations, Scheme In Text: Chapter 14.
Introduction to Finite Automata
Common Lisp II.
Lisp.
Presentation transcript:

331 Final Fall 2013

Details 3:30-5:30 Monday, December 16 ITE 229 (this room!) Comprehensive with more emphasis on material since the midterm Look at the review page – We may update this, so watch your Study past finals and midterm exams, especially those from fall 2008, spring 2010, and fall 2010

Readings Read all assigned material from book and schedule From the text: chapters 1, 2, 3, 4, 5, 9 and 16 From the web: read things marked as read on the schedule

For Help Think Look in our text Search the Web Use the discussion forum to post questions or ask for clarification Seek help from the TAs me

Example Problem Briefly describe the language this grammar defines in a sentence or two. Assume that the start symbol is S and that any symbol found only on the right hand side of a production is a terminal symbol. S -> B A S -> a B -> S A A -> a

Example Problem Briefly describe the language this grammar defines in a sentence or two. Assume that the start symbol is S and that any symbol found only on the right hand side of a production is a terminal symbol. S -> a | aa S -> a X S -> b S b S -> b | bb X -> S a

EBNF to BNF Assume that you have already been given grammars for the non-terminals and which represent identifiers and expressions, respectively. Rewrite the following EBNF grammar in BNF. You may create new non-terminal symbols if you wish. ::= '=' ::= 'IF' 'THEN' [ 'ELSE' ] 'ENDIF' ::= 'WHILE' 'DO' 'ENDWHILE' ::= 'BEGIN' {';' } 'END'

EBNF to BNF ::= '=' ::= 'IF' 'THEN' [ 'ELSE' ] 'ENDIF’ ::= 'WHILE' 'DO' 'ENDWHILE’ ::= 'BEGIN' {';' } 'END’ Becomes ::= '=' ::= 'IF' 'THEN' 'ENDIF’ ::= 'IF' 'THEN' 'ELSE’ 'ENDIF’ ::= 'WHILE' 'DO' 'ENDWHILE’ ::= 'BEGIN' 'END’ ::= ::= ;

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.

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 2 in the list

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

Example Problem Consider a function insert with three args: an arbitrary 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. If the integer is greater than the length of the list, put the expression at the end. > > (insert 'X '(a b c) 3) (a b c X d) > > (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 )))