Re: a newbie's dumb question...

Vinay Kakade <kvinay@ip.eth.net>
23 Jul 2001 02:18:57 -0400

          From comp.compilers

Related articles
a newbie's dumb question... explosion78@hotmail.com (2001-07-18)
Re: a newbie's dumb question... kvinay@ip.eth.net (Vinay Kakade) (2001-07-23)
Re: a newbie's dumb question... joachim_d@gmx.de (Joachim Durchholz) (2001-07-23)
Re: a newbie's dumb question... haberg@matematik.su.se (2001-07-23)
Re: a newbie's dumb question... hirner@yahoo.com (ThaFacka) (2001-07-23)
Re: a newbie's dumb question... rkrayhawk@aol.com (2001-07-27)
Re: a newbie's dumb question... james.grosbach@microchip.com (James Grosbach) (2001-07-30)
| List of all articles for this month |
From: Vinay Kakade <kvinay@ip.eth.net>
Newsgroups: comp.compilers
Date: 23 Jul 2001 02:18:57 -0400
Organization: Compilers Central
References: 01-07-094
Keywords: lex, yacc
Posted-Date: 23 Jul 2001 02:18:56 EDT

Hi,


Sunny wrote:


> Hi there~!


> I just strated to use lex and yacc to make a compiler for PICmicro
> assembler. I have gathered enough materials for lex and yacc over the
> internet. But I still don't have a slight idea of making a compiler
> though.


----> I think you should read "Lex and Yacc" by John Levine, published by


O'Reilly. To get an idea of making a compiler, read chapter 2
"A Simple One-Pass Compiler" from "Compilers - Principles, Techniques and
Tools"
by Aho, Sethi and Ullman.


> I've sort of done the lex part, creating token and stuff. But
> I can't do the yacc part yet.


-----> You will find a lot of examples in the above books to complete
  the Yacc part. A basic requirement to write a yacc script is that you
  should be able to write grammar for your language and should also be
  able to remove ambiguities (if any) in it. If you get any shift-reduce
  conflicts, try to modify your grammar.


> A friend of mine has done it for 68HC11. His compiler reads the whole
> code first and stack it, then finds any errors. Is it a good way? Or
> is there another way??


----> IMHO This is certainly not a good way. It will be very
inefficient for large code size. Another way, which is better
according to me, is that you should add semantic actions in your yacc
script for error detection and/or recovery. To give exact error
messages, it is better to write some additional grammar rules to
detect and/or correct errors. Besides, yacc also provides many error
detection facilities including error token. It is not possible to
explain all the details here. A nice explanation of finding errors in
the input file is given in both the books mentioned above.


> And the errors.. I spent a lot of hours to seek any clues about
> error-checking. I found one compiler which had over 200 error
> messages... I can only think of branch range errors, labeling errors
> and nothing else. Can any of you give me some ideas??


-----> There are really many types of errors. But they depend on the
syntax and semantics of the language you are developing. Try to visualize
each and every error that a user can make.


> Finally, parsers. I sort of understand that it's hierarchical and it
> eventually comes down to the token that the lex makes. Is that all
> there is to it? So am I just need to find the types of grammars (eg
> opcode label, label opcode number)??


-------> For using Yacc, you do not need to know the complicated
theory behind parsers, their types and their working. All you need to
know is how to write an unambiguous grammar, and semantic actions
for error handling and generating target code.


-Vinay Kakade.


Post a followup to this message

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