Lexical and Syntax Analysis

Size: px
Start display at page:

Download "Lexical and Syntax Analysis"

Transcription

1 Lexical and Syntax Analysis (of Programming Languages) Lexical Analysis

2 Lexical and Syntax Analysis (of Programming Languages) Lexical Analysis

3 What is Parsing? Parser String of characters Data structure Easy for humans to write Easy for programs to process A parser also checks that the input string is well-formed, and if not, rejects it.

4 What is Parsing? Parser String of characters Data structure Easy for humans to write Easy for programs to process A parser also checks that the input string is well-formed, and if not, rejects it.

5 PARSING = LEXICAL ANALYSIS + SYNTAX ANALYSIS

6 PARSING = LEXICAL ANALYSIS + SYNTAX ANALYSIS

7 Lexical Analysis (Also known as scanning ) Identifies the lexemes in a sentence. Lexeme: a minimal meaningful unit of a language. Converts each lexeme to a token. Throws away ignorable text such as spaces, new-lines, and comments.

8 Lexical Analysis (Also known as scanning ) Identifies the lexemes in a sentence. Lexeme: a minimal meaningful unit of a language. Converts each lexeme to a token. Throws away ignorable text such as spaces, new-lines, and comments.

9 What is a token? Every token has an identifier, used to denote the kind of lexeme that it represents, e.g. Token identifier PLUS ASSIGN VAR NUM denotes a + operator a := operator a variable a number Some tokens have a component value, conventionally written in parenthesis after the identifier, e.g. VAR(foo), NUM(12).

10 What is a token? Every token has an identifier, used to denote the kind of lexeme that it represents, e.g. Token identifier PLUS ASSIGN VAR NUM denotes a + operator a := operator a variable a number Some tokens have a component value, conventionally written in parenthesis after the identifier, e.g. VAR(foo), NUM(12).

11 Lexical Analysis Stream of characters Stream of tokens Example input: foo := 20 + bar Example output: VAR(foo), ASSIGN, NUM(20), PLUS, VAR(bar)

12 Lexical Analysis Stream of characters Stream of tokens Example input: foo := 20 + bar Example output: VAR(foo), ASSIGN, NUM(20), PLUS, VAR(bar)

13 Lexical Analysis Lexemes are specified by regular expressions. For example: number = digit digit * variable = letter (letter digit) * digit = letter = a... z Example numbers: Example variables: x foo foo2 x1y20

14 Lexical Analysis Lexemes are specified by regular expressions. For example: number = digit digit * variable = letter (letter digit) * digit = letter = a... z Example numbers: Example variables: x foo foo2 x1y20

15 REGULAR EXPRESSIONS What exactly is a regular expression?

16 REGULAR EXPRESSIONS What exactly is a regular expression?

17 Notation Alphabet is the set of all characters that can appear in an input string. If a string s matches a regular expressions r, we write s r. Language L(r) = { s s r }, i.e. the set of all strings matching regular expression r. We write s 1 s 2 to denote the concatenation of strings s 1 and s 2.

18 Notation Alphabet is the set of all characters that can appear in an input string. If a string s matches a regular expressions r, we write s r. Language L(r) = { s s r }, i.e. the set of all strings matching regular expression r. We write s 1 s 2 to denote the concatenation of strings s 1 and s 2.

19 Syntax The syntax of regular expressions is defined by the following grammar, where x ranges over symbols in. r ε r x r r r r r r r r * r ( r )

20 Syntax The syntax of regular expressions is defined by the following grammar, where x ranges over symbols in. r ε r x r r r r r r r r * r ( r )

21 Intuitive definition Regular expression Matching strings are ε The empty string ε x The singleton string x if x r 1 r 2 Any string matching r 1 or r 2. r 1 r 2 r * Any string that can be split into substrings s 1 and s 2 such that s 1 matches r 1 and s 2 matches r 2 The empty string or any string that can be split into substrings s 1...s n such that s i matches r for all i in 1...n

22 Intuitive definition Regular expression Matching strings are ε The empty string ε x The singleton string x if x r 1 r 2 Any string matching r 1 or r 2. r 1 r 2 r * Any string that can be split into substrings s 1 and s 2 such that s 1 matches r 1 and s 2 matches r 2 The empty string or any string that can be split into substrings s 1...s n such that s i matches r for all i in 1...n

23 Formal definition: Base cases L(ε ) = { ε } L(x) = { x } where x

24 Formal definition: Base cases L(ε ) = { ε } L(x) = { x } where x

25 Formal definition: Choice and Sequence L(r 1 r 2 ) = L(r 1 ) L(r 2 ) L(r 1 r 2 ) = { s 1 s 2 s 1 L(r 1 ), s 2 L(r 2 ) }

26 Formal definition: Choice and Sequence L(r 1 r 2 ) = L(r 1 ) L(r 2 ) L(r 1 r 2 ) = { s 1 s 2 s 1 L(r 1 ), s 2 L(r 2 ) }

27 Formal definition: Kleene closure L(r n ) = { ε }, if n = 0 L(r r n-1 ), if n > 0 L(r * ) = { L(r n ) n { 0 } }

28 Formal definition: Kleene closure L(r n ) = { ε }, if n = 0 L(r r n-1 ), if n > 0 L(r * ) = { L(r n ) n { 0 } }

29 Example 1 Suppose = { a, b }. r L(r) a b { a, b } (a b) (a b) { aa, ab, ba, bb } a * { ε, a, aa, aaa,... } (a b) * { ε, ab, abab,... } (a b) * { ε, a, b, ab, ba,... }

30 Example 1 Suppose = { a, b }. r L(r) a b { a, b } (a b) (a b) { aa, ab, ba, bb } a * { ε, a, aa, aaa,... } (a b) * { ε, ab, abab,... } (a b) * { ε, a, b, ab, ba,... }

31 Example 2 Example of a language that cannot be defined by a regular expression: { a n b n n N } The set of strings containing n consecutive a symbols followed by n consecutive b symbols, for all n.

32 Example 2 Example of a language that cannot be defined by a regular expression: { a n b n n N } The set of strings containing n consecutive a symbols followed by n consecutive b symbols, for all n.

33 Exercise 1 Characterise the languages defined by the following regular expressions a (a b) * a a * b a * b a * b a * ((ε a) b * ) *

34 Exercise 1 Characterise the languages defined by the following regular expressions a (a b) * a a * b a * b a * b a * ((ε a) b * ) *

35 Proof rules: Base cases The empty string ε matches ε. ε ε [Empty] If x then x matches x. x x x [Single]

36 Proof rules: Base cases The empty string ε matches ε. ε ε [Empty] If x then x matches x. x x x [Single]

37 Proof rules: Sequence If s 1 matches r 1 and s 2 matches r 2 then s 1 s 2 matches r 1 r 2. s 1 r 1 s 2 r 2 [Seq] s 1 s 2 r 1 r 2

38 Proof rules: Sequence If s 1 matches r 1 and s 2 matches r 2 then s 1 s 2 matches r 1 r 2. s 1 r 1 s 2 r 2 [Seq] s 1 s 2 r 1 r 2

39 Proof rules: Choice If s matches r 1 then s matches r 1 r 2 s r 1 [Or 1 ] s r 1 r 2 If s matches r 2 then s matches r 1 r 2 s r 2 [Or 2 ] s r 1 r 2

40 Proof rules: Choice If s matches r 1 then s matches r 1 r 2 s r 1 [Or 1 ] s r 1 r 2 If s matches r 2 then s matches r 1 r 2 s r 2 [Or 2 ] s r 1 r 2

41 Proof rules: Kleene closure If s matches ε then s matches r *. s ε s r * [Kleene 1 ] If s matches r r * then s matches r *. s r r * [Kleene s r * 2 ]

42 Proof rules: Kleene closure If s matches ε then s matches r *. s ε s r * [Kleene 1 ] If s matches r r * then s matches r *. s r r * [Kleene s r * 2 ]

43 Exercise 2 Proove that the string cab matches the regular expression ((a b) c) *

44 Exercise 2 Proove that the string cab matches the regular expression ((a b) c) *

45 Exercise 2 cab ((a b) c) * { Kleene 2 } cab ((a b) c) ((a b) c) * { Seq } c (a b) c, ab ((a b) c) * { Or 2 } c c, ab ((a b) c) * { Single } ab ((a b) c) * Continued...

46 Exercise 2 cab ((a b) c) * { Kleene 2 } cab ((a b) c) ((a b) c) * { Seq } c (a b) c, ab ((a b) c) * { Or 2 } c c, ab ((a b) c) * { Single } ab ((a b) c) * Continued...

47 Exercise 2 ab ((a b) c) * { Kleene 2 } ab ((a b) c) ((a b) c) * { Seq } ab (a b) c, ε ((a b) c) * { Or 1, Kleene 1 } ab (a b) { Seq } a a, b b { Single, Single } true

48 Exercise 2 ab ((a b) c) * { Kleene 2 } ab ((a b) c) ((a b) c) * { Seq } ab (a b) c, ε ((a b) c) * { Or 1, Kleene 1 } ab (a b) { Seq } a a, b b { Single, Single } true

49 Sound and Complete The proof rules are: Sound: if we can prove s r using the rules then s L(r). Complete: if s L(r) then we can prove s r using the rules.

50 Sound and Complete The proof rules are: Sound: if we can prove s r using the rules then s L(r). Complete: if s L(r) then we can prove s r using the rules.

51 Prolog If we define our proof rules in Prolog then we get a regular expression implementation. [] []. [X] X. S R1!R2 :- S R1. S R1!R2 :- S R2. S R1.R2 :- append(s1, S2, S), S1 R1, S2 R2. [] R*. S R* :- append(s1, S2, S), S1=[X Xs], S1 R, S2 R*. NOTES: Operator! used to represent vertical bar. Read :- as if. Strings represented by lists of symbols. Termination ensured by requiring S1 to be non-empty in final clause.

52 Prolog If we define our proof rules in Prolog then we get a regular expression implementation. [] []. [X] X. S R1!R2 :- S R1. S R1!R2 :- S R2. S R1.R2 :- append(s1, S2, S), S1 R1, S2 R2. [] R*. S R* :- append(s1, S2, S), S1=[X Xs], S1 R, S2 R*. NOTES: Operator! used to represent vertical bar. Read :- as if. Strings represented by lists of symbols. Termination ensured by requiring S1 to be non-empty in final clause.

53 Prolog Sadly the Prolog implementation is not very efficient: when applying the proof rules by hand we used human intuition to know where to split the string; Prolog does not have this intuition; instead, Prolog guesses, trying all possible ways to split a string, and backtracks on failure.

54 Prolog Sadly the Prolog implementation is not very efficient: when applying the proof rules by hand we used human intuition to know where to split the string; Prolog does not have this intuition; instead, Prolog guesses, trying all possible ways to split a string, and backtracks on failure.

55 Common extensions Regular expression is the same as r + r r * r? ε r [c 1 c 2 c 3 -c n ] c 1 c 2 c 3... c n [^c 1 c 2 ] { x x, x {c 1, c 2 } }

56 Common extensions Regular expression is the same as r + r r * r? ε r [c 1 c 2 c 3 -c n ] c 1 c 2 c 3... c n [^c 1 c 2 ] { x x, x {c 1, c 2 } }

57 Escaping What if contains regular expression symbols such as * ( + [? We can escape such symbols by prefixing with a backslash: \ \ * \ \( \[ \? And if we want \ then write \\. Example: \[ * \] * means zero or left brackets followed by zero or more right brackets.

58 Escaping What if contains regular expression symbols such as * ( + [? We can escape such symbols by prefixing with a backslash: \ \ * \ \( \[ \? And if we want \ then write \\. Example: \[ * \] * means zero or left brackets followed by zero or more right brackets.

59 Regular definitions For convenience, we may wish to name a regular expression so that we can refer to it many times: name = r We write name but sometimes the notation {name} is used (e.g. in Flex). Example: number = digit digit * digit =

60 Regular definitions For convenience, we may wish to name a regular expression so that we can refer to it many times: name = r We write name but sometimes the notation {name} is used (e.g. in Flex). Example: number = digit digit * digit =

61 Implementing regular expressions How do we convert a regular expression r into an efficient program that prints YES when applied to any string in L(r) and NO in all other cases? Two options: By hand (LSA Lab 1) Automatically (Chapters 3 & 4 of lecture notes, and LSA Lab 2)

62 Implementing regular expressions How do we convert a regular expression r into an efficient program that prints YES when applied to any string in L(r) and NO in all other cases? Two options: By hand (LSA Lab 1) Automatically (Chapters 3 & 4 of lecture notes, and LSA Lab 2)

63 Outline Automatic conversion of regular expressions to efficient stringmatching functions: Step 1: RE NFA Step 2: NFA DFA Step 3: DFA C Function Acronym RE NFA DFA Meaning Regular Expression Non-deterministic Finite Automaton Deterministic Finite Automaton

64 Outline Automatic conversion of regular expressions to efficient stringmatching functions: Step 1: RE NFA Step 2: NFA DFA Step 3: DFA C Function Acronym RE NFA DFA Meaning Regular Expression Non-deterministic Finite Automaton Deterministic Finite Automaton

65 STEP 1: RE NFA Thompson s construction

66 STEP 1: RE NFA Thompson s construction

67 What is an NFA? A directed graph with nodes denoting states s A state s s The start state s s An accepting state s s The start state s that is also an accepting state and edges labelled with a symbol x {ε} denoting transitions x s 1 s 2

68 What is an NFA? A directed graph with nodes denoting states s A state s s The start state s s An accepting state s s The start state s that is also an accepting state and edges labelled with a symbol x {ε} denoting transitions x s 1 s 2

69 Meaning of an NFA A string x 1 x 2...x n is accepted by an NFA if there is a path labelled x 1,x 2,...,x n (including any number of ε transitions) from the start state to an accepting state.

70 Meaning of an NFA A string x 1 x 2...x n is accepted by an NFA if there is a path labelled x 1,x 2,...,x n (including any number of ε transitions) from the start state to an accepting state.

71 Example of an NFA The following NFA accepts exactly the strings that match the regular expression a a * b b *. ε 1 a 2 0 a ε 3 b 4 b

72 Example of an NFA The following NFA accepts exactly the strings that match the regular expression a a * b b *. ε 1 a 2 0 a ε 3 b 4 b

73 Thompson s construction: Notation Let N(r) be the NFA accepting exactly the set of strings in L(r). We abstractly represent an NFA N(r) with start state s 0 and final state s a by the diagram: s 0 N(r) s a

74 Thompson s construction: Notation Let N(r) be the NFA accepting exactly the set of strings in L(r). We abstractly represent an NFA N(r) with start state s 0 and final state s a by the diagram: s 0 N(r) s a

75 Thompson s construction: Base cases = s 0 N(ε) s a s 0 ε s a = s 0 N(x) s a s 0 x s a where x

76 Thompson s construction: Base cases = s 0 N(ε) s a s 0 ε s a = s 0 N(x) s a s 0 x s a where x

77 Thompson s construction: Choice s 0 N(r t) s a = s 0 ε ε N(r) N(t) ε ε s a

78 Thompson s construction: Choice s 0 N(r t) s a = s 0 ε ε N(r) N(t) ε ε s a

79 Thompson s construction: Sequence s 0 N(r t) s a = s 0 N(r) N(t) s a

80 Thompson s construction: Sequence s 0 N(r t) s a = s 0 N(r) N(t) s a

81 Thompson s construction: Kleene closure s 0 N(r* ) s a = ε s 0 ε N(r) ε s a ε

82 Thompson s construction: Kleene closure s 0 N(r* ) s a = ε s 0 ε N(r) ε s a ε

83 Exercise 3 Apply Thompson s construction to the following regular expression. ((a b) c) *

84 Exercise 3 Apply Thompson s construction to the following regular expression. ((a b) c) *

85 Problem with NFAs It is not straightforward to turn an NFA into a deterministic program because: There may be many possible next-states for a given input. Which one do we choose? Try them all? Idea: convert an NFA into a DFA: a DFA can be easily converted into an efficient executable program.

86 Problem with NFAs It is not straightforward to turn an NFA into a deterministic program because: There may be many possible next-states for a given input. Which one do we choose? Try them all? Idea: convert an NFA into a DFA: a DFA can be easily converted into an efficient executable program.

87 STEP 2: NFA DFA The subset construction.

88 STEP 2: NFA DFA The subset construction.

89 What is a DFA? A deterministic finite automaton (DFA) is an NFA in which there are no ε transitions, and for each state s and input symbol a there is at most one transition out of s labelled a.

90 What is a DFA? A deterministic finite automaton (DFA) is an NFA in which there are no ε transitions, and for each state s and input symbol a there is at most one transition out of s labelled a.

91 Example of a DFA The following DFA accepts exactly the strings that match the regular expression a a * b b *. 0 a 1 a b 2 b

92 Example of a DFA The following DFA accepts exactly the strings that match the regular expression a a * b b *. 0 a 1 a b 2 b

93 NFA DFA: key observation After consuming an input string, an NFA can be in be in one of a set of states. Example 3: b 0 1 a a a Input States aa 0, 1, 2 aba aab 2 b aaba 3 ε

94 NFA DFA: key observation After consuming an input string, an NFA can be in be in one of a set of states. Example 3: b 0 1 a a a Input States aa 0, 1, 2 aba aab 2 b aaba 3 ε

95 NFA DFA: key idea Idea: construct a DFA in which each state corresponds to a set of NFA states. After consuming a 1 a n the DFA is in a state which corresponds to the set of states that the NFA can reach on input a 1 a n.

96 NFA DFA: key idea Idea: construct a DFA in which each state corresponds to a set of NFA states. After consuming a 1 a n the DFA is in a state which corresponds to the set of states that the NFA can reach on input a 1 a n.

97 Example 3, revisited Create a DFA state corresponding to each set of NFA states. Input NFA States DFA State aa 0, 1, 2 A aba 0,1 B aab 0,3 C aaba 0,1 B ε 0 D Question: which states would be initial and final DFA states?

98 Example 3, revisited Create a DFA state corresponding to each set of NFA states. Input NFA States DFA State aa 0, 1, 2 A aba 0,1 B aab 0,3 C aaba 0,1 B ε 0 D Question: which states would be initial and final DFA states?

99 Notation Operation ε-closure(s) Description Set of NFA states reachable from NFA state s on zero or more ε-transitions. ε-closure(t) move(t, a) ε-closure(s) s T Set of NFA states to which there is a transition on symbol a from some state s in T.

100 Notation Operation ε-closure(s) Description Set of NFA states reachable from NFA state s on zero or more ε-transitions. ε-closure(t) move(t, a) ε-closure(s) s T Set of NFA states to which there is a transition on symbol a from some state s in T.

101 Exercise 4 Consider the following NFA. a a c ε ε 3 ε a Compute: ε-closure(0) ε-closure({1, 2}) move({0,3}, a) ε-closure(move({0,3}, a))

102 Exercise 4 Consider the following NFA. a a c ε ε 3 ε a Compute: ε-closure(0) ε-closure({1, 2}) move({0,3}, a) ε-closure(move({0,3}, a))

103 Subset construction: input and output Input: an NFA N. Output: a DFA D accepting the same language as N. Specifically, the set of states of D, termed D states, and its transition function D tran that maps any state-symbol pair to a next state.

104 Subset construction: input and output Input: an NFA N. Output: a DFA D accepting the same language as N. Specifically, the set of states of D, termed D states, and its transition function D tran that maps any state-symbol pair to a next state.

105 Subset construction: input and output Each state in D is denoted by a subset of N s states. To ensure termination, every state is either marked or unmarked. Initially, D states contains a single unmarked start state ε-closure(s 0 ) where s 0 is the start state of N. The accepting states of D are the states that contain at least one accepting state of N.

106 Subset construction: input and output Each state in D is denoted by a subset of N s states. To ensure termination, every state is either marked or unmarked. Initially, D states contains a single unmarked start state ε-closure(s 0 ) where s 0 is the start state of N. The accepting states of D are the states that contain at least one accepting state of N.

107 Subset construction: algorithm while (there is an unmarked state T in D states ) { mark T; for (each input symbol a) { U = ε-closure(move(t, a)); D tran [T, a] = U if (U is not in D states ) add U as unmarked state to D states ; } }

108 Subset construction: algorithm while (there is an unmarked state T in D states ) { mark T; for (each input symbol a) { U = ε-closure(move(t, a)); D tran [T, a] = U if (U is not in D states ) add U as unmarked state to D states ; } }

109 Exercise 5 Convert the following NFA into a DFA by applying the subset construction algorithm. ε 1 a b ε 7 ε ε 8 ε 10 ε 5 6 c ε ε

110 Exercise 5 Convert the following NFA into a DFA by applying the subset construction algorithm. ε 1 a b ε 7 ε ε 8 ε 10 ε 5 6 c ε ε

111 Exercise 6 It is not obvious how to simulate an NFA in linear time with respect to the length of the input string. But it may be converted to a DFA that can be simulated easily in linear time. What s the catch? Can you think of any problems with the DFA produced by subset construction?

112 Exercise 6 It is not obvious how to simulate an NFA in linear time with respect to the length of the input string. But it may be converted to a DFA that can be simulated easily in linear time. What s the catch? Can you think of any problems with the DFA produced by subset construction?

113 Caveats Number of DFA states could be exponential in number of NFA states! DFA produced is not minimal in number of states. (Can apply a minimisation algorithm.) Often no problem in practice.

114 Caveats Number of DFA states could be exponential in number of NFA states! DFA produced is not minimal in number of states. (Can apply a minimisation algorithm.) Often no problem in practice.

115 Homework Exercise Convert the following NFA into a DFA by applying the subset construction algorithm. b a a b a

116 Homework Exercise Convert the following NFA into a DFA by applying the subset construction algorithm. b a a b a

117 STEP 3: DFA C CODE

118 STEP 3: DFA C CODE

119 Exercise 7 Implement the DFA a B b a A a D c C c c as a C function int match(char *next) { } returning 1 if the string pointed to by next is accepted by the DFA and 0 otherwise.

120 Exercise 7 Implement the DFA a B b a A a D c C c c as a C function int match(char *next) { } returning 1 if the string pointed to by next is accepted by the DFA and 0 otherwise.

121 int match(char* next) { goto A; /* start state */ A: if (*next == '\0') return 1; if (*next == 'a') { next++; goto B; } if (*next == 'c') { next++; goto C; } return 0; B: if (*next == '\0') return 0; if (*next == 'b') { next++; goto D; } return 0; C: if (*next == '\0') return 1; if (*next == 'a') { next++; goto B; } if (*next == 'c') { next++; goto D; } return 0; } D: if (*next == '\0') return 1; if (*next == 'a') { next++; goto B; } if (*next == 'c') { next++; goto D; } return 0;

122 int match(char* next) { goto A; /* start state */ A: if (*next == '\0') return 1; if (*next == 'a') { next++; goto B; } if (*next == 'c') { next++; goto C; } return 0; B: if (*next == '\0') return 0; if (*next == 'b') { next++; goto D; } return 0; C: if (*next == '\0') return 1; if (*next == 'a') { next++; goto B; } if (*next == 'c') { next++; goto D; } return 0; } D: if (*next == '\0') return 1; if (*next == 'a') { next++; goto B; } if (*next == 'c') { next++; goto D; } return 0;

123 SUMMARY

124 SUMMARY

125 Summary In lexical analysis, the lexemes of the language are identified and converted into tokens. Lexemes are typically specified by regular expressions. Matching of regular expressions formalised by proof rules. Defining proof rules in Prolog gives a simple but inefficient implementation.

126 Summary In lexical analysis, the lexemes of the language are identified and converted into tokens. Lexemes are typically specified by regular expressions. Matching of regular expressions formalised by proof rules. Defining proof rules in Prolog gives a simple but inefficient implementation.

127 Summary Automatically converting regular expressions into efficient C code involves three main steps: 1. RE NFA (Thompson s Construction) 2. NFA DFA (Subset Construction) 3. DFA C Function

128 Summary Automatically converting regular expressions into efficient C code involves three main steps: 1. RE NFA (Thompson s Construction) 2. NFA DFA (Subset Construction) 3. DFA C Function

129 Theory & Practice In the next lecture, we will learn how to use a tool called Flex that puts the regular expression theory into practice.

Scanner. tokens scanner parser IR. source code. errors

Scanner. tokens scanner parser IR. source code. errors Scanner source code tokens scanner parser IR errors maps characters into tokens the basic unit of syntax x = x + y; becomes = + ; character string value for a token is a lexeme

More information

Formal Languages and Automata Theory - Regular Expressions and Finite Automata -

Formal Languages and Automata Theory - Regular Expressions and Finite Automata - Formal Languages and Automata Theory - Regular Expressions and Finite Automata - Samarjit Chakraborty Computer Engineering and Networks Laboratory Swiss Federal Institute of Technology (ETH) Zürich March

More information

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010. Class 4 Nancy Lynch

6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010. Class 4 Nancy Lynch 6.045: Automata, Computability, and Complexity Or, Great Ideas in Theoretical Computer Science Spring, 2010 Class 4 Nancy Lynch Today Two more models of computation: Nondeterministic Finite Automata (NFAs)

More information

C H A P T E R Regular Expressions regular expression

C H A P T E R Regular Expressions regular expression 7 CHAPTER Regular Expressions Most programmers and other power-users of computer systems have used tools that match text patterns. You may have used a Web search engine with a pattern like travel cancun

More information

Compiler Construction

Compiler Construction Compiler Construction Regular expressions Scanning Görel Hedin Reviderad 2013 01 23.a 2013 Compiler Construction 2013 F02-1 Compiler overview source code lexical analysis tokens intermediate code generation

More information

Regular Languages and Finite State Machines

Regular Languages and Finite State Machines Regular Languages and Finite State Machines Plan for the Day: Mathematical preliminaries - some review One application formal definition of finite automata Examples 1 Sets A set is an unordered collection

More information

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions

CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions CS103B Handout 17 Winter 2007 February 26, 2007 Languages and Regular Expressions Theory of Formal Languages In the English language, we distinguish between three different identities: letter, word, sentence.

More information

03 - Lexical Analysis

03 - Lexical Analysis 03 - Lexical Analysis First, let s see a simplified overview of the compilation process: source code file (sequence of char) Step 2: parsing (syntax analysis) arse Tree Step 1: scanning (lexical analysis)

More information

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, 2014. School of Informatics University of Edinburgh als@inf.ed.ac.

Pushdown automata. Informatics 2A: Lecture 9. Alex Simpson. 3 October, 2014. School of Informatics University of Edinburgh als@inf.ed.ac. Pushdown automata Informatics 2A: Lecture 9 Alex Simpson School of Informatics University of Edinburgh als@inf.ed.ac.uk 3 October, 2014 1 / 17 Recap of lecture 8 Context-free languages are defined by context-free

More information

Reading 13 : Finite State Automata and Regular Expressions

Reading 13 : Finite State Automata and Regular Expressions CS/Math 24: Introduction to Discrete Mathematics Fall 25 Reading 3 : Finite State Automata and Regular Expressions Instructors: Beck Hasti, Gautam Prakriya In this reading we study a mathematical model

More information

Finite Automata. Reading: Chapter 2

Finite Automata. Reading: Chapter 2 Finite Automata Reading: Chapter 2 1 Finite Automaton (FA) Informally, a state diagram that comprehensively captures all possible states and transitions that a machine can take while responding to a stream

More information

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016 Master s Degree Course in Computer Engineering Formal Languages FORMAL LANGUAGES AND COMPILERS Lexical analysis Floriano Scioscia 1 Introductive terminological distinction Lexical string or lexeme = meaningful

More information

Regular Expressions and Automata using Haskell

Regular Expressions and Automata using Haskell Regular Expressions and Automata using Haskell Simon Thompson Computing Laboratory University of Kent at Canterbury January 2000 Contents 1 Introduction 2 2 Regular Expressions 2 3 Matching regular expressions

More information

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013

CMPSCI 250: Introduction to Computation. Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013 CMPSCI 250: Introduction to Computation Lecture #19: Regular Expressions and Their Languages David Mix Barrington 11 April 2013 Regular Expressions and Their Languages Alphabets, Strings and Languages

More information

Fundamentele Informatica II

Fundamentele Informatica II Fundamentele Informatica II Answer to selected exercises 1 John C Martin: Introduction to Languages and the Theory of Computation M.M. Bonsangue (and J. Kleijn) Fall 2011 Let L be a language. It is clear

More information

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi

Automata Theory. Şubat 2006 Tuğrul Yılmaz Ankara Üniversitesi Automata Theory Automata theory is the study of abstract computing devices. A. M. Turing studied an abstract machine that had all the capabilities of today s computers. Turing s goal was to describe the

More information

Automata on Infinite Words and Trees

Automata on Infinite Words and Trees Automata on Infinite Words and Trees Course notes for the course Automata on Infinite Words and Trees given by Dr. Meghyn Bienvenu at Universität Bremen in the 2009-2010 winter semester Last modified:

More information

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing The scanner (or lexical analyzer) of a compiler processes the source program, recognizing

More information

Automata and Formal Languages

Automata and Formal Languages Automata and Formal Languages Winter 2009-2010 Yacov Hel-Or 1 What this course is all about This course is about mathematical models of computation We ll study different machine models (finite automata,

More information

Automata and Computability. Solutions to Exercises

Automata and Computability. Solutions to Exercises Automata and Computability Solutions to Exercises Fall 25 Alexis Maciel Department of Computer Science Clarkson University Copyright c 25 Alexis Maciel ii Contents Preface vii Introduction 2 Finite Automata

More information

Finite Automata. Reading: Chapter 2

Finite Automata. Reading: Chapter 2 Finite Automata Reading: Chapter 2 1 Finite Automata Informally, a state machine that comprehensively captures all possible states and transitions that a machine can take while responding to a stream (or

More information

Lecture 18 Regular Expressions

Lecture 18 Regular Expressions Lecture 18 Regular Expressions Many of today s web applications require matching patterns in a text document to look for specific information. A good example is parsing a html file to extract tags

More information

Compiler I: Syntax Analysis Human Thought

Compiler I: Syntax Analysis Human Thought Course map Compiler I: Syntax Analysis Human Thought Abstract design Chapters 9, 12 H.L. Language & Operating Sys. Compiler Chapters 10-11 Virtual Machine Software hierarchy Translator Chapters 7-8 Assembly

More information

2110711 THEORY of COMPUTATION

2110711 THEORY of COMPUTATION 2110711 THEORY of COMPUTATION ATHASIT SURARERKS ELITE Athasit Surarerks ELITE Engineering Laboratory in Theoretical Enumerable System Computer Engineering, Faculty of Engineering Chulalongkorn University

More information

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions CSC45 AUTOMATA 2. Finite Automata: Examples and Definitions Finite Automata: Examples and Definitions A finite automaton is a simple type of computer. Itsoutputislimitedto yes to or no. It has very primitive

More information

NFAs with Tagged Transitions, their Conversion to Deterministic Automata and Application to Regular Expressions

NFAs with Tagged Transitions, their Conversion to Deterministic Automata and Application to Regular Expressions NFAs with Tagged Transitions, their Conversion to Deterministic Automata and Application to Regular Expressions Ville Laurikari Helsinki University of Technology Laboratory of Computer Science PL 9700,

More information

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer How to make the computer understand? Fall 2005 Lecture 15: Putting it all together From parsing to code generation Write a program using a programming language Microprocessors talk in assembly language

More information

Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile

Pushdown Automata. place the input head on the leftmost input symbol. while symbol read = b and pile contains discs advance head remove disc from pile Pushdown Automata In the last section we found that restricting the computational power of computing devices produced solvable decision problems for the class of sets accepted by finite automata. But along

More information

The Halting Problem is Undecidable

The Halting Problem is Undecidable 185 Corollary G = { M, w w L(M) } is not Turing-recognizable. Proof. = ERR, where ERR is the easy to decide language: ERR = { x { 0, 1 }* x does not have a prefix that is a valid code for a Turing machine

More information

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005 University of Toronto Department of Electrical and Computer Engineering Midterm Examination CSC467 Compilers and Interpreters Fall Semester, 2005 Time and date: TBA Location: TBA Print your name and ID

More information

Finite Automata and Regular Languages

Finite Automata and Regular Languages CHAPTER 3 Finite Automata and Regular Languages 3. Introduction 3.. States and Automata A finite-state machine or finite automaton (the noun comes from the Greek; the singular is automaton, the Greek-derived

More information

6.080/6.089 GITCS Feb 12, 2008. Lecture 3

6.080/6.089 GITCS Feb 12, 2008. Lecture 3 6.8/6.89 GITCS Feb 2, 28 Lecturer: Scott Aaronson Lecture 3 Scribe: Adam Rogal Administrivia. Scribe notes The purpose of scribe notes is to transcribe our lectures. Although I have formal notes of my

More information

Programming Languages CIS 443

Programming Languages CIS 443 Course Objectives Programming Languages CIS 443 0.1 Lexical analysis Syntax Semantics Functional programming Variable lifetime and scoping Parameter passing Object-oriented programming Continuations Exception

More information

How To Compare A Markov Algorithm To A Turing Machine

How To Compare A Markov Algorithm To A Turing Machine Markov Algorithm CHEN Yuanmi December 18, 2007 1 Abstract Markov Algorithm can be understood as a priority string rewriting system. In this short paper we give the definition of Markov algorithm and also

More information

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems.

(IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems. 3130CIT: Theory of Computation Turing machines and undecidability (IALC, Chapters 8 and 9) Introduction to Turing s life, Turing machines, universal machines, unsolvable problems. An undecidable problem

More information

CAs and Turing Machines. The Basis for Universal Computation

CAs and Turing Machines. The Basis for Universal Computation CAs and Turing Machines The Basis for Universal Computation What We Mean By Universal When we claim universal computation we mean that the CA is capable of calculating anything that could possibly be calculated*.

More information

Regular Languages and Finite Automata

Regular Languages and Finite Automata Regular Languages and Finite Automata A C Norman, Lent Term 1996 Part IA 1 Introduction This course is short, but it is present in Part 1A because of the way it introduces links between many different

More information

CS5236 Advanced Automata Theory

CS5236 Advanced Automata Theory CS5236 Advanced Automata Theory Frank Stephan Semester I, Academic Year 2012-2013 Advanced Automata Theory is a lecture which will first review the basics of formal languages and automata theory and then

More information

Informatique Fondamentale IMA S8

Informatique Fondamentale IMA S8 Informatique Fondamentale IMA S8 Cours 1 - Intro + schedule + finite state machines Laure Gonnord http://laure.gonnord.org/pro/teaching/ Laure.Gonnord@polytech-lille.fr Université Lille 1 - Polytech Lille

More information

Introduction to Finite Automata

Introduction to Finite Automata Introduction to Finite Automata Our First Machine Model Captain Pedro Ortiz Department of Computer Science United States Naval Academy SI-340 Theory of Computing Fall 2012 Captain Pedro Ortiz (US Naval

More information

Lecture 2: Regular Languages [Fa 14]

Lecture 2: Regular Languages [Fa 14] Caveat lector: This is the first edition of this lecture note. Please send bug reports and suggestions to jeffe@illinois.edu. But the Lord came down to see the city and the tower the people were building.

More information

If-Then-Else Problem (a motivating example for LR grammars)

If-Then-Else Problem (a motivating example for LR grammars) If-Then-Else Problem (a motivating example for LR grammars) If x then y else z If a then if b then c else d this is analogous to a bracket notation when left brackets >= right brackets: [ [ ] ([ i ] j,

More information

Introduction to Automata Theory. Reading: Chapter 1

Introduction to Automata Theory. Reading: Chapter 1 Introduction to Automata Theory Reading: Chapter 1 1 What is Automata Theory? Study of abstract computing devices, or machines Automaton = an abstract computing device Note: A device need not even be a

More information

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar Lexical Analysis and Scanning Honors Compilers Feb 5 th 2001 Robert Dewar The Input Read string input Might be sequence of characters (Unix) Might be sequence of lines (VMS) Character set ASCII ISO Latin-1

More information

CS154. Turing Machines. Turing Machine. Turing Machines versus DFAs FINITE STATE CONTROL AI N P U T INFINITE TAPE. read write move.

CS154. Turing Machines. Turing Machine. Turing Machines versus DFAs FINITE STATE CONTROL AI N P U T INFINITE TAPE. read write move. CS54 Turing Machines Turing Machine q 0 AI N P U T IN TAPE read write move read write move Language = {0} q This Turing machine recognizes the language {0} Turing Machines versus DFAs TM can both write

More information

5HFDOO &RPSLOHU 6WUXFWXUH

5HFDOO &RPSLOHU 6WUXFWXUH 6FDQQLQJ 2XWOLQH 2. Scanning The basics Ad-hoc scanning FSM based techniques A Lexical Analysis tool - Lex (a scanner generator) 5HFDOO &RPSLOHU 6WUXFWXUH 6RXUFH &RGH /H[LFDO $QDO\VLV6FDQQLQJ 6\QWD[ $QDO\VLV3DUVLQJ

More information

Compilers Lexical Analysis

Compilers Lexical Analysis Compilers Lexical Analysis SITE : http://www.info.univ-tours.fr/ mirian/ TLC - Mírian Halfeld-Ferrari p. 1/3 The Role of the Lexical Analyzer The first phase of a compiler. Lexical analysis : process of

More information

ML-Flex Implementation Notes

ML-Flex Implementation Notes ML-Flex Implementation Notes Aaron Turon adrassi@uchicago.edu February 17, 2006 Contents 1 Organization 2 2 Theory 3 2.1 Regular expressions................................ 3 2.2 Derivatives.....................................

More information

CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing

CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing CS143 Handout 08 Summer 2008 July 02, 2007 Bottom-Up Parsing Handout written by Maggie Johnson and revised by Julie Zelenski. Bottom-up parsing As the name suggests, bottom-up parsing works in the opposite

More information

2) Write in detail the issues in the design of code generator.

2) Write in detail the issues in the design of code generator. COMPUTER SCIENCE AND ENGINEERING VI SEM CSE Principles of Compiler Design Unit-IV Question and answers UNIT IV CODE GENERATION 9 Issues in the design of code generator The target machine Runtime Storage

More information

Turing Machines, Part I

Turing Machines, Part I Turing Machines, Part I Languages The $64,000 Question What is a language? What is a class of languages? Computer Science Theory 2 1 Now our picture looks like Context Free Languages Deterministic Context

More information

FINITE STATE AND TURING MACHINES

FINITE STATE AND TURING MACHINES FINITE STATE AND TURING MACHINES FSM With Output Without Output (also called Finite State Automata) Mealy Machine Moore Machine FINITE STATE MACHINES... 2 INTRODUCTION TO FSM S... 2 STATE TRANSITION DIAGRAMS

More information

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy

Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy Regular Expressions with Nested Levels of Back Referencing Form a Hierarchy Kim S. Larsen Odense University Abstract For many years, regular expressions with back referencing have been used in a variety

More information

Semantic Analysis: Types and Type Checking

Semantic Analysis: Types and Type Checking Semantic Analysis Semantic Analysis: Types and Type Checking CS 471 October 10, 2007 Source code Lexical Analysis tokens Syntactic Analysis AST Semantic Analysis AST Intermediate Code Gen lexical errors

More information

Genetic programming with regular expressions

Genetic programming with regular expressions Genetic programming with regular expressions Børge Svingen Chief Technology Officer, Open AdExchange bsvingen@openadex.com 2009-03-23 Pattern discovery Pattern discovery: Recognizing patterns that characterize

More information

3515ICT Theory of Computation Turing Machines

3515ICT Theory of Computation Turing Machines Griffith University 3515ICT Theory of Computation Turing Machines (Based loosely on slides by Harald Søndergaard of The University of Melbourne) 9-0 Overview Turing machines: a general model of computation

More information

MACM 101 Discrete Mathematics I

MACM 101 Discrete Mathematics I MACM 101 Discrete Mathematics I Exercises on Combinatorics, Probability, Languages and Integers. Due: Tuesday, November 2th (at the beginning of the class) Reminder: the work you submit must be your own.

More information

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification)

1. Nondeterministically guess a solution (called a certificate) 2. Check whether the solution solves the problem (called verification) Some N P problems Computer scientists have studied many N P problems, that is, problems that can be solved nondeterministically in polynomial time. Traditionally complexity question are studied as languages:

More information

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006 Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006 Final Examination January 24 th, 2006 NAME: Please read all instructions carefully before start answering. The exam will be

More information

CSE 135: Introduction to Theory of Computation Decidability and Recognizability

CSE 135: Introduction to Theory of Computation Decidability and Recognizability CSE 135: Introduction to Theory of Computation Decidability and Recognizability Sungjin Im University of California, Merced 04-28, 30-2014 High-Level Descriptions of Computation Instead of giving a Turing

More information

Composability of Infinite-State Activity Automata*

Composability of Infinite-State Activity Automata* Composability of Infinite-State Activity Automata* Zhe Dang 1, Oscar H. Ibarra 2, Jianwen Su 2 1 Washington State University, Pullman 2 University of California, Santa Barbara Presented by Prof. Hsu-Chun

More information

Flex/Bison Tutorial. Aaron Myles Landwehr aron+ta@udel.edu CAPSL 2/17/2012

Flex/Bison Tutorial. Aaron Myles Landwehr aron+ta@udel.edu CAPSL 2/17/2012 Flex/Bison Tutorial Aaron Myles Landwehr aron+ta@udel.edu 1 GENERAL COMPILER OVERVIEW 2 Compiler Overview Frontend Middle-end Backend Lexer / Scanner Parser Semantic Analyzer Optimizers Code Generator

More information

Learning Analysis by Reduction from Positive Data

Learning Analysis by Reduction from Positive Data Learning Analysis by Reduction from Positive Data František Mráz 1, Friedrich Otto 1, and Martin Plátek 2 1 Fachbereich Mathematik/Informatik, Universität Kassel 34109 Kassel, Germany {mraz,otto}@theory.informatik.uni-kassel.de

More information

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology

Honors Class (Foundations of) Informatics. Tom Verhoeff. Department of Mathematics & Computer Science Software Engineering & Technology Honors Class (Foundations of) Informatics Tom Verhoeff Department of Mathematics & Computer Science Software Engineering & Technology www.win.tue.nl/~wstomv/edu/hci c 2011, T. Verhoeff @ TUE.NL 1/20 Information

More information

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION Tao Chen 1, Tarek Sobh 2 Abstract -- In this paper, a software application that features the visualization of commonly used

More information

Regular Languages and Finite Automata

Regular Languages and Finite Automata Regular Languages and Finite Automata 1 Introduction Hing Leung Department of Computer Science New Mexico State University Sep 16, 2010 In 1943, McCulloch and Pitts [4] published a pioneering work on a

More information

Context free grammars and predictive parsing

Context free grammars and predictive parsing Context free grammars and predictive parsing Programming Language Concepts and Implementation Fall 2012, Lecture 6 Context free grammars Next week: LR parsing Describing programming language syntax Ambiguities

More information

The Optimum One-Pass Strategy for Juliet

The Optimum One-Pass Strategy for Juliet Master s Thesis One-Pass Strategies for Context-Free Games Christian Cöster August 2015 Examiners: Prof. Dr. Thomas Schwentick Prof. Dr. Christoph Buchheim Technische Universität Dortmund Fakultät für

More information

Formal Grammars and Languages

Formal Grammars and Languages Formal Grammars and Languages Tao Jiang Department of Computer Science McMaster University Hamilton, Ontario L8S 4K1, Canada Bala Ravikumar Department of Computer Science University of Rhode Island Kingston,

More information

Bottom-Up Parsing. An Introductory Example

Bottom-Up Parsing. An Introductory Example Bottom-Up Parsing Bottom-up parsing is more general than top-down parsing Just as efficient Builds on ideas in top-down parsing Bottom-up is the preferred method in practice Reading: Section 4.5 An Introductory

More information

Lempel-Ziv Coding Adaptive Dictionary Compression Algorithm

Lempel-Ziv Coding Adaptive Dictionary Compression Algorithm Lempel-Ziv Coding Adaptive Dictionary Compression Algorithm 1. LZ77:Sliding Window Lempel-Ziv Algorithm [gzip, pkzip] Encode a string by finding the longest match anywhere within a window of past symbols

More information

Formal Deænition of Finite Automaton. 1. Finite set of states, typically Q. 2. Alphabet of input symbols, typically æ.

Formal Deænition of Finite Automaton. 1. Finite set of states, typically Q. 2. Alphabet of input symbols, typically æ. Formal Denition of Finite Automaton 1. Finite set of states, typically Q. 2. Alphabet of input symbols, typically. 3. One state is the startèinitial state, typically q 0. 4. Zero or more nalèaccepting

More information

ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear:

ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear: ω-automata ω-automata Automata that accept (or reject) words of infinite length. Languages of infinite words appear: in verification, as encodings of non-terminating executions of a program. in arithmetic,

More information

CS 3719 (Theory of Computation and Algorithms) Lecture 4

CS 3719 (Theory of Computation and Algorithms) Lecture 4 CS 3719 (Theory of Computation and Algorithms) Lecture 4 Antonina Kolokolova January 18, 2012 1 Undecidable languages 1.1 Church-Turing thesis Let s recap how it all started. In 1990, Hilbert stated a

More information

http://aejm.ca Journal of Mathematics http://rema.ca Volume 1, Number 1, Summer 2006 pp. 69 86

http://aejm.ca Journal of Mathematics http://rema.ca Volume 1, Number 1, Summer 2006 pp. 69 86 Atlantic Electronic http://aejm.ca Journal of Mathematics http://rema.ca Volume 1, Number 1, Summer 2006 pp. 69 86 AUTOMATED RECOGNITION OF STUTTER INVARIANCE OF LTL FORMULAS Jeffrey Dallien 1 and Wendy

More information

Computability Theory

Computability Theory CSC 438F/2404F Notes (S. Cook and T. Pitassi) Fall, 2014 Computability Theory This section is partly inspired by the material in A Course in Mathematical Logic by Bell and Machover, Chap 6, sections 1-10.

More information

Approximating Context-Free Grammars for Parsing and Verification

Approximating Context-Free Grammars for Parsing and Verification Approximating Context-Free Grammars for Parsing and Verification Sylvain Schmitz LORIA, INRIA Nancy - Grand Est October 18, 2007 datatype a option = NONE SOME of a fun filter pred l = let fun filterp (x::r,

More information

University of Wales Swansea. Department of Computer Science. Compilers. Course notes for module CS 218

University of Wales Swansea. Department of Computer Science. Compilers. Course notes for module CS 218 University of Wales Swansea Department of Computer Science Compilers Course notes for module CS 218 Dr. Matt Poole 2002, edited by Mr. Christopher Whyley, 2nd Semester 2006/2007 www-compsci.swan.ac.uk/~cschris/compilers

More information

. 0 1 10 2 100 11 1000 3 20 1 2 3 4 5 6 7 8 9

. 0 1 10 2 100 11 1000 3 20 1 2 3 4 5 6 7 8 9 Introduction The purpose of this note is to find and study a method for determining and counting all the positive integer divisors of a positive integer Let N be a given positive integer We say d is a

More information

ASSIGNMENT ONE SOLUTIONS MATH 4805 / COMP 4805 / MATH 5605

ASSIGNMENT ONE SOLUTIONS MATH 4805 / COMP 4805 / MATH 5605 ASSIGNMENT ONE SOLUTIONS MATH 4805 / COMP 4805 / MATH 5605 (1) (a) (0 + 1) 010 (finite automata below). (b) First observe that the following regular expression generates the binary strings with an even

More information

Eventia Log Parsing Editor 1.0 Administration Guide

Eventia Log Parsing Editor 1.0 Administration Guide Eventia Log Parsing Editor 1.0 Administration Guide Revised: November 28, 2007 In This Document Overview page 2 Installation and Supported Platforms page 4 Menus and Main Window page 5 Creating Parsing

More information

Lecture 9. Semantic Analysis Scoping and Symbol Table

Lecture 9. Semantic Analysis Scoping and Symbol Table Lecture 9. Semantic Analysis Scoping and Symbol Table Wei Le 2015.10 Outline Semantic analysis Scoping The Role of Symbol Table Implementing a Symbol Table Semantic Analysis Parser builds abstract syntax

More information

24 Uses of Turing Machines

24 Uses of Turing Machines Formal Language and Automata Theory: CS2004 24 Uses of Turing Machines 24 Introduction We have previously covered the application of Turing Machine as a recognizer and decider In this lecture we will discuss

More information

On String Languages Generated by Spiking Neural P Systems

On String Languages Generated by Spiking Neural P Systems On String Languages Generated by Spiking Neural P Systems Haiming Chen 1, Rudolf Freund 2, Mihai Ionescu 3, Gheorghe Păun 4,5, Mario J. Pérez-Jiménez 5 1 Computer Science Laboratory, Institute of Software

More information

Questions and Answers in Computer Science. By Yonas Tesfazghi Weldeselassie http://www.ictp.trieste.it/ weldesel

Questions and Answers in Computer Science. By Yonas Tesfazghi Weldeselassie http://www.ictp.trieste.it/ weldesel Questions and Answers in Computer Science By Yonas Tesfazghi Weldeselassie http://www.ictp.trieste.it/ weldesel The Questions in this material are collected from Computer Science Subject Graduate Record

More information

MBA Jump Start Program

MBA Jump Start Program MBA Jump Start Program Module 2: Mathematics Thomas Gilbert Mathematics Module Online Appendix: Basic Mathematical Concepts 2 1 The Number Spectrum Generally we depict numbers increasing from left to right

More information

Class Notes CS 3137. 1 Creating and Using a Huffman Code. Ref: Weiss, page 433

Class Notes CS 3137. 1 Creating and Using a Huffman Code. Ref: Weiss, page 433 Class Notes CS 3137 1 Creating and Using a Huffman Code. Ref: Weiss, page 433 1. FIXED LENGTH CODES: Codes are used to transmit characters over data links. You are probably aware of the ASCII code, a fixed-length

More information

POLYNOMIALS and FACTORING

POLYNOMIALS and FACTORING POLYNOMIALS and FACTORING Exponents ( days); 1. Evaluate exponential expressions. Use the product rule for exponents, 1. How do you remember the rules for exponents?. How do you decide which rule to use

More information

NP-Completeness and Cook s Theorem

NP-Completeness and Cook s Theorem NP-Completeness and Cook s Theorem Lecture notes for COM3412 Logic and Computation 15th January 2002 1 NP decision problems The decision problem D L for a formal language L Σ is the computational task:

More information

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, 2008. 1 Introduction 1. 2 Invoking Shell Scripts 2 Unix Shell Scripts Norman Matloff July 30, 2008 Contents 1 Introduction 1 2 Invoking Shell Scripts 2 2.1 Direct Interpretation....................................... 2 2.2 Indirect Interpretation......................................

More information

Chapter 2: Elements of Java

Chapter 2: Elements of Java Chapter 2: Elements of Java Basic components of a Java program Primitive data types Arithmetic expressions Type casting. The String type (introduction) Basic I/O statements Importing packages. 1 Introduction

More information

Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction

Dynamic Programming. Lecture 11. 11.1 Overview. 11.2 Introduction Lecture 11 Dynamic Programming 11.1 Overview Dynamic Programming is a powerful technique that allows one to solve many different types of problems in time O(n 2 ) or O(n 3 ) for which a naive approach

More information

6.3 Conditional Probability and Independence

6.3 Conditional Probability and Independence 222 CHAPTER 6. PROBABILITY 6.3 Conditional Probability and Independence Conditional Probability Two cubical dice each have a triangle painted on one side, a circle painted on two sides and a square painted

More information

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm Scanning and Parsing Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm Today Outline of planned topics for course Overall structure of a compiler Lexical analysis

More information

How To Understand The Theory Of Computer Science

How To Understand The Theory Of Computer Science Theory of Computation Lecture Notes Abhijat Vichare August 2005 Contents 1 Introduction 2 What is Computation? 3 The λ Calculus 3.1 Conversions: 3.2 The calculus in use 3.3 Few Important Theorems 3.4 Worked

More information

Algebraic Recognizability of Languages

Algebraic Recognizability of Languages of Languages LaBRI, Université Bordeaux-1 and CNRS MFCS Conference, Prague, August 2004 The general problem Problem: to specify and analyse infinite sets by finite means The general problem Problem: to

More information

Lecture 2: Universality

Lecture 2: Universality CS 710: Complexity Theory 1/21/2010 Lecture 2: Universality Instructor: Dieter van Melkebeek Scribe: Tyson Williams In this lecture, we introduce the notion of a universal machine, develop efficient universal

More information

SECTION 10-5 Multiplication Principle, Permutations, and Combinations

SECTION 10-5 Multiplication Principle, Permutations, and Combinations 10-5 Multiplication Principle, Permutations, and Combinations 761 54. Can you guess what the next two rows in Pascal s triangle, shown at right, are? Compare the numbers in the triangle with the binomial

More information

Web Data Extraction: 1 o Semestre 2007/2008

Web Data Extraction: 1 o Semestre 2007/2008 Web Data : Given Slides baseados nos slides oficiais do livro Web Data Mining c Bing Liu, Springer, December, 2006. Departamento de Engenharia Informática Instituto Superior Técnico 1 o Semestre 2007/2008

More information

Automata, languages, and grammars

Automata, languages, and grammars Automata, languages, and grammars Cristopher Moore January 24, 2015 Abstract These lecture notes are intended as a supplement to Moore and Mertens The Nature of Computation, and are available to anyone

More information