Skip to content

Commit

Permalink
added build files
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-doty committed Oct 8, 2024
1 parent 962a5db commit 49e1bfb
Show file tree
Hide file tree
Showing 25 changed files with 1,635 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/0-three-from-end.nfa
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
states = {q1,q2,q3,q4}
input_alphabet = {0,1}
start_state = q1
accept_states = {q4}
delta =
q1,0 -> {q1,q2};
q1,1 -> q1;
q2,0 -> q3;
q2,1 -> q3;
q3,0 -> q4;
q3,1 -> q4;
12 changes: 12 additions & 0 deletions examples/0s1s2s.nfa
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// This NFA recognizes the language described by the regular expression 0*1*2*

states = {q0,q1,q2}
input_alphabet = {0,1,2}
start_state = q0
accept_states = {q2}
delta =
q0,0 -> q0;
q0, -> q1;
q1,1 -> q1;
q1, -> q2;
q2,2 -> q2;
8 changes: 8 additions & 0 deletions examples/balanced-parens.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This context-free grammar generates the language of balanced (square bracket) parentheses.

S -> [S] | SS | ;

// The line above is equivalent to writing
// S -> [S];
// S -> SS;
// S -> ;
3 changes: 3 additions & 0 deletions examples/contains-010.regex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// matches any binary string containing the substring 010
B = (0|1)*; // subexpression matching any binary string
B 010 B
21 changes: 21 additions & 0 deletions examples/count-a-wildcard.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This TM counts the number of a's on the first tape and writes that
// number of 0's on the second tape. It demonstrates the use of the ?
// wildcard in specifying transition rules. Note that because they have
// no wildcard symbols, the rules
// q1,a_ -> q1,a0,RR;
// and
// q1,__ -> qA,__,SS;
// overrride the wildcard rule
// q1,?_ -> q1,?_,RS;

states = {q,qA,qR}
input_alphabet = {a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z}
tape_alphabet_extra = {0,_}
start_state = q
accept_state = qA
reject_state = qR
num_tapes = 2
delta =
q,?_ -> q, ?_,RS;
q,a_ -> q, a0,RR;
q,__ -> qA,__,SS;
16 changes: 16 additions & 0 deletions examples/double-inferred-states.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This TM computes the function f(0^n) = 0^{2n}.

states = ? // the state names are inferred from the rest of the definition
input_alphabet = {0}
tape_alphabet = {_,!}
start_state = q0
accept_state = qA
reject_state = qR
num_tapes = 2
delta =
q0,0_ -> q1,0!,SR;
q1,0_ -> q2,00,SR;
q2,0_ -> q1,00,RR;
q1,__ -> qD,__,SL;
qD,_0 -> qD,_0,SL;
qD,_! -> qA,_!,SR;
16 changes: 16 additions & 0 deletions examples/double.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This TM computes the function f(0^n) = 0^{2n}.

states = {q0,q1,q2,qD,qA,qR}
input_alphabet = {0}
tape_alphabet_extra = {!,_}
start_state = q0
accept_state = qA
reject_state = qR
num_tapes = 2
delta =
q0,0_ -> q1,0!,SR;
q1,0_ -> q2,00,SR;
q2,0_ -> q1,00,RR;
q1,__ -> qD,__,SL;
qD,_0 -> qD,_0,SL;
qD,_! -> qA,_!,SR;
27 changes: 27 additions & 0 deletions examples/no-000-end.dfa
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// This DFA recognizes { x in {0,1}* | x does not end in 000 }

states = {q, // last bit was a 1 or non-existent
q0, // last two bits were 10
q00, // last three bits were 100
q000} // last three bits were 000

input_alphabet = {0,1}

start_state = q // no last bit when we start

accept_states = {q,q0,q00} // accept if last three bits were not 000

delta =
// if we see a 1, reset
q,1 -> q;
q0,1 -> q;
q00,1 -> q;
q000,1 -> q;

// if we see a 0, count one more 0 than before
q,0 -> q0;
q0,0 -> q00;
q00,0 -> q000;

// until we get to three
q000,0 -> q000;
30 changes: 30 additions & 0 deletions examples/palindrome-single-tape.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This TM recognizes the language { w in {0,1}* | w = w^R }

states = {s,r00,r11,r01,r10,l,lx,qA,qR}
input_alphabet = {0,1}
tape_alphabet_extra = {x,_}
start_state = s
accept_state = qA
reject_state = qR
delta =
s,0 -> r00,x,R;
s,1 -> r11,x,R;
r00,0 -> r00,0,R;
r00,1 -> r01,1,R;
r01,0 -> r00,0,R;
r01,1 -> r01,1,R;
r10,0 -> r10,0,R;
r10,1 -> r11,1,R;
r11,0 -> r10,0,R;
r11,1 -> r11,1,R;
r00,_ -> lx,_,L;
r11,_ -> lx,_,L;
r00,x -> lx,x,L;
r11,x -> lx,x,L;
lx, 0 -> l,x,L;
lx, 1 -> l,x,L;
lx, x -> qA,x,S;
l, 0 -> l,0,L;
l, 1 -> l,1,L;
l, x -> s,x,R;
s, x -> qA,x,S;
30 changes: 30 additions & 0 deletions examples/w-marker-w-wildcard.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// This TM recognizes the language { w:w | w is a string in {0,1}* }
// It is the same as the one described in w-marker-w.tm.

// It demonstrates the use of the ? wildcard in specifying transition rules.

states = {q1,q2,q3,q4,q5,q6,q7,q8,qA,qR}
input_alphabet = {0,1,:}
tape_alphabet_extra = {x,_}
start_state = q1
accept_state = qA
reject_state = qR
num_tapes = 1
delta =
q1,0 -> q2,x,R;
q1,1 -> q3,x,R;
q1,: -> q8,:,R;
q2,? -> q2,?,R;
q2,: -> q4,:,R;
q3,? -> q3,?,R;
q3,: -> q5,:,R;
q4,0 -> q6,x,L;
q4,x -> q4,x,R;
q5,1 -> q6,x,L;
q5,x -> q5,x,R;
q6,? -> q6,?,L;
q6,: -> q7,:,L;
q7,? -> q7,?,L;
q7,x -> q1,x,R;
q8,x -> q8,x,R;
q8,_ -> qA,_,R;
26 changes: 26 additions & 0 deletions examples/w-marker-w.tm
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
states = {q1,q2,q3,q4,q5,q6,q7,q8,qA,qR}
input_alphabet = {0,1,:}
tape_alphabet_extra ={x,_}
start_state = q1
accept_state = qA
reject_state = qR
num_tapes = 1
delta =
q1,0 -> q2,x,R;
q1,1 -> q3,x,R;
q1,: -> q8,:,R;
q2,? -> q2,?,R;
q2,: -> q4,:,R;
q3,? -> q3,?,R;
q3,: -> q5,:,R;
q4,0 -> q6,x,L;
q4,x -> q4,x,R;
q5,1 -> q6,x,L;
q5,x -> q5,x,R;
q6,? -> q6,?,L;
q6,: -> q7,:,L;
q6,x -> q6,x,L;
q7,? -> q7,?,L;
q7,x -> q1,x,R;
q8,x -> q8,x,R;
q8,_ -> qA,_,R;
Loading

0 comments on commit 49e1bfb

Please sign in to comment.