fsa2 - Sara Kazemi 02/15/2008 Ling 581 Malouf Assignment #1...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Sara Kazemi 02/15/2008 Ling 581 Malouf Assignment #1 Exercise 1 The original implementation of recognize for Non-deterministic Finite State Automata (NFSAs) performs a depth-first or Last in First Out (LIFO) search. The recognize module was modified by adding a keyword argument (I called this depthFirst) which the user can use to control the which search implementation the recognize method uses, either LIFO or FIFO (in this case, setting the keyword argument to True initiates a LIFO search and setting it to False initiates a FIFO search). If the user specifies that a LIFO search will be done, recognize runs through the same while loop that the original code specified. This loop makes use of pop(), which treats the agenda as a stack and removes the element last added to it (last in first out) as the machine moves through the recognize loop. If the user specifies a FIFO search, the program moves to the else clause of the if bi- conditional and goes through a similar loop. The very important distinction between the LIFO and FIFO loop is that the agenda is treated as a queue rather than a stack. By specifying 0 as the index number by changing pop() to pop(0), the 0th or first added element of the index is removed from the list during the recognize loop (first in first out). >>> fsa2.recognize('baa!',depthFirst=True, trace=True) Obs 0 at state 0 Obs 1 at state 1 Obs 2 at state 2 Obs 3 at state 3 Obs 4 at state 4 ACCEPT True >>> >>> fsa2.recognize('baa!',depthFirst=False,trace=True) Obs 0 at state 0 Obs 1 at state 1 Obs 2 at state 2 Obs 3 at state 2 Obs 3 at state 3 Obs 4 at state 4 ACCEPT True >>>
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Exercise 2 The original program can identify strings that are members of "Sheep Language" ( [ba*!]) through searching the language's NFSAs and DFSA. In order to identify the Sheep Language's complement language deterministically, it was necessary to modify the DFSA so that it acknoweldged all other potential combinations of the alphabet used by Sheep Language that is not actually in that language (i.e. in its complement language) such as 'baa' or 'aba!aaa'. This was done by adding a sink state or fail state to the DFSA, to which all strings not in the Sheep Language would transition to. After this was done, a new method to recognize these complement language strings was defined. This method, complement, is the same as the recognize method, save for one change in what is accepts and rejects. By changing the line "if current_state in self.finals:" that was used in recognize to "if current_state not in self.finals:", complement accepts all strings with the same alphabet as the Sheep Language that end in a non-accepting state and rejects all of those strings that end in an accepting final state (because those are in the Sheep Language). >>> fsa1.complement('baa!',trace=True)
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/06/2009 for the course LING 571 taught by Professor Staff during the Fall '08 term at San Diego State.

Page1 / 10

fsa2 - Sara Kazemi 02/15/2008 Ling 581 Malouf Assignment #1...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online