Chapter 18 Part II: PDA Transducers

Topics
What is a PDA transducer
PDA transducer for converting infix notation to postfix notation
A scheme for producing postfix from infix (no parens)
The PDA machine
Adding parentheses to our language

 

What is a PDA transducer? We add to our PDA
PDA transducer for converting infix notation to postfix notation

Infix notation:

Postfix notation:
A scheme for producing postfix from infix (no parens)
  1. Operators cannot be printed until after the operands are seen: e.g. a + b Þ ab+ . So we will save operators when we read them, and print them later. We will save them on the stack
  2. Think about a + b * c * d + e + f .

  3. The red * would have been saved on the top of the stack until after the c is read. It can be printed at that point, regardless of what operator comes before or after, because * has higher precedence that +.  We would end up printing the subexpression bc* (which is correct).
  4. Think about:   a + b * c * d + e + f .

  5. The red + would have been saved on the top of the stack until after the b is read. It cannot be printed at that point, because * has higher precedence than +. We will have to:

The PDA machine

Here is a PDA that implements the above idea for

Let’s follow the workings of this machine for some sample input (the stack is shown after reading an operator; the top of the stack is to the right):
 
input   a + b * c D        
stack  D   +   +*   D        
print   a   b   c *+        

a+b*c Þ abc*+
 
input   a * b + c D        
stack  D   *   +   D        
print   a   b * c +        

a*b+c Þ ab*c+
 
input   a + b * c * d + e D
stack  D   +   +*   +*   +   D
print   a   b   c * d *+ e +

a+b*c*d+e Þ abc*d*+e+


Adding parentheses to our language

Here is the scheme:

The complete machine (including parens) is given on p. 427 of our book.
 
 
Hosted by www.Geocities.ws

1