Re: Using BTYACC to write C compiler

Scott.Nicol@infoadvn.com (Scott Nicol)
10 May 1996 01:32:00 -0400

          From comp.compilers

Related articles
Using BTYACC to write C compiler J.R.Hall@dcs.warwick.ac.uk (Jules) (1996-05-08)
Re: Using BTYACC to write C compiler Scott.Nicol@infoadvn.com (1996-05-10)
Re: Using BTYACC to write C compiler rfg@monkeys.com (1996-05-19)
| List of all articles for this month |
From: Scott.Nicol@infoadvn.com (Scott Nicol)
Newsgroups: comp.compilers
Date: 10 May 1996 01:32:00 -0400
Organization: Information Advantage
References: 96-05-060
Keywords: C

J.R.Hall@dcs.warwick.ac.uk 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 y.tab.h, 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
y.output.


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.
>-John]


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: scott@infoadvan.com
Information Advantage, Inc.


--


Post a followup to this message

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