A .dfa file represents a deterministic finite automaton (DFA) together with some optional input data.
You can use the cs241.DFA tool to check the syntax of these files and to process the strings in the input data with the DFA:
$ cs241.DFA < input.dfa
Here is an example of a DFA file for
a DFA that recognizes strings over
the alphabet {a, b, ..., z}
that contain cs
.
The text in italics
is not part of the file,
and is just there to describe how the file works.
.ALPHABET a-b d-r t-z c s .STATES start seen_c seen_cs! .TRANSITIONS start a b d-z start start c seen_c seen_c a-r t-z start seen_c s seen_cs seen_cs a-z seen_cs .INPUT hellocsstudents .EMPTY lyrics cstwofourone bstwofournone |
character ranges can be specified or characters can be listed individually first state listed is the initial state ! marks a state as accepting loop at 'start' on a, b, and d-z transition from 'start' to 'seen_c' on c this special keyword is treated as the empty string can list multiple inputs on one line |
For this file, the output of cs241.DFA
is:
$ cs241.DFA < input.dfa hellocsstudents true .EMPTY false lyrics true cstwofourone true bstwofournone false
The output indicates which input strings were accepted by the DFA.
The DFA is encoded in three sections (alphabet, states, transitions) and then the input is encoded in a fourth section.
.ALPHABET
, followed by a sequence of
characters or ranges, each separated by whitespace:
-
(ASCII 0x2D), and represents the
range of ASCII characters whose codes are between
the first character and second character (inclusive)..STATE
, followed by a sequence of
whitespace-separated strings representing state names.
.TRANSITIONS
, followed by a sequence of
lines representing transition collections.
A transition collection has three parts, each separated by
(non-newline) whitespace:
.INPUT
. Following this is input data
which can be used by programs that read DFA files. The format
and interpretation of this data depends on the program:
cs241.DFA
tool
will interpret the input
data as a series of whitespace-separated strings to run
through the DFA using the DFA recognition algorithm.
It will print each string followed by true
(if the string was accepted) or false
(if it was not accepted).
It will treat the special keyword .EMPTY
as the empty string.
bang!!
would
correspond to a state named bang!
that is accepting.
.TRANSITIONS
cannot be used as a state name, since
it marks the end of the states section..INPUT
can technically be used as a state name,
but you cannot use this state name in the transitions section as it marks
the end of the transitions section.