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?
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.