0% found this document useful (0 votes)
8 views2 pages

CSC 312 Assignment Solution

The document provides solutions for a CSC 312 assignment, detailing regular expressions for decimal and octal integers, valid C identifiers, integer and string constants. It also includes NFA and DFA transition tables, highlighting the differences between NFA and DFA in terms of determinism and state complexity. Additionally, it presents specific NFA transition tables for given patterns.

Uploaded by

Nwodo Chinenye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

CSC 312 Assignment Solution

The document provides solutions for a CSC 312 assignment, detailing regular expressions for decimal and octal integers, valid C identifiers, integer and string constants. It also includes NFA and DFA transition tables, highlighting the differences between NFA and DFA in terms of determinism and state complexity. Additionally, it presents specific NFA transition tables for given patterns.

Uploaded by

Nwodo Chinenye
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

CSC 312 Assignment Solution

Q1: Regular Expressions


a. Decimal Integers:

^[+-]?[0-9]+$

Explanation: This matches an optional + or - sign, followed by one or more digits.

b. Octal Integers:

^[+-]?[0-7]+$

Explanation: This matches an optional + or - sign, followed by one or more digits between 0
and 7.

c. A valid identifier in C Programming Language:

^[a-zA-Z_][a-zA-Z0-9_]*$

Explanation: The first character must be a letter or underscore, followed by any number of
letters, digits, or underscores.

d. Integer Constant:

^[+-]?([0-9]+|0[0-7]*|0[xX][0-9a-fA-F]+)$

Explanation: This allows optional + or -, followed by either a decimal number, an octal


number (starting with 0), or a hexadecimal number (starting with 0x or 0X).

e. String Constant:

^"([^"\\]|\\.)*"$

Explanation: This matches a string enclosed in double quotes where the contents are either
any character except " and \, or an escaped character like \" or \\.

Q2: NFA and DFA

Q2a: NFA Transition Table and DFA


(i) NFA Transition Table for given NFA diagram:

State Input 0 Input 1 ε (epsilon)

q0 {q1} ∅ {q1, q2}


q1 ∅ {q2} ∅

q2 {q0} {q2} ∅

(ii) DFA Transition Table:

DFA State Input 0 Input 1

{q0, q1, q2} {q0, q1, q2} {q2}

{q2} {q0, q1, q2} {q2}

{q1, q2} ∅ {q2}

{q1} ∅ {q2}

Q2b: Differences Between NFA and DFA


1. Determinism: NFA allows multiple transitions for the same input from a given state, while
DFA has exactly one transition for each input symbol.

2. State Complexity: NFA can have fewer states than DFA, but DFA is simpler to implement
since it has a deterministic path for each input.

(i) NFA Transition Table for 0(0|1)*01:

State Input 0 Input 1 ε (epsilon)

q0 q1 ∅ ∅

q1 q1, q2 q1 ∅

q2 ∅ q3 ∅

q3 ∅ ∅ (Accepting)

(ii) NFA Transition Table for 01|10:

State Input 0 Input 1 ε (epsilon)

q0 q1 q3 ∅

q1 ∅ q2 ∅

q2 ∅ ∅ (Accepting)

q3 q4 ∅ ∅

q4 ∅ ∅ (Accepting)

You might also like