LL(k) grammar for c?

Laurence R. Brothers quasar at krazykat.ctt.bellcore.com
Tue May 9 23:31:01 AEST 1989


First: Please reply via email, since I don't read this group.

I want a program that produces parse trees of c programs. In the
absence of one, I'll take a good grammar and write the program myself.

Since I want the parse tree to at least vaguely resemble the intuitive
structure of the code, I'd prefer a LL grammar that would allow a
recursive-descent parser to be easily written. I realize
that you can't have a true LL(k) grammar for C, but I'd like one
that's close, at least.

Alternatively, I'd like a yacc style LR grammar, but one with
reaonable rules for things like expressions. I currently have
a yacc grammar, but about 64 rules fire just to parse a literal
expression.

For an example of what I don't want, this is the parse of the c
statement "Return y;" in the yacc grammar I have now.

       decl_or_stmt
        stmt
         bal_stmt
          basic_stmt
           return_stmt
            Return
            list_exp
             exp
              assign_exp
               cond_exp
                or_oper_exp
                 and_oper_exp
                  bitor_oper_exp
                   bitxor_oper_exp
                    bitand_oper_exp
                     equ_oper_exp
                      rel_oper_exp
                       shift_oper_exp
                        add_oper_exp
                         mult_oper_exp
                          unary_oper_exp
                           cast_exp
                            prefix_exp
                             postfix_exp
                              primary_exp
                               primary_p2_exp
                                primary_p1_exp
                                 identifier
            ;


	    Laurence R. Brothers (quasar at ctt.bellcore.com)
Bellcore -- Computer Technology Transfer -- Knowledge-Based Systems Development
		 "...to seek the helpless future...."



More information about the Comp.lang.c mailing list