Phase 1: Postfix Expressions

In this phase of the project, you are to write a translation system, using flex and bison (or lex and yacc), that translates a list of C expressions from infix to postfix notation. Your translator should read from standard input and write to standard output.

In addition to the grammar rules in K&R that define expressions, you will need to add the rule:

        expr-list :
                expression ;
                expr-list expression ;
    

You do not need to translate expressions that use the following rules from K&R:

        expression:
                expression , assignment-expression
        cast-expression :
                ( type-name ) cast-expression
        unary-expression:
                sizeof ( type-name )
        postfix-expression:
                postfix-expression [ expression ]
        postfix-expression:
                postfix-expression ( argument-expression-list )
        postfix-expression:
                postfix-expression ( )
        postfix-expression:
                postfix-expression . identifier
        postfix-expression:
                postfix-expression -> identifier
        primary-expression:
                string
        constant:
                floating-constant
        constant:
                enumeration-constant
      
A couple of things that you should think about:
  1. C uses the same name for the pre- and post-increment operators, ++, you'll need to use different names for these operators.
  2. C also uses the same names the for post- and pre-decrement operators.
  3. The conditional expression has three operands (nothing all that interesting, just be aware of this).
A simple test file:
a + b * c ;
(a + b) * c ;
a ? b : ++c ;

'\n';
'\?';
    

Barney Maccabe
Last modified: Mon Sep 1 22:51:20 MDT 1997