CS 454, Section 001 Sonoma State University Spring, 2024
 
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, the SSU CS faculty recently have approved an updated course description. Also, the required SSU Signature Project for SSU's Upper Division GE Area B Requirement for CS Majors has been rethought for this course. Currently, the Web site is reasonably stable, but modest refinements are likely. Check these pages regularly for adjustments.


Contract Negotiations Have Yielded a Tentative Agreement

Since May, 2024, the California Faculty Association (CFA) – the labor union of professors, lecturers, librarians, counselors, and coaches across the 23 California State University campuses – has been in negotiations with the management of the California State University System. After a one-day strike on Monday, January 22, the two sides have reached a tentative agreement, and the strike has been called off. Effective Tuesday, January 23, SSU classes (including CS 454) will be held as scheduled.

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 Pascal: Suppose the symbols Boolean-expression and statement have been defined for the Pascal language through a context-free grammar. Then, the Pascal Standard specifies the following context-free grammar for "if" statements:

    if-statement → "if"  Boolean-expression  "then"  statement
                       |   "if"  Boolean-expression  "then"  statement else-part
      
     else-part →   "else"  statement
            

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

    if (x < 1.5)
         then if (y > 4)
           
            then   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 Pascal standard added a note to resolve this issue for compilers. Thus, while the formal grammar was ambiguous, the interpretation in actual programs was not.

  3. Conditional Statements in Some Programming Languages: In some programming languages, a cond statement is roughly defined as a type of generalized if statement in C/C++. This exercise explores a variation of this construction.

    Notes:

    Suppose the symbols condition and statement have been defined through a context-free grammar for Boolean expressions and statements, respectively, within the programming language.

    1. Give a context-free grammar that generates exactly the cond statements of this language.
    2. Write a state diagram of a PDA that accepts exactly the cond statements of this programming language (using condition and statement as simple input symbols).

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
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.