0

I am looking for an algorithm to convert a Deterministic Finite Automata to Push Down Automata.

Any help appreciated.

Thanks!

iBiryukov
  • 1,730
  • 4
  • 19
  • 30

4 Answers4

3

The PDA version of DFA would look the same except each state transition also pushes nothing on the stack and pops nothing off the stack.

Austin
  • 2,771
  • 1
  • 18
  • 14
1

Since a PDA is an extension of a DFA with just one additional feature : stack. Because the transition of a PDA is determined by a triple (current state, input, element at the top of the stack) while transition of a DFA is determined by a tuple (current state, input). And the only difference is the element at the top of the stack. You can convert all the transitions of DFA by transforming the tuple to a triple, e (empty string) inserted as the element at the top of the stack

And after changing the state, push e (empty string) to the stack.

bliss
  • 330
  • 3
  • 14
0

I'm answering this old question just in case someone else looks at it.

The conversions of DFA to PDA can be automated easily by just adding a stack. But there could be possible changes to the semantics of the DFA and after you change it that way manually you could end up in a PDA with less number of states. I faced this problem recently. Its somewhat like this,

In a system (not a compiler or anything like that) the code written earlier was written using an DFA due to some reasons. The transitions occur as the user progress through the code using various functions. After some time a new set of transitions functions arrived which can be used in any order. and also the state after any of these new functions can change back to previous state by one of these functions. The only way to solve this using FST was to add a large number of new states to support this behavior which i a huge amount of work. But instead I just changed from DFA to a PDA. The stack keeps track of the transitions very nicely and the problem is solved with far less number of states. Actually i only had to add N number of states where N is the number of new functions that arrived.

I do not know if someone can automate this kind of a process easily. But there you go, just in case someone is curious about it.

Deamonpog
  • 805
  • 1
  • 10
  • 24
-1

The wikipedia article says

Pushdown automata differ from finite state machines in two ways:

  1. They can use the top of the stack to decide which transition to take.
  2. They can manipulate the stack as part of performing a transition.

Pushdown automata choose a transition by indexing a table by input signal, current state, and the symbol at the top of the stack. This means that those three parameters completely determine the transition path that is chosen. Finite state machines just look at the input signal and the current state: they have no stack to work with. Pushdown automata add the stack as a parameter for choice.

...
Pushdown automata are equivalent to context-free grammars: for every context-free grammar, there exists a pushdown automaton such that the language generated by the grammar is identical with the language generated by the automaton, which is easy to prove. The reverse is true, though harder to prove: for every pushdown automaton there exists a context-free grammar such that the language generated by the automaton is identical with the language generated by the grammar.

hlovdal
  • 26,565
  • 10
  • 94
  • 165
  • The question is not very precise, and he does not reveal anything about what he have tried or what he knows. The wikipedia article contains much information (how should I know if he has read this?). And also from just reading the extract, studying context-free grammars seems to be helpful. "Any help appreciated" puts the bar quite low on what might be helpful. – hlovdal Mar 15 '11 at 15:47
  • His question is 100% clear. Sure he has not given any code, but that is because he is looking for an algorithm describing how to convert a DFA to a PDA. Does not get more clear than that. The Wikipedia article does not give such an algorithm. – Nico Huysamen Mar 15 '11 at 17:40
  • Uh, it's been a while. @hlovdai - I am aware of the existence of wikipedia. I don't see any point in copy pasting :) I have solved the problem more or less myself. Just if anyone is interested, here is my code (C#) that produces NFA,DFA, N-PDA and Deterministic PDA (somewhat buggy still). http://dl.dropbox.com/u/1855144/Parser.7z The info on parsing/compilers is very scarce, unfortunately. Hope, this will help someone. – iBiryukov Apr 24 '11 at 04:57