CS 454, Section 001 Sonoma State University Spring, 2026
 
Theory of Computation
Instructor: Henry M. Walker

Lecturer, Sonoma State University
Professor Emeritus of Computer Science and Mathematics, Grinnell College

Although much of this course has been well developed in recent semesters, some details may be adjusted from semester to semester. For example, the Signature Project for this course has satisfied SSU's Upper Division GE Area B Requirement for CS Majors for several years, and satisfying that requirement again this semester. However, details of this project likely vary from instructor to instructor and from semester to semester. Also,

Assignment on Pushdown Automata and Context-free Grammars

Context-free Grammars

  1. Let CFG W be

    S → x S y | x Q | Q y
    Q → x Q | y Q | ε
    1. Describe L(W) in simple English, and justify your answer.
    2. Use that description to give a CFG for L(W), the complement of L(W).
  2. if Statements in C/C++: Suppose the symbols expression and statement have been defined for the C/C++ language through a context-free grammar. Then, the C/C++ Draft Standard ISO/IEC 9899:201x (April 12, 2011, page 472) specifies the following (slightly-edited) context-free grammar for if statements (where words in bold font are designated keywords):

    if-statementif  ( expression )  statement
               |   if  ( expression )  else  statement
            

    Assume both (x < 1.5) and (y > 4) are valid expressions, and assume assignments a := 6.7; and b := -x; are valid statements. Consider the C/C++ code:

    if ( x < 1.5 )
         if (y > 4)
            a = 6.7;
      else 
           b = -x;
            
    1. Show the formal grammar is ambiguous by giving two different derivations of this code segment.
    2. For each derivation, show the corresponding parse tree.
    3. Convert the above grammar to Chomsky Normal Form.

    Note that the C/C++ standards add a note to resolve this issue for compilers. Thus, while the formal grammar is ambiguous, the interpretation in actual programs is not.

  3. Regular/Non-regular Languages and Context-free Languages: Consider the following two languages:

    Exercises:

    1. Are languages L and M Regular Languages? Either show that they are Regular by outlining the construction of a DFA or NFA, or give a proof that they cannot be Regular.
    2. Show languages L and M are Context-free by constructing an appropriate grammar.

Pushdown Automata

  1. Using the alphabet Σ = {a, b}, consider the language L of strings with the same number of a's and b's.

    1. Is language L regular? Either give a DFA that accepts this language, or prove that no such DFA exists.
    2. Describe a pushdown automaton that accepts exactly those strongs in the language L, or explain why such a PDA cannot exist.
  2. Consider the problem of checking whether an expression has balanced parentheses. For example, (())() is balanced, but ())()), ((), and ())(() are not. (In the last case, there are the same number of left and right parentheses, but the second right parenthesis appears before the a corresponding left parenthesis appears—that is, the left and right parentheses appear in the wrong order to balance.)

    The following diagram is a proposed to accepted expressions with matching parentheses:

    1. Does the proposed PDF accept strings with balanced parentheses or not? Explain.
    2. Write a state diagram for a PDA over the alphabet Σ = { {, }, <, >, (, ) } , which accepts exactly those strings where parentheses match and are properly nested,

      For example, the string ({<>}) is properly matched, but neither ({><}) nor ({<)}>) are.

created Fall, 2023
revised Fall, 2023
revised October, 2025
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.
ccbyncsa.png

Copyright © 2011-2026 by Henry M. Walker.
Selected materials copyright by Marge Coahran, Samuel A. Rebelsky, John David Stone, and Henry Walker and used by permission.
This page and other materials developed for this course are under development.
This and all laboratory exercises for this course are licensed under a Creative Commons Attribution-NonCommercial-Share Alike 4.0 International License.