CISC 223 - Assignment 2 Solutions
Winter 2014
1. (a) Accepted: 1, 010, 111 (for example)
Not accepted: 0, 11, 110 (for example)
(b) The transition table:
0
1
-A |
A
B
B |
B
C
C |
A
B
(c) The language consists of all strings that have an odd number of 1s.

CISC 223 - Assignment 1 Solutions
Winter 2015
1. (a) , 0, 1, 00, 01, 10, 11
(b) A B = cfw_1001, 1000, 100, 1101, 1100, 110, 101, 10. The language A B consists of 8
strings. (100 has two dierent decompositions as a concatenation of strings from A
and B.)
(

CISC 223 - Assignment 1 (Winter 2015)
Due: beginning of class (9:30 AM), Wednesday January 14
1. (3 marks) Let = cfw_0, 1 and consider languages A = cfw_10, 11, 1, B = cfw_01, 00, 0.
(a) Write down all strings over that have length at most two.
(b) Write

CISC 223 - Assignment 4 Solutions
Winter 2014
1. Question 1 solution:
Stage 0: At the beginning we mark as distinguishable each pair where one component
is an accepting state and the other is not.
Stage 1: (3, 5) is not marked because on a we get (1,1)

1
Context-Free Languages
This material is described in Chapter 10 of the textbook.
Context-free grammars are the most widely used specication tool for the syntactic
structure of programming languages.
Context-free grammars are more powerful than state d

1
Introduction
The relationship between programs and formal languages provides an example of the impact
of theory on practice. Uses of formal theory include the following:
lexical and parsing stages of compiler construction
use of regular expressions in

1
Parsing
This material is covered in Chapter 11 of the textbook.
Parsing is the process of determining if a string of tokens can be generated by a
grammar.
Parsing in an important step in the compilation of programming languages. Two directions:
Attemp

CISC 223 - Assignment 2 Solutions
Winter 2015
1. (a) Some strings that are accepted include: 1, 111, 010, 01110, 00001
Some strings that are not accepted include: 0, 00, 01, 011, 0111
(b) The transition table:
0
1
-A |
C
B
B |
D
A
C |
A
D
D |
B
C
(c) The

CISC223, Winter 2015, Minimization of DFAs and nonregular languages
1
Nonregular languages and minimization of DFAs
While the regular languages have nice properties (as we have seen in the early part of the
course), unfortunately many languages that we en

1
Specifying Algorithms
We now continue with Part A of the textbook.
Specications describe transformations from input values to output values.
A program transforms input values to output values in a particular way.
A specication consists of the followin

1
State-transition diagrams
This material is from Chapter 8 in the textbook.
Example. An identier can be dened as a string of letters and digits that begins with a
letter.
Token letter stands for any of the symbols a, . . . , z, A, . . . , Z.
Token digi

1
Converting regular expressions to state diagrams and
vice versa
This material is from Chapter 9 in the textbook.
We show that regular expressions and state diagrams dene exactly the same class of languages. This fact is remarkable because supercially st

CISC 223 - Assignment 3 Solutions
Winter 2015
1. The solution for Question 1 is given in Figure 1 (next page).
2. Question 2 solution: The state diagram has exactly one accepting state which is not
the starting state. Hence no initial modication of the st

CISC 223 - Assignment 2 (Winter 2015)
Due: beginning of class (9:30 AM), Wednesday January 21
1. (3 marks) Let = cfw_0, 1 and consider the state-transition diagram given in Figure 1.
0
C
A
0
1
1
1
1
0
B
0
D
Figure 1: State-transition diagram for Question

CISC 223 - Assignment 3 (Winter 2015)
Due: beginning of class (9:30 AM), Wednesday January 28
1. (3 marks) Using the method described in Section 9.1 (and in class), convert the following
regular expression into a state diagram:
(01) (0 + (01) )
Your answe

CISC 223 - Assignment 5 (Winter 2015)
Due: beginning of class (9:30 AM), Wednesday February 25
1. (2 marks) Show that the following grammar is ambiguous:
S aSbS | bSaS |
Here S is the start nonterminal and the set of terminals is cfw_a, b.
2. (4 marks) C

CISC 223 - Assignment 7
by adding all the intermediate assertions int
ASSERT( i <= j )
x = i;
y = j;
ASSERT( y >= x & y >= j & ( y = x | y = j ) )
ASSERT( y >=
if ( y > z )
else cfw_ z = z
ASSERT( y >=
0
cfw_
0
& z >= 0 )
y = y - z;
y;
&

CISC 223 - Assignment 6 (Winter 2015)
Due: beginning of class (9:30 AM), Wednesday March 4
1. (4 marks) Use left-factoring and/or eliminate left-recursion to transform each of the below
four grammars into a form that is suitable for recursive-descent pars

CISC-223 2nd Midterm, March 2014
Page 1 of 7
Queen's University
CISC-223 2nd Midterm March 2014
INSTRUCTIONS
You have 45 minutes. Attempt all ve questions.
You may bring in one 8.5 11 sheet of paper containing notes, and use it during the
midterm.
Answ

1
Verifying Algorithms
We continue the discussion how to validate correctness statements for the central programming language constructs. Next we consider loops, see Section 2.9 in the textbook.
The inference rule for while statements is:
I&B cfw_C I
I cf

1
Context-Free Languages
This material is desribed in Chapter 10 of the textbook.
Context-free grammars are the most widely used speiation tool for the syntati
struture of programming languages.
Context-free grammars are more powerful than state diagrams,

CISC/CMPE 223 - Assignment 2 Solutions
Winter 2017
1. (a) Some strings that are aepted inlude: 1, 111, 010, 01110, 00001
Some strings that are not aepted inlude: 0, 00, 01, 011, 0111
(b) The transition table:
0
1
-A |
C
B
B |
D
A
C |
A
D
D |
B
C
() The la

1
Verifying Algorithms
We ontinue the disussion how to validate orretness statements for the entral programming language onstruts. Next we onsider loops, see Setion 2.9 in the textbook.
The inferene rule for while statements is:
I&B cfw_C I
I cfw_while(B)

1
Parsing
This material is overed in Chapter 11 of the textbook.
Parsing is the proess of determining if a string of tokens an be generated by a
grammar.
Parsing in an important step in the ompilation of programming languages. Two diretions:
Attempt to on

1
Specifying Algorithms
We now ontinue with Part A of the textbook.
Speiations desribe transformations from input values to output values.
A program transforms input values to output values in a partiular way.
A speiation onsists of the following parts:

1
Introduction
The relationship between programs and formal languages provides an example of the impat
of theory on pratie. Uses of formal theory inlude the following:
lexial and parsing stages of ompiler onstrution
use of regular expressions in text edit

Application: DNA and protein sequence matching
0 Primary structure of proteins: sequence of amino acids.
20 different amino acids, encoded as one-letter symbols
0 DNA molecule: two strands made up of a sequence of nucleotides
bases: Adenine, Thymine, Cyto

CISC/CMPE 223 - Assignment 3 (Winter 2017)
Due: Thursday February 2 by 3:30 PM
(in the loked CISC 223 drop-o box on Goodwin 2nd oor)
Papers that have all the names and
student numbers written exatly as requested in the regulations (found at the end), will

CISC/CMPE 223 - Assignment 1 Solutions
Winter 2017
1. (a) A B = cfw_baab, baaa, baa, bbab, bbaa, bba, bab, ba. The language A B onsists of 8
strings. (baa has two dierent deompositions as a onatenation of strings from A
and B .)
(b) B A = cfw_abba, abbb,

Module 1 Concept Quiz
Question 1: Two components in a system, C1 and C2 are tested and declared to
be in one of three possible states: Functioning (F), not functioning but repairable
(R); and kaput (K).
1. What is the sample space in this experiment?
2. W