CS 454, Section 001 | Sonoma State University | Spring, 2026 |
Theory of Computation
|
||
Instructor: Henry M. Walker
Lecturer, Sonoma State University |
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,
Let CFG W be
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-statement → if ( 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;
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.
Regular/Non-regular Languages and Context-free Languages: Consider the following two languages:
Exercises:
Using the alphabet Σ = {a, b}, consider the language L of strings with the same number of a's and b's.
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:
For example, the string ({<>}) is properly matched, but neither ({><}) nor ({<)}>) are.
created Fall, 2023 revised Fall, 2023 revised October, 2025 |
![]() ![]() |
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |
![]() |
Copyright © 2011-2026
by Henry M. Walker.
|