CS3012 Formal Languages and Compilers Frank Guerin Room 227 Lectures Monday11:00MT3 Tuesday9:00105 St. Marys Tutorials Thursday13:00 Thursday 14:00definitely.

Slides:



Advertisements
Similar presentations
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Advertisements

Why empty strings? A bit like zero –you may think you can do without –but it makes definitions & calculations easier Definitions: –An alphabeth is a finite.
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
Formal Languages Languages: English, Spanish,... PASCAL, C,... Problem: How do we define a language? i.e. what sentences belong to a language? e.g.Large.
Chapter 6 Languages: finite state machines
Finite-State Machines with No Output Ying Lu
Natural Language Processing - Formal Language - (formal) Language (formal) Grammar.
1 Lecture 32 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union,
COMP-421 Compiler Design Presented by Dr Ioanna Dionysiou.
YES-NO machines Finite State Automata as language recognizers.
1 Languages. 2 A language is a set of strings String: A sequence of letters Examples: “cat”, “dog”, “house”, … Defined over an alphabet: Languages.
Finite Automata Great Theoretical Ideas In Computer Science Anupam Gupta Danny Sleator CS Fall 2010 Lecture 20Oct 28, 2010Carnegie Mellon University.
1 Introduction to Computability Theory Lecture3: Regular Expressions Prof. Amos Israeli.
1 Lecture 4: Formal Definition of Solvability Analysis of decision problems –Two types of inputs:yes inputs and no inputs –Language recognition problem.
1 CSCI-2400 Models of Computation. 2 Computation CPU memory.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
Regular Languages Sequential Machine Theory Prof. K. J. Hintz Department of Electrical and Computer Engineering Lecture 3 Comments, additions and modifications.
1 Languages and Finite Automata or how to talk to machines...
1 Module 31 Closure Properties for CFL’s –Kleene Closure construction examples proof of correctness –Others covered less thoroughly in lecture union, concatenation.
CS5371 Theory of Computation Lecture 4: Automata Theory II (DFA = NFA, Regular Language)
1 Module 4: Formal Definition of Solvability Analysis of decision problems –Two types of inputs:yes inputs and no inputs –Language recognition problem.
CS 3240 – Chuck Allison.  A model of computation  A very simple, manual computer (we draw pictures!)  Our machines: automata  1) Finite automata (“finite-state.
Topics Automata Theory Grammars and Languages Complexities
Languages and Machines Unit two: Regular languages and Finite State Automata.
Lecture 1 String and Language. String string is a finite sequence of symbols. For example, string ( s, t, r, i, n, g) CS4384 ( C, S, 4, 3, 8) (1,
Great Theoretical Ideas in Computer Science.
Regular Languages A language is regular over  if it can be built from ;, {  }, and { a } for every a 2 , using operators union ( [ ), concatenation.
Chapter 2 Languages.
Finite-State Machines with No Output
Lexical Analysis CSE 340 – Principles of Programming Languages Fall 2015 Adam Doupé Arizona State University
CS490 Presentation: Automata & Language Theory Thong Lam Ran Shi.
CS/IT 138 THEORY OF COMPUTATION Chapter 1 Introduction to the Theory of Computation.
CSC312 Automata Theory Lecture # 2 Languages.
CSC312 Automata Theory Lecture # 2 Languages.
Lecture Two: Formal Languages Formal Languages, Lecture 2, slide 1 Amjad Ali.
Introduction to Theory of Automata
Introduction to CS Theory Lecture 3 – Regular Languages Piotr Faliszewski
MA/CSSE 474 Theory of Computation Functions, Closure, Decision Problems.
1 Chapter 1 Introduction to the Theory of Computation.
Grammars CPSC 5135.
CS 3813: Introduction to Formal Languages and Automata
1 CD5560 FABER Formal Languages, Automata and Models of Computation Lecture 2 Mälardalen University 2006.
Great Theoretical Ideas in Computer Science.
Regular Expressions CIS 361. Need finite descriptions of infinite sets of strings. Discover and specify “regularity”. The set of languages over a finite.
Languages and Strings Chapter 2. (1) Lexical analysis: Scan the program and break it up into variable names, numbers, etc. (2) Parsing: Create a tree.
Strings and Languages CS 130: Theory of Computation HMU textbook, Chapter 1 (Sec 1.5)
Overview of Previous Lesson(s) Over View  Symbol tables are data structures that are used by compilers to hold information about source-program constructs.
CS 203: Introduction to Formal Languages and Automata
Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising.
CSCI 4325 / 6339 Theory of Computation Zhixiang Chen.
Pushdown Automata Chapter 12. Recognizing Context-Free Languages Two notions of recognition: (1) Say yes or no, just like with FSMs (2) Say yes or no,
Set, Alphabets, Strings, and Languages. The regular languages. Clouser properties of regular sets. Finite State Automata. Types of Finite State Automata.
Lecture 03: Theory of Automata:2014 Asif Nawaz Theory of Automata.
Akram Salah ISSR Basic Concepts Languages Grammar Automata (Automaton)
Theory of Languages and Automata By: Mojtaba Khezrian.
MA/CSSE 474 Theory of Computation Languages, prefixes, sets, cardinality, functions.
Languages and Strings Chapter 2. (1) Lexical analysis: Scan the program and break it up into variable names, numbers, etc. (2) Parsing: Create a tree.
Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION.
Language Theory Module 03.1 COP4020 – Programming Language Concepts Dr. Manuel E. Bermudez.
Languages.
Lecture 1 Theory of Automata
CIS Automata and Formal Languages – Pei Wang
Theory of Computation Theory of computation is mainly concerned with the study of how problems can be solved using algorithms.  Therefore, we can infer.
Natural Language Processing - Formal Language -
Languages, prefixes, sets, cardinality, functions
COP4620 – Programming Language Translators Dr. Manuel E. Bermudez
Languages, prefixes, sets, cardinality, functions
Chapter 1 Introduction to the Theory of Computation
CSC312 Automata Theory Lecture # 2 Languages.
What is it? The term "Automata" is derived from the Greek word "αὐτόματα" which means "self-acting". An automaton (Automata in plural) is an abstract self-propelled.
Presentation transcript:

CS3012 Formal Languages and Compilers Frank Guerin Room 227 Lectures Monday11:00MT3 Tuesday9:00105 St. Marys Tutorials Thursday13:00 Thursday 14:00definitely

Formal Languages Languages: English, Spanish,... PASCAL, C,... Problem: How do we define a language? i.e. what sentences are valid in a language? e.g.Large red cars go quickly. Colourless green ideas sleep furiously. Cars red large go quickly. Coches rojos grandes marchan rapidamente. Formal languages: Languages with a well-defined membership, based solely on the form of the sentences.

Example Program #include main() { printf("hello world\n"); } eof #include main ( ) { printf ( "hello world\n" ) ; } eof

Course Content Basic formal language theory Alphabets, strings, languages Finite state automata Regular expressions and languages Finite state automata and regular languages Finite state automata with output Grammar theory Languages and grammars Derivations and ambiguity Parsing

Alphabets and Strings: Definitions A symbol is a basic unit. g, 5, 1 and $ are symbols A string over an alphabet T is a finite sequence of symbols from T. Also called T-string, or simply string. aZb, 45637, , aabababba The empty string is the string with no symbols, denoted by. An alphabet is a finite set of symbols. {a, b, c, d, e,..., z, A, B,..., Z} {0,1,2,3,4,5,6,7,8,9} {0,1} {a,b}

Definitions (cont.) The length of a string, w, is the number of symbols in the sequence, denoted |w|. |4732| = 4, |abbca| = 5 Two strings, w & v are equal if they have exactly the same sequence of symbols. The concatenation of two strings, w & v, is the sequence of symbols in w followed by the sequence of symbols in v. Denoted wv. w = abb, v = bab, wv = abbbab. w = w. Note: concatenation is not commutative: wv need not equal vw. Concatenation is associative: w(vu) = (wv)u.

Definitions (cont.) A string u is a substring of w if there exist other strings x & y s.t. w = xuy. ab is a substring of babba. Note: is a substring of every string. If u is a substring of w, and x above is, then u is a prefix of w. If u w, then u is a proper prefix. ba is a prefix of babba. If u is a substring of w, and y above is, then u is a suffix of w. If u w, then u is a proper suffix. bba is a suffix of babba.

Definitions (cont.) If T is an alphabet, then T* is the set of all strings over T. T + is T* without T = {a,b}, T* = {,a, b, aa, ab, bb, ba, aaa,...} If a is a symbol, then a n is the string of n a's a 3 = aaa a* = {, a, aa, aaa,...} a + = {a, aa, aaa,...} Note: a n a m = a n+m. A language over an alphabet T is a set of strings over T. Also called T-language, or simply language. T = {a,b}, then {, ab, babba, bbbbbbb} is a T-language Note: L is a T-language iff L T*

Language Operations A+B is the set union of A and B A B is the set intersection of A and B A' is the complement of A - i.e. all strings in T* but not in A. AB is the concatenation of A and B - i.e. all strings uv where u A and v B Note: associative, but not commutative. Let A and B be languages over T. A n is the concatenation of A with itself n times. Note: A 0 = { }.

Language Operations A* = A 0 + A 1 + A This is called the Kleene Closure of A. Note: (A*)* = A* A + = A 1 + A

Orderings Let T be an alphabet with a given ordering on its symbols. Say T = {a, b, c, d,...}. Strings over T can be ordered in two ways: Dictionary Order All strings beginning a are ordered before all strings beginning b, and b before c, etc. Within groups of strings beginning with the same symbol, strings are ordered by their second symbol, and so on. is always the first string. Lexical Order Strings are ordered by their length, with the shortest first. Within groups of strings of the same length, strings are ordered in dictionary order. is always the first string.

Specifying Languages L 1 = {x n : n = 1, 2, 3,...} What elements are in L 1 ? L 2 = {x n : n = 1, 4, 9, 16,...} What elements are in L 2 ? L 3 = {x n : n = 1,4, 9, 48,...} What elements are in L 3 ? Problem: Devise a clear and precise method for defining infinite languages.

Languages and Machines Languages represent problems Machines find the solution Given a Question: How to Find the Answer? Yes/no – decision problem – can generalise to function problem Given a Problem: How to Work Out the Solution? How to solve equations Given a Task: How to Achieve it? How to get out of a maze How to drive a car through an obstacle course Languages are as useful as numbers – A language can describe any problem. A class of languages is a useful abstraction for a class of problems. Maths is all about abstraction (e.g. a number is an abstraction) If you think about problems abstractly you can see solutions you might otherwise miss You can see equivalent/related problems

Recognising Languages We will tackle the problem of defining languages by considering how we could recognise them. Problem: Is there a method of recognising infinite languages? i.e. given a language description and a string, is there an algorithm which will answer yes or no correctly? We will define an abstract machine which takes a candidate string and produces the answer yes or no. The abstract machine will be the specification of the language.

Finite State Automata A finite state automaton is an abstract model of a simple machine (or computer). The machine can be in a finite number of states. It receives symbols as input, and the result of receiving a particular input in a particular state moves the machine to a specified new state. Certain states are finishing states, and if the machine is in one of those states when the input ends, it has ended successfully (or has accepted the input). Example: A a b b b a a a,b

Halting Problem There are some problems for which no machine can find an answer function searchForOddPerfectNumber() var int n = 1 loop { var int sumOfFactors = 0 for factor from 1 to n - 1 if factor is a factor of n then sumOfFactors = sumOfFactors + factor if sumOfFactors = n then exit loop n = n + 2 } return