Can the second argument of a stack machine's transition function be the empty string?

47 Views Asked by At

I am learning about stack machines. The text I am using is Formal Languages, by Adam Brooks Webber (which I really like). He defines stack machines formally as follows:

A stack machine M is a 4-tuple M = (Γ,Σ,S,δ), where Γ is the stack alphabet, Σ is the input alphabet, S ∈ Γ is the initial stack symbol, δ ∈ ((Σ ∪ {ε}) x Γ → P(Γ*)) is the transition function.

According to this definition, it would appear that the transition function can take the empty string as its first argument, and can return the empty string, but cannot take the empty string as its second argument. Is it not possible, then, to specify a legal transition that pushes a string onto the stack regardless of the symbol at the top of the stack? If it is possible, how would you specify such a transition?

2

There are 2 best solutions below

2
On

Sure, you just need one rule for each possible stack symbol. Each of these rules uses no input, pops the associated stack symbol, and then pushes the same symbol back onto the stack along with the rest of the symbols you want to push.

0
On

By definition, a string is accepted by a stack machine if, after the last symbol of the string is processed, the stack is empty. If a transition function were defined that takes as it's second argument the empty string, it could potentially describe an empty stack, and thus describe the addition of something to the empty stack.

As rici points out, you can still specify transition functions for each symbol of the stack alphabet which pop the symbol and then replaces it, but being able to specify the empty string would, I presume, cause issues with how a stack machine accepts strings.

That's what occurred to this novice learning the subject after a lot of head scratching. If anyone can add to that or explain it more formally, I would welcome it.