Re: Using BTYACC to write C compiler (Scott Nicol)
10 May 1996 01:32:00 -0400

          From comp.compilers

Related articles
Using BTYACC to write C compiler (Jules) (1996-05-08)
Re: Using BTYACC to write C compiler (1996-05-10)
Re: Using BTYACC to write C compiler (1996-05-19)
| List of all articles for this month |

From: (Scott Nicol)
Newsgroups: comp.compilers
Date: 10 May 1996 01:32:00 -0400
Organization: Information Advantage
References: 96-05-060
Keywords: C says...
>I have started work with the ``ansiC.y'' and ``ansiC2.y'' grammars
>that were included in the BTYACC package, and wrote a lexical analyser
>for these using FLEX. My problem is that while trying to parse my
>assembler (which is an almost correct ANSI C program, and at least
>accepted as syntactically correct by every C compiler I've tried it
>on), the grammar freezes after a certain point, and I am unsure why.

You need to turn on Lex and YACC debugging. The Lex debugging output
should be obvious, but to read the YACC output, you need to have a
copy of y.output handy (generated using yacc -v). YACC will report
"State #, Token #". You can lookup the token in, and the
state in y.output. You will also see "reduce by #", which means that
you have just completed a rule - the reductions are also available in

Having to lookup stuff in y.output is a pain, and it can be confusing
at first. Some YACCs will let you interactively trace a running
grammar, so if you need to trace things often, this may be worth
looking into.

BTW, I agree with the following comments from the moderator:

>[I'd start with lcc. There's a lot more to a C compiler than the parser.

I would add that, if you need C++, you may want to port g++ at some
point in the future. But start with lcc.

Scott Nicol email:
Information Advantage, Inc.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.